## $Id: test_applicantcopier.py 16545 2021-07-13 14:08:06Z henrik $ ## ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## """ Tests for the creation of student containers with data from admitted applicants. """ import os import grok from StringIO import StringIO from datetime import datetime from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState from zope.event import notify from zope.component import getUtility from zope.i18n import translate from zope.securitypolicy.interfaces import IPrincipalRoleManager from waeup.kofa.testing import FunctionalLayer from waeup.kofa.interfaces import IExtFileStore, IFileStoreNameChooser from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup from waeup.kofa.browser.tests.test_pdf import samples_dir session = datetime.now().year - 2 class ApplicantCopierFunctionalTests(ApplicantsFullSetup): layer = FunctionalLayer def setUp(self): super(ApplicantCopierFunctionalTests, self).setUp() return def prepare_applicant(self): self.browser.open(self.manage_path) self.fill_correct_values() self.browser.getControl("Save").click() # Upload a passport picture ctrl = self.browser.getControl(name='form.passport') file_obj = open( os.path.join(os.path.dirname(__file__), 'test_image.jpg'),'rb') file_ctrl = ctrl.mech_control file_ctrl.add_file(file_obj, filename='my_photo.jpg') self.browser.getControl("Save").click() # submit form return def test_applicant_student_copier(self): self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') self.prepare_applicant() storage = getUtility(IExtFileStore) # The stored image can be fetched file_id = IFileStoreNameChooser(self.applicant).chooseName() fd = storage.getFile(file_id) file_len_orig = len(fd.read()) # We store a test pdf file dummy_file = StringIO('test file') testfile_id = IFileStoreNameChooser( self.applicant).chooseName(attr='testfile.jpg') test_file = storage.createFile(testfile_id, dummy_file) # The stored file can be fetched fd = storage.getFile(testfile_id) testfile_len_orig = len(fd.read()) self.assertEqual(self.app['students']._curr_stud_id, 1000000) # Let's try to create the student (success, msg) = self.applicant.createStudent() self.assertTrue(msg == 'Applicant has not yet been admitted.') IWorkflowState(self.applicant).setState('admitted') (success, msg) = self.applicant.createStudent() # Current student_id has not changed. self.assertEqual(self.app['students']._curr_stud_id, 1000000) self.assertTrue(msg == 'No study course provided.') self.browser.open(self.manage_path) self.browser.getControl(name="form.course_admitted").value = ['CERT1'] self.browser.getControl("Save").click() # Maybe the certificate has meanwhile been removed del self.app['faculties']['fac1']['dep1'].certificates['CERT1'] (success, msg) = self.applicant.createStudent() self.assertFalse(success) self.assertTrue('ConstraintNotSatisfied: CERT1' in msg) # Current student_id has not changed. self.assertEqual(self.app['students']._curr_stud_id, 1000000) # Ok, lets add the certificate and try again self.app['faculties']['fac1']['dep1'].certificates.addCertificate( self.certificate) # Managers are not allowed to trigger the create transition manually self.assertFalse('