Ignore:
Timestamp:
7 Sep 2020, 12:28:14 (4 years ago)
Author:
Henrik Bettermann
Message:

Use Applicant.createStudent method also to create graduated
students from transcript application data (not used in base package).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_applicantcopier.py

    r15941 r16228  
    5656        return
    5757
    58     def test_copier(self):
     58    def test_applicant_student_copier(self):
    5959        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    6060        self.prepare_applicant()
     
    8080        # Current student_id has not changed.
    8181        self.assertEqual(self.app['students']._curr_stud_id, 1000000)
    82         self.assertTrue(msg == 'No course admitted provided.')
     82        self.assertTrue(msg == 'No study course provided.')
    8383        self.browser.open(self.manage_path)
    8484        self.browser.getControl(name="form.course_admitted").value = ['CERT1']
     
    158158        self.assertEqual(student['studycourse'].current_level, 100)
    159159
     160    def test_applicant_graduated_copier(self):
     161        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     162        self.prepare_applicant()
     163        storage = getUtility(IExtFileStore)
     164        # The stored image can be fetched
     165        file_id = IFileStoreNameChooser(self.applicant).chooseName()
     166        fd = storage.getFile(file_id)
     167        file_len_orig = len(fd.read())
     168        # We store a test pdf file
     169        dummy_file = StringIO('test file')
     170        testfile_id = IFileStoreNameChooser(
     171            self.applicant).chooseName(attr='testfile.pdf')
     172        test_file = storage.createFile(testfile_id, dummy_file)
     173        # The stored file can be fetched
     174        fd = storage.getFile(testfile_id)
     175        testfile_len_orig = len(fd.read())
     176        self.assertEqual(self.app['students']._curr_stud_id, 1000000)
     177        # Let's try to create the student
     178        (success, msg) = self.applicant.createStudent(graduated=True)
     179        self.assertTrue(msg == 'Applicant has not yet been processed.')
     180        IWorkflowState(self.applicant).setState('processed')
     181        (success, msg) = self.applicant.createStudent(graduated=True)
     182        # Current student_id has not changed.
     183        self.assertEqual(self.app['students']._curr_stud_id, 1000000)
     184        self.assertTrue(msg == 'No study course provided.')
     185        # The course_studied field is not used in the base package. Thus we
     186        # have to set the attribute manually.
     187        self.applicant.course_studied = self.certificate
     188        self.browser.open(self.manage_path)
     189        self.browser.getControl("Save").click()
     190        # Maybe the certificate has meanwhile been removed
     191        del self.app['faculties']['fac1']['dep1'].certificates['CERT1']
     192        (success, msg) = self.applicant.createStudent(graduated=True)
     193        self.assertFalse(success)
     194        self.assertTrue('ConstraintNotSatisfied: CERT1' in msg)
     195        # Current student_id has not changed.
     196        self.assertEqual(self.app['students']._curr_stud_id, 1000000)
     197        # Ok, lets add the certificate and try again
     198        self.app['faculties']['fac1']['dep1'].certificates.addCertificate(
     199            self.certificate)
     200        # Managers are not allowed to trigger the create transition manually
     201        self.assertFalse('<option value="create">' in self.browser.contents)
     202        # Graduated student can be created
     203        (success, msg) = self.applicant.createStudent(graduated=True)
     204        self.assertTrue('created' in msg)
     205        # Current student_id has not changed.
     206        self.assertEqual(self.app['students']._curr_stud_id, 1000001)
     207        student_id = translate(msg, 'waeup.kofa').split()[1]
     208        # View student container just created
     209        student = self.app['students'][student_id]
     210        student_path = 'http://localhost/app/students/%s' % student_id
     211        self.browser.open(student_path)
     212        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     213        self.assertEqual(self.browser.url, student_path)
     214        # Student is in state graduated
     215        self.assertEqual(student.state, 'graduated')
     216        # Attributes properly set?
     217        self.assertEqual(student.email, 'xx@yy.zz')
     218        self.assertEqual(student.firstname, 'John')
     219        self.assertEqual(student.middlename, 'Anthony')
     220        self.assertEqual(student.lastname, 'Tester')
     221        # student_id set in application record?
     222        self.assertEqual(self.applicant.student_id, student.student_id)
     223        # Check if passport image has been copied
     224        file_id = IFileStoreNameChooser(student).chooseName(attr='passport.jpg')
     225        fd = storage.getFile(file_id)
     226        file_len = len(fd.read())
     227        self.assertEqual(file_len_orig, file_len)
     228        # Check if test file has been copied too (new)
     229        file_id = IFileStoreNameChooser(student).chooseName(attr='testfile.jpg')
     230        fd = storage.getFile(file_id)
     231        file_len = len(fd.read())
     232        self.assertEqual(testfile_len_orig, file_len)
     233        # Check if application slip exists and is a PDF file
     234        file_id = IFileStoreNameChooser(
     235            student).chooseName(attr='application_slip.pdf')
     236        pdf = storage.getFile(file_id).read()
     237        self.assertTrue(len(pdf) > 0)
     238        self.assertEqual(pdf[:8], '%PDF-1.4')
     239        path = os.path.join(samples_dir(), 'application_slip.pdf')
     240        open(path, 'wb').write(pdf)
     241        print "Sample PDF application_slip.pdf written to %s" % path
     242        # Check if there is an application slip link in UI
     243        self.assertTrue('Application Slip' in self.browser.contents)
     244        self.browser.getLink("Application Slip").click()
     245        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     246        self.assertEqual(self.browser.headers['Content-Type'],
     247                         'application/pdf')
     248        # Has the student been properly indexed?
     249        # Yes, we can find the student in department
     250        self.browser.open('http://localhost/app/students')
     251        self.browser.getControl(name="searchtype").value = ['depcode']
     252        self.browser.getControl(name="searchterm").value = 'dep1'
     253        self.browser.getControl("Find student(s)").click()
     254        self.assertMatches('...John Anthony Tester...', self.browser.contents)
     255        # Has the student studycourse the correct attributes?
     256        self.assertEqual(student['studycourse'].certificate.code, 'CERT1')
     257        self.assertEqual(student['studycourse'].entry_session, session)
     258        self.assertEqual(student['studycourse'].entry_mode, 'ug_ft')
     259        self.assertEqual(student['studycourse'].current_session, session)
     260        self.assertEqual(student['studycourse'].current_level, 100)
     261
    160262    def test_batch_copying(self):
    161263        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     
    184286        notify(grok.ObjectModifiedEvent(self.applicant))
    185287        self.browser.open(self.container_path + '/createallstudents')
    186         self.assertTrue('No course admitted provided' in self.browser.contents)
     288        self.assertTrue('No study course provided' in self.browser.contents)
    187289        self.assertFalse('Successfully created records' in self.browser.contents)
    188290        self.assertTrue('Failed records' in self.browser.contents)
     
    215317        notify(grok.ObjectModifiedEvent(self.applicant))
    216318        self.browser.open(self.root_path + '/createallstudents')
    217         self.assertTrue('No course admitted provided' in self.browser.contents)
     319        self.assertTrue('No study course provided' in self.browser.contents)
    218320        self.applicant.course_admitted = self.certificate
    219321        self.browser.open(self.root_path + '/createallstudents')
Note: See TracChangeset for help on using the changeset viewer.