source: main/waeup.sirp/trunk/src/waeup/sirp/applicants/tests/test_applicantcopier.py @ 11067

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

We have to ensure that students are properly indexed after creation from applicants.

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