Ignore:
Timestamp:
13 Dec 2011, 09:45:28 (13 years ago)
Author:
Henrik Bettermann
Message:

Add missing UI tests for course advisers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py

    r7326 r7337  
    3636from waeup.sirp.configuration import SessionConfiguration
    3737from waeup.sirp.students.student import Student
     38from waeup.sirp.students.studylevel import StudentStudyLevel
    3839from waeup.sirp.university.faculty import Faculty
    3940from waeup.sirp.university.department import Department
     
    772773        self.assertTrue(self.student_id in self.browser.contents)
    773774
     775    def test_handle_courses_by_ca(self):
     776        # Create course adviser
     777        self.app['users'].addUser('mrsadvise', 'mrsadvisesecret')
     778        # Assign local CourseAdviser100 role for a certificate
     779        cert = self.app['faculties']['fac1']['dep1'].certificates['CERT1']
     780        prmlocal = IPrincipalRoleManager(cert)
     781        prmlocal.assignRoleToPrincipal('waeup.local.CourseAdviser100', 'mrsadvise')
     782        IWorkflowInfo(self.student).fireTransition('admit')
     783        IWorkflowInfo(self.student).fireTransition('start_clearance')
     784        IWorkflowInfo(self.student).fireTransition('request_clearance')
     785        IWorkflowInfo(self.student).fireTransition('clear')
     786        IWorkflowInfo(self.student).fireTransition('pay_first_school_fee')
     787        # Login as course adviser
     788        self.browser.open(self.login_path)
     789        self.browser.getControl(name="form.login").value = 'mrsadvise'
     790        self.browser.getControl(name="form.password").value = 'mrsadvisesecret'
     791        self.browser.getControl("Login").click()
     792        self.assertMatches('...You logged in...', self.browser.contents)
     793        # CO can see his roles
     794        self.browser.getLink("My Roles").click()
     795        self.assertMatches(
     796            '...<div>Academics Officer (view only)</div>...',
     797            self.browser.contents)
     798        # But not his local role ...
     799        self.assertFalse('Course Adviser' in self.browser.contents)
     800        # ... because we forgot to notify the certificate that the local role
     801        # has changed
     802        notify(LocalRoleSetEvent(
     803            cert, 'waeup.local.CourseAdviser100', 'mrsadvise', granted=True))
     804        self.browser.open('http://localhost/app/users/mrsadvise/my_roles')
     805        self.assertTrue('Course Adviser 100L' in self.browser.contents)
     806        self.assertMatches(
     807            '...<a href="http://localhost/app/faculties/fac1/dep1/certificates/CERT1">...',
     808            self.browser.contents)
     809        # CA can view the student ...
     810        self.browser.open(self.student_path)
     811        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     812        self.assertEqual(self.browser.url, self.student_path)
     813        # ... but not other students
     814        other_student = Student()
     815        other_student.fullname = u'Dep2 Student'
     816        self.app['students'].addStudent(other_student)
     817        other_student_path = (
     818            'http://localhost/app/students/%s' % other_student.student_id)
     819        self.assertRaises(
     820            Unauthorized, self.browser.open, other_student_path)
     821        # We add study level 110 to the student's studycourse
     822        studylevel = StudentStudyLevel()
     823        studylevel.level = 110
     824        self.student['studycourse'].addStudentStudyLevel(
     825            cert,studylevel)
     826        L110_student_path = self.studycourse_student_path + '/110'
     827        # Only in state courses registered and only if the current level
     828        # corresponds with the name of the study level object
     829        # the 100L CA does see the 'Validate' button
     830        self.browser.open(L110_student_path)
     831        self.assertFalse('Validate' in self.browser.contents)
     832        IWorkflowInfo(self.student).fireTransition('register_courses')
     833        self.browser.open(L110_student_path)
     834        self.assertFalse('Validate' in self.browser.contents)
     835        self.student['studycourse'].current_level = 110
     836        self.browser.open(L110_student_path)
     837        self.assertTrue('Validate' in self.browser.contents)
     838        # ... but a 100L CA does not see the button on other levels
     839        studylevel2 = StudentStudyLevel()
     840        studylevel2.level = 200
     841        self.student['studycourse'].addStudentStudyLevel(
     842            cert,studylevel2)
     843        L200_student_path = self.studycourse_student_path + '/200'
     844        self.browser.open(L200_student_path)
     845        self.assertFalse('Validate' in self.browser.contents)
     846        self.browser.open(L110_student_path)
     847        self.browser.getLink("Validate courses").click()
     848        self.assertTrue('Course list has been validated' in self.browser.contents)
     849        self.assertTrue('State: <span>courses validated</span>' in self.browser.contents)
     850        self.browser.getLink("Reject courses").click()
     851        self.assertTrue('Course list request has been annulled'
     852            in self.browser.contents)
     853        urlmessage = 'Course+list+request+has+been+annulled'
     854        self.assertEqual(self.browser.url, self.student_path +
     855            '/contactstudent?subject=%s' % urlmessage)
     856        self.assertTrue('State: <span>school fee paid</span>'
     857            in self.browser.contents)
     858        IWorkflowInfo(self.student).fireTransition('register_courses')
     859        self.browser.open(L110_student_path)
     860        self.browser.getLink("Reject courses").click()
     861        self.assertTrue('Course list request has been rejected'
     862            in self.browser.contents)
     863        self.assertTrue('State: <span>school fee paid</span>'
     864            in self.browser.contents)
     865        # The CA can't validate courses if not in state
     866        # courses registered
     867        self.browser.open(L110_student_path + '/validate_courses')
     868        self.assertTrue('Student is in the wrong state'
     869            in self.browser.contents)
     870        # The CA can go to his certificate throug the my_roles page
     871        self.browser.open('http://localhost/app/users/mrsadvise/my_roles')
     872        self.browser.getLink(
     873            "http://localhost/app/faculties/fac1/dep1/certificates/CERT1").click()
     874        # and view the list of students
     875        self.browser.getLink("Show students").click()
     876        self.assertTrue(self.student_id in self.browser.contents)
     877
    774878    def test_student_change_password(self):
    775879        # Students can change the password
Note: See TracChangeset for help on using the changeset viewer.