source: main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_applicantcopier.py @ 8636

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

Implement CreateAllStudentsPage? which creates students from all admitted students in a container.

  • Property svn:keywords set to Id
File size: 7.5 KB
Line 
1## $Id: test_applicantcopier.py 8636 2012-06-06 09:17:37Z 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 the creation of student containers with data from admitted applicants.
20"""
21import os
22import grok
23from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
24from zope.event import notify
25from zope.component import getUtility
26from zope.i18n import translate
27from waeup.kofa.testing import FunctionalLayer
28from waeup.kofa.interfaces import IExtFileStore, IFileStoreNameChooser
29from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup
30
31class ApplicantCopierFunctionalTests(ApplicantsFullSetup):
32
33    layer = FunctionalLayer
34
35    def setUp(self):
36        super(ApplicantCopierFunctionalTests, self).setUp()
37        return
38
39    def prepare_applicant(self):
40        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
41        self.browser.open(self.manage_path)
42        self.fill_correct_values()
43        self.browser.getControl("Save").click()
44        # Upload a passport picture
45        ctrl = self.browser.getControl(name='form.passport')
46        file_obj = open(
47            os.path.join(os.path.dirname(__file__), 'test_image.jpg'),'rb')
48        file_ctrl = ctrl.mech_control
49        file_ctrl.add_file(file_obj, filename='my_photo.jpg')
50        self.browser.getControl("Save").click() # submit form
51        return
52
53    def test_copier(self):
54        self.prepare_applicant()
55        storage = getUtility(IExtFileStore)
56        file_id = IFileStoreNameChooser(self.applicant).chooseName()
57        # The stored image can be fetched
58        fd = storage.getFile(file_id)
59        file_len_orig = len(fd.read())
60        # Let's try to create the student
61        (success, msg) = self.applicant.createStudent()
62        self.assertTrue(msg == 'Applicant has not yet been admitted.')
63        IWorkflowState(self.applicant).setState('admitted')
64        (success, msg) = self.applicant.createStudent()
65        self.assertTrue(msg == 'No course admitted provided.')
66        self.browser.open(self.manage_path)
67        self.browser.getControl(name="form.course_admitted").value = ['CERT1']
68        self.browser.getControl("Save").click()
69        (success, msg) = self.applicant.createStudent()
70        self.assertTrue('created' in msg)
71        student_id = translate(msg, 'waeup.kofa').split()[1]
72        # View student container just created
73        student = self.app['students'][student_id]
74        student_path = 'http://localhost/app/students/%s' % student_id
75        self.browser.open(student_path)
76        self.assertEqual(self.browser.headers['Status'], '200 Ok')
77        self.assertEqual(self.browser.url, student_path)
78        # Student is in state admitted
79        self.assertEqual(student.state, 'admitted')
80        # Check if passport image has been copied
81        storage = getUtility(IExtFileStore)
82        file_id = IFileStoreNameChooser(
83            student).chooseName(attr='passport.jpg')
84        fd = storage.getFile(file_id)
85        file_len = len(fd.read())
86        self.assertEqual(file_len_orig, file_len)
87        # Check if application slip exists and is a PDF file
88        file_id = IFileStoreNameChooser(
89            student).chooseName(attr='application_slip.pdf')
90        pdf = storage.getFile(file_id).read()
91        self.assertTrue(len(pdf) > 0)
92        self.assertEqual(pdf[:8], '%PDF-1.4')
93        # Check if there is an application slip link in UI
94        self.assertTrue('Application Slip' in self.browser.contents)
95        self.browser.getLink("Application Slip").click()
96        self.assertEqual(self.browser.headers['Status'], '200 Ok')
97        self.assertEqual(self.browser.headers['Content-Type'],
98                         'application/pdf')
99        # Has the student been properly indexed?
100        # Yes, we can find the student in department
101        self.browser.open('http://localhost/app/students')
102        self.browser.getControl(name="searchtype").value = ['depcode']
103        self.browser.getControl(name="searchterm").value = 'dep1'
104        self.browser.getControl("Search").click()
105        self.assertMatches('...John Tester...', self.browser.contents)
106
107    def test_batch_copying(self):
108        self.prepare_applicant()
109        IWorkflowState(self.applicant).setState('admitted')
110        self.browser.getControl(name="form.course_admitted").value = ['CERT1']
111        self.browser.getControl("Save").click()
112        self.browser.open(self.manage_container_path)
113        self.browser.getControl("Create students from selected", index=0).click()
114        self.assertTrue('No applicant selected' in self.browser.contents)
115        ctrl = self.browser.getControl(name='val_id')
116        ctrl.getControl(value=self.applicant.application_number).selected = True
117        self.browser.getControl("Create students from selected", index=0).click()
118        self.assertTrue('1 students successfully created' in self.browser.contents)
119
120    def test_hidden_batch_copying(self):
121        logfile = os.path.join(
122            self.app['datacenter'].storage, 'logs', 'applicants.log')
123        self.prepare_applicant()
124        self.browser.open(self.container_path + '/createallstudents')
125        self.assertTrue('No student could be created' in self.browser.contents)
126        IWorkflowState(self.applicant).setState('admitted')
127        notify(grok.ObjectModifiedEvent(self.applicant))
128        self.browser.open(self.container_path + '/createallstudents')
129        self.assertTrue('No student could be created' in self.browser.contents)
130        logcontent = open(logfile).read()
131        self.assertTrue('No course admitted provided' in logcontent)
132        self.browser.open(self.manage_path)
133        self.browser.getControl(name="form.course_admitted").value = ['CERT1']
134        self.browser.getControl("Save").click()
135        # date_of_birth is not required for applicants but for students
136        self.applicant.date_of_birth = None
137        self.browser.open(self.container_path + '/createallstudents')
138        self.assertTrue('No student could be created' in self.browser.contents)
139        logcontent = open(logfile).read()
140        self.assertTrue('RequiredMissing: date_of_birth' in logcontent)
141        self.browser.open(self.manage_path)
142        self.browser.getControl(name="form.date_of_birth").value = '09/09/1988'
143        self.browser.getControl("Save").click()
144        self.browser.open(self.container_path + '/createallstudents')
145        self.assertTrue('1 students successfully created' in self.browser.contents)
146
147    def test_copier_wo_passport(self):
148        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
149        self.browser.open(self.manage_path)
150        self.fill_correct_values()
151        # Let's try to create the student
152        IWorkflowState(self.applicant).setState('admitted')
153        self.browser.getControl(name="form.course_admitted").value = ['CERT1']
154        self.browser.getControl("Save").click()
155        (success, msg) = self.applicant.createStudent()
156        self.assertTrue('created' in msg)
Note: See TracBrowser for help on using the repository browser.