source: main/waeup.kofa/branches/uli-py3/src/waeup/kofa/applicants/tests/test_catalog.py

Last change on this file was 8700, checked in by Henrik Bettermann, 12 years ago

Catalogue all kinds of payments not only student payments.

  • Property svn:keywords set to Id
File size: 4.7 KB
Line 
1## $Id: test_catalog.py 8700 2012-06-12 21:01:17Z henrik $
2##
3## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18"""
19Tests for applicants specific catalog (currently only one).
20"""
21import shutil
22import tempfile
23import grok
24from zope.component import getUtility, createObject
25from hurry.query import Eq
26from hurry.query.interfaces import IQuery
27from zope.catalog.interfaces import ICatalog
28from zope.component import getUtility
29from zope.component.hooks import setSite
30from zope.component.interfaces import ComponentLookupError
31from zope.testbrowser.testing import Browser
32from waeup.kofa.app import University
33from waeup.kofa.applicants.container import ApplicantsContainer
34from waeup.kofa.applicants.applicant import Applicant
35from waeup.kofa.testing import FunctionalLayer, FunctionalTestCase
36
37class CatalogTests(FunctionalTestCase):
38
39    layer = FunctionalLayer
40
41    def setUp(self):
42        super(CatalogTests, self).setUp()
43
44        # Setup a sample site for each test
45        app = University()
46        self.dc_root = tempfile.mkdtemp()
47        app['datacenter'].setStoragePath(self.dc_root)
48
49        # Prepopulate the ZODB...
50        self.getRootFolder()['app'] = app
51        self.app = self.getRootFolder()['app']
52        self.browser = Browser()
53        self.browser.handleErrors = False
54
55    def tearDown(self):
56        super(CatalogTests, self).tearDown()
57        shutil.rmtree(self.dc_root)
58
59    def create_applicant(self):
60        # Create an applicant in an applicants container
61        self.container = ApplicantsContainer()
62        self.container.code = u"mystuff"
63        setSite(self.app)
64        self.app['applicants']['mystuff'] = self.container
65        self.applicant = Applicant()
66        self.app['applicants']['mystuff'].addApplicant(self.applicant)
67        return
68
69    def test_get_applicants_catalog(self):
70        # There is no global applicants catalog, but one for each site.
71        self.assertRaises(
72            ComponentLookupError,
73            getUtility, ICatalog, name='applicants_catalog')
74        # If we are 'in the local site' we can get an applicants catalog.
75        setSite(self.app)
76        cat = getUtility(ICatalog, name='applicants_catalog')
77        self.assertTrue(ICatalog.providedBy(cat))
78
79    def test_get_applicant(self):
80        # Make sure that applicants are really catalogued on creation.
81        self.create_applicant()
82        q = getUtility(IQuery)
83        subquery = Eq(('applicants_catalog', 'applicant_id'),
84            self.applicant.applicant_id)
85        results = list(q.searchResults(subquery))
86        self.assertEqual(len(results), 1)
87        result_applicant = results[0]
88        self.assertTrue(isinstance(result_applicant, Applicant))
89        self.assertEqual(result_applicant.applicant_id, self.applicant.applicant_id)
90
91    def test_get_payment(self):
92        self.create_applicant()
93        q = getUtility(IQuery)
94        subquery = Eq(('applicants_catalog', 'applicant_id'),
95            self.applicant.applicant_id)
96        results = list(q.searchResults(subquery))
97        self.assertEqual(len(results), 1)
98        result_applicant = results[0]
99        payment = createObject('waeup.ApplicantOnlinePayment')
100        payment.p_id = 'p1234567890'
101        payment.p_item = u'Payment Item'
102        payment.p_session = 2011
103        payment.p_category = 'application'
104        result_applicant[payment.p_id] = payment
105        # We can find a payment ticket by the payment session ...
106        cat = getUtility(ICatalog, name='payments_catalog')
107        results = cat.searchResults(p_session=(2011, 2011))
108        results = [x for x in results] # Turn results generator into list
109        assert len(results) == 1
110        assert results[0] is result_applicant['p1234567890']
111        # ... and by the payment id
112        results = cat.searchResults(p_id=('p1234567890', 'p1234567890'))
113        assert len(results) == 1
114        # If we remove the applicant also the payment disappears
115        del self.app['applicants']['mystuff'][result_applicant.application_number]
116        results = cat.searchResults(p_id=('p1234567890', 'p1234567890'))
117        assert len(results) == 0
Note: See TracBrowser for help on using the repository browser.