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

Last change on this file since 8404 was 8384, checked in by Henrik Bettermann, 13 years ago

Fix test.

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