1 | ## $Id: test_browser.py 10120 2013-04-30 06:33:55Z 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 StringIO import StringIO |
---|
22 | from hurry.workflow.interfaces import IWorkflowState, IWorkflowInfo |
---|
23 | from zope.component.hooks import setSite, clearSite |
---|
24 | from zope.component import getUtility, createObject |
---|
25 | from zope.interface import verify |
---|
26 | from waeup.kofa.app import University |
---|
27 | from waeup.kofa.students.tests.test_browser import ( |
---|
28 | StudentsFullSetup, SAMPLE_IMAGE) |
---|
29 | from waeup.kofa.students.accommodation import BedTicket |
---|
30 | from waeup.kofa.testing import FunctionalTestCase |
---|
31 | from waeup.kofa.interfaces import ( |
---|
32 | IExtFileStore, IFileStoreNameChooser) |
---|
33 | from waeup.kofa.students.interfaces import IStudentsUtils |
---|
34 | from waeup.aaua.testing import FunctionalLayer |
---|
35 | |
---|
36 | |
---|
37 | class StudentProcessorTest(FunctionalTestCase): |
---|
38 | """Perform some batching tests. |
---|
39 | """ |
---|
40 | |
---|
41 | layer = FunctionalLayer |
---|
42 | |
---|
43 | def setUp(self): |
---|
44 | super(StudentProcessorTest, self).setUp() |
---|
45 | # Setup a sample site for each test |
---|
46 | app = University() |
---|
47 | self.dc_root = tempfile.mkdtemp() |
---|
48 | app['datacenter'].setStoragePath(self.dc_root) |
---|
49 | |
---|
50 | # Prepopulate the ZODB... |
---|
51 | self.getRootFolder()['app'] = app |
---|
52 | # we add the site immediately after creation to the |
---|
53 | # ZODB. Catalogs and other local utilities are not setup |
---|
54 | # before that step. |
---|
55 | self.app = self.getRootFolder()['app'] |
---|
56 | # Set site here. Some of the following setup code might need |
---|
57 | # to access grok.getSite() and should get our new app then |
---|
58 | setSite(app) |
---|
59 | |
---|
60 | |
---|
61 | def tearDown(self): |
---|
62 | super(StudentProcessorTest, self).tearDown() |
---|
63 | shutil.rmtree(self.workdir) |
---|
64 | shutil.rmtree(self.dc_root) |
---|
65 | clearSite() |
---|
66 | return |
---|
67 | |
---|
68 | class StudentUITests(StudentsFullSetup): |
---|
69 | """Tests for customized student class views and pages |
---|
70 | """ |
---|
71 | |
---|
72 | layer = FunctionalLayer |
---|
73 | |
---|
74 | def setUp(self): |
---|
75 | super(StudentUITests, self).setUp() |
---|
76 | |
---|
77 | bedticket = BedTicket() |
---|
78 | bedticket.booking_session = 2004 |
---|
79 | bedticket.bed_type = u'any bed type' |
---|
80 | bedticket.bed = self.app['hostels']['hall-1']['hall-1_A_101_A'] |
---|
81 | bedticket.bed_coordinates = u'My bed coordinates' |
---|
82 | self.student['accommodation'].addBedTicket(bedticket) |
---|
83 | |
---|
84 | |
---|
85 | |
---|
86 | def test_student_start_clearance(self): |
---|
87 | self.browser.open(self.login_path) |
---|
88 | self.browser.getControl(name="form.login").value = self.student_id |
---|
89 | self.browser.getControl(name="form.password").value = 'spwd' |
---|
90 | self.browser.getControl("Login").click() |
---|
91 | |
---|
92 | IWorkflowInfo(self.student).fireTransition('admit') |
---|
93 | self.browser.open(self.student_path + '/change_portrait') |
---|
94 | image = open(SAMPLE_IMAGE, 'rb') |
---|
95 | ctrl = self.browser.getControl(name='passportuploadedit') |
---|
96 | file_ctrl = ctrl.mech_control |
---|
97 | file_ctrl.add_file(image, filename='my_photo.jpg') |
---|
98 | self.browser.getControl( |
---|
99 | name='upload_passportuploadedit').click() |
---|
100 | self.browser.open(self.student_path + '/start_clearance') |
---|
101 | # In Okene the students can just start clearance without entering |
---|
102 | # an activation code. |
---|
103 | self.browser.getControl("Start clearance now").click() |
---|
104 | self.assertMatches('...Clearance process has been started...', |
---|
105 | self.browser.contents) |
---|
106 | |
---|
107 | def test_student_accommodation(self): |
---|
108 | del self.student['accommodation']['2004'] |
---|
109 | # Login |
---|
110 | self.browser.open(self.login_path) |
---|
111 | self.browser.getControl(name="form.login").value = self.student_id |
---|
112 | self.browser.getControl(name="form.password").value = 'spwd' |
---|
113 | self.browser.getControl("Login").click() |
---|
114 | |
---|
115 | # Students can book accommodation without AC ... |
---|
116 | self.browser.open(self.acco_path) |
---|
117 | IWorkflowInfo(self.student).fireTransition('admit') |
---|
118 | self.browser.getLink("Book accommodation").click() |
---|
119 | self.assertFalse('Activation Code:' in self.browser.contents) |
---|
120 | self.browser.getControl("Create bed ticket").click() |
---|
121 | # Bed is randomly selected but, since there is only |
---|
122 | # one bed for this student, we know that |
---|
123 | self.assertMatches('...Hall 1, Block A, Room 101, Bed A...', |
---|
124 | self.browser.contents) |
---|
125 | return |
---|