1 | ## $Id: tests.py 8012 2012-03-30 17:55:44Z 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 | import os |
---|
19 | import shutil |
---|
20 | import tempfile |
---|
21 | from zope.interface.verify import verifyClass, verifyObject |
---|
22 | from zope.component.hooks import setSite, clearSite |
---|
23 | from zope.component import createObject |
---|
24 | from zope.testbrowser.testing import Browser |
---|
25 | from waeup.kofa.app import University |
---|
26 | from waeup.kofa.university.faculty import Faculty |
---|
27 | from waeup.kofa.university.department import Department |
---|
28 | from waeup.kofa.testing import FunctionalTestCase |
---|
29 | from waeup.kofa.applicants.container import ApplicantsContainer |
---|
30 | from waeup.custom.testing import FunctionalLayer |
---|
31 | from waeup.kofa.interfaces import IBatchProcessor |
---|
32 | |
---|
33 | class ApplicantUITest(FunctionalTestCase): |
---|
34 | """Perform some browser tests. |
---|
35 | """ |
---|
36 | layer = FunctionalLayer |
---|
37 | |
---|
38 | def setUp(self): |
---|
39 | super(ApplicantUITest, self).setUp() |
---|
40 | # Setup a sample site for each test |
---|
41 | app = University() |
---|
42 | self.dc_root = tempfile.mkdtemp() |
---|
43 | app['datacenter'].setStoragePath(self.dc_root) |
---|
44 | |
---|
45 | # Prepopulate the ZODB... |
---|
46 | self.getRootFolder()['app'] = app |
---|
47 | # we add the site immediately after creation to the |
---|
48 | # ZODB. Catalogs and other local utilities are not setup |
---|
49 | # before that step. |
---|
50 | self.app = self.getRootFolder()['app'] |
---|
51 | # Set site here. Some of the following setup code might need |
---|
52 | # to access grok.getSite() and should get our new app then |
---|
53 | setSite(app) |
---|
54 | |
---|
55 | # Add an two different applicants containers |
---|
56 | self.pgcontainer = ApplicantsContainer() |
---|
57 | self.pgcontainer.code = u'pg2011' |
---|
58 | self.pgcontainer.prefix = u'pg' |
---|
59 | self.app['applicants']['pg2011'] = self.pgcontainer |
---|
60 | self.ugcontainer = ApplicantsContainer() |
---|
61 | self.ugcontainer.code = u'app2011' |
---|
62 | self.ugcontainer.prefix = u'app' |
---|
63 | self.app['applicants']['app2011'] = self.ugcontainer |
---|
64 | |
---|
65 | # Populate university |
---|
66 | self.certificate = createObject('waeup.Certificate') |
---|
67 | self.certificate.code = 'CERT1' |
---|
68 | self.certificate.application_category = 'basic' |
---|
69 | self.certificate.start_level = 100 |
---|
70 | self.certificate.end_level = 500 |
---|
71 | self.app['faculties']['fac1'] = Faculty() |
---|
72 | self.app['faculties']['fac1']['dep1'] = Department() |
---|
73 | self.app['faculties']['fac1']['dep1'].certificates.addCertificate( |
---|
74 | self.certificate) |
---|
75 | |
---|
76 | # Add (customized) applicants |
---|
77 | pgapplicant = createObject(u'waeup.Applicant') |
---|
78 | pgapplicant.firstname = u'Anna' |
---|
79 | pgapplicant.lastname = u'Post' |
---|
80 | self.app['applicants']['pg2011'].addApplicant(pgapplicant) |
---|
81 | self.pgapplication_number = pgapplicant.application_number |
---|
82 | self.pgapplicant = self.app['applicants']['pg2011'][ |
---|
83 | self.pgapplication_number] |
---|
84 | |
---|
85 | ugapplicant = createObject(u'waeup.Applicant') |
---|
86 | ugapplicant.firstname = u'Klaus' |
---|
87 | ugapplicant.lastname = u'Under' |
---|
88 | self.app['applicants']['app2011'].addApplicant(ugapplicant) |
---|
89 | self.ugapplication_number = ugapplicant.application_number |
---|
90 | self.ugapplicant = self.app['applicants']['app2011'][ |
---|
91 | self.ugapplication_number] |
---|
92 | |
---|
93 | self.browser = Browser() |
---|
94 | self.browser.handleErrors = False |
---|
95 | |
---|
96 | def tearDown(self): |
---|
97 | super(ApplicantUITest, self).tearDown() |
---|
98 | shutil.rmtree(self.dc_root) |
---|
99 | clearSite() |
---|
100 | return |
---|
101 | |
---|
102 | def test_manage_and_view_applicant(self): |
---|
103 | # Managers can manage pg applicants |
---|
104 | pgapplicant_path = ('http://localhost/app/applicants/pg2011/%s' |
---|
105 | % self.pgapplication_number) |
---|
106 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
107 | self.browser.open(pgapplicant_path) |
---|
108 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
109 | # The IPGApplicant interface is really used |
---|
110 | self.assertTrue('Employer' in self.browser.contents) |
---|
111 | # If we move the applicant to the container, |
---|
112 | # the Employer field disappears |
---|
113 | ugapplicant_path = ('http://localhost/app/applicants/app2011/%s' |
---|
114 | % self.ugapplication_number) |
---|
115 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
116 | self.browser.open(ugapplicant_path) |
---|
117 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
118 | |
---|
119 | self.assertFalse('Employer' in self.browser.contents) |
---|
120 | return |
---|