Changeset 13918 for main/waeup.kofa/branches/uli-scores-upload/src
- Timestamp:
- 12 Jun 2016, 16:35:42 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/branches/uli-scores-upload/src/waeup/kofa/students/tests/test_browser.py
r13917 r13918 45 45 from waeup.kofa.university.faculty import Faculty 46 46 from waeup.kofa.university.department import Department 47 from waeup.kofa.interfaces import IUserAccount, IJobManager 47 from waeup.kofa.interfaces import IUserAccount, IJobManager, VALIDATED, CREATED 48 48 from waeup.kofa.authentication import LocalRoleSetEvent 49 49 from waeup.kofa.hostels.hostel import Hostel, Bed, NOT_OCCUPIED … … 55 55 SAMPLE_IMAGE = os.path.join(os.path.dirname(__file__), 'test_image.jpg') 56 56 SAMPLE_IMAGE_BMP = os.path.join(os.path.dirname(__file__), 'test_image.bmp') 57 URL_LECTURER_LANDING = 'http://localhost/app/my_courses' 57 58 58 59 … … 3913 3914 name="form.password").value = 'mrslecturersecret' 3914 3915 self.browser.getControl("Login").click() 3915 3916 def test_handle_courses_by_lecturer(self): 3916 # Store reused urls/paths 3917 self.course_url = ( 3918 'http://localhost/app/faculties/fac1/dep1/courses/COURSE1') 3919 self.edit_scores_url = '%s/edit_scores' % self.course_url 3920 # Set standard parameters 3921 self.app['configuration'].current_academic_session = 2004 3922 self.app['faculties']['fac1']['dep1'].score_editing_disabled = False 3923 IWorkflowState(self.student).setState(VALIDATED) 3924 3925 @property 3926 def stud_log_path(self): 3927 return os.path.join( 3928 self.app['datacenter'].storage, 'logs', 'students.log') 3929 3930 def test_lecturer_lands_on_landing_page(self): 3931 # lecturers can login and will be led to landing page. 3917 3932 self.login_as_lecturer() 3918 3933 self.assertMatches('...You logged in...', self.browser.contents) 3919 # Lecturer is on landing page 3920 self.assertTrue('(<span>COURSE1</span>)' in self.browser.contents) 3921 # Lecturer can click the 'My Roles' link. 3934 self.assertEqual(self.browser.url, URL_LECTURER_LANDING) 3935 3936 def test_my_roles_link_works(self): 3937 # lecturers can see their roles 3938 self.login_as_lecturer() 3922 3939 self.browser.getLink("My Roles").click() 3923 self.assertMatches( 3924 '...<div>Academics Officer (view only)</div>...', 3925 self.browser.contents) 3926 self.assertMatches( 3927 '...<a href="http://localhost/app/' 3928 'faculties/fac1/dep1/courses/COURSE1">...', 3929 self.browser.contents) 3930 self.assertFalse('(<span>COURSE1</span>)' in self.browser.contents) 3931 # Lecturer can click the 'My Courses' link ... 3940 self.assertTrue( 3941 "<div>Academics Officer (view only)</div>" 3942 in self.browser.contents) 3943 self.assertTrue( 3944 '<a href="%s">' % self.course_url in self.browser.contents) 3945 3946 def test_my_roles_page_contains_backlink(self): 3947 # we can get back from 'My Roles' view to landing page 3948 self.login_as_lecturer() 3949 self.browser.getLink("My Roles").click() 3932 3950 self.browser.getLink("My Courses").click() 3933 # ... and is is back on landing page 3934 self.assertTrue('(<span>COURSE1</span>)' in self.browser.contents) 3935 # The lecturer can go to her course ... 3951 self.assertEqual(self.browser.url, URL_LECTURER_LANDING) 3952 3953 def test_lecturers_can_reach_their_courses(self): 3954 # lecturers get links to their courses on the landing page 3955 self.login_as_lecturer() 3936 3956 self.browser.getLink("COURSE1").click() 3957 self.assertEqual(self.browser.url, self.course_url) 3958 3959 def test_lecturers_student_access_is_restricted(self): 3960 # lecturers are not able to change other student data 3961 self.login_as_lecturer() 3937 3962 # Lecturers can neither filter students ... 3938 3963 self.assertRaises( 3939 Unauthorized, self.browser.open, 3940 "http://localhost/app/faculties/fac1/dep1/courses/COURSE1/students") 3964 Unauthorized, self.browser.open, '%s/students' % self.course_url) 3941 3965 # ... nor access the student ... 3942 3966 self.assertRaises( 3943 3967 Unauthorized, self.browser.open, self.student_path) 3944 # ... nor the respective course ticket since 3945 # editing coursetickets by lecturers is not feasible.3968 # ... nor the respective course ticket since editing course 3969 # tickets by lecturers is not feasible. 3946 3970 self.assertTrue('COURSE1' in self.student['studycourse']['100'].keys()) 3947 3971 course_ticket_path = self.student_path + '/studycourse/100/COURSE1' 3948 3972 self.assertRaises( 3949 3973 Unauthorized, self.browser.open, course_ticket_path) 3950 # Course results can be batch edited via the edit_courses view. 3974 3975 def test_score_editing_requires_department_permit(self): 3976 # we get a warning if we try to update score while we are not allowed 3977 self.login_as_lecturer() 3951 3978 self.app['faculties']['fac1']['dep1'].score_editing_disabled = True 3952 self.browser.open( 3953 "http://localhost/app/faculties/fac1/dep1/courses/COURSE1") 3979 self.browser.open(self.course_url) 3954 3980 self.browser.getLink("Update scores").click() 3955 3981 self.assertTrue('Score editing disabled' in self.browser.contents) 3956 3982 self.app['faculties']['fac1']['dep1'].score_editing_disabled = False 3983 self.browser.open(self.course_url) 3957 3984 self.browser.getLink("Update scores").click() 3958 self.assertTrue( 3959 'Current academic session not set' in self.browser.contents) 3985 self.assertFalse('Score editing disabled' in self.browser.contents) 3986 3987 def test_score_editing_requires_validated_students(self): 3988 # we can edit only scores of students whose courses have been 3989 # validated. 3990 self.login_as_lecturer() 3991 # set invalid student state 3992 IWorkflowState(self.student).setState(CREATED) 3993 self.browser.open(self.edit_scores_url) 3994 self.assertRaises( 3995 LookupError, self.browser.getControl, name="scores") 3996 # set valid student state 3997 IWorkflowState(self.student).setState(VALIDATED) 3998 self.browser.open(self.edit_scores_url) 3999 self.assertTrue(self.browser.getControl(name="scores") is not None) 4000 4001 def test_score_editing_offers_only_current_scores(self): 4002 # only scores from current academic session can be edited 4003 self.login_as_lecturer() 4004 IWorkflowState(self.student).setState('courses validated') 4005 # with no academic session set 4006 self.app['configuration'].current_academic_session = None 4007 self.browser.open(self.edit_scores_url) 4008 self.assertRaises( 4009 LookupError, self.browser.getControl, name="scores") 4010 # with wrong academic session set 4011 self.app['configuration'].current_academic_session = 1999 4012 self.browser.open(self.edit_scores_url) 4013 self.assertRaises( 4014 LookupError, self.browser.getControl, name="scores") 4015 # with right academic session set 3960 4016 self.app['configuration'].current_academic_session = 2004 3961 self.browser.getLink("Update scores").click() 3962 self.assertFalse( 3963 '<input type="text" name="scores" class="span1" />' 3964 in self.browser.contents) 3965 IWorkflowState(self.student).setState('courses validated') 3966 # Student must be in state 'courses validated'. 3967 self.browser.open( 3968 'http://localhost/app/faculties/fac1/' 3969 'dep1/courses/COURSE1/edit_scores') 3970 self.assertTrue( 3971 'input type="text" name="scores"' in self.browser.contents) 4017 self.browser.reload() 4018 self.assertTrue(self.browser.getControl(name="scores") is not None) 4019 4020 def test_score_editing_can_change_scores(self): 4021 # we can really change scores via edit_scores view 4022 self.login_as_lecturer() 4023 self.assertEqual( 4024 self.student['studycourse']['100']['COURSE1'].score, None) 4025 self.browser.open(self.edit_scores_url) 3972 4026 self.browser.getControl(name="scores", index=0).value = '55' 3973 4027 self.browser.getControl("Update scores").click() 3974 # New score has been set.4028 # the new value is stored in data 3975 4029 self.assertEqual( 3976 4030 self.student['studycourse']['100']['COURSE1'].score, 55) 3977 # Score editing has been logged. 3978 logfile = os.path.join( 3979 self.app['datacenter'].storage, 'logs', 'students.log') 3980 logcontent = open(logfile).read() 3981 self.assertTrue('mrslecturer - students.browser.EditScoresPage - ' 3982 'K1000000 100/COURSE1 score updated (55)' in logcontent) 4031 # the new value is displayed on page/prefilled in form 4032 self.assertEqual( 4033 self.browser.getControl(name="scores", index=0).value, '55') 4034 # The change has been logged 4035 with open(self.stud_log_path, 'r') as fd: 4036 self.assertTrue( 4037 'mrslecturer - students.browser.EditScoresPage - ' 4038 'K1000000 100/COURSE1 score updated (55)' in fd.read()) 4039 4040 def test_scores_editing_scores_must_be_integers(self): 3983 4041 # Non-integer scores won't be accepted. 3984 self.browser.open( 3985 'http://localhost/app/faculties/fac1/' 3986 'dep1/courses/COURSE1/edit_scores') 3987 self.assertTrue('value="55" />' in self.browser.contents) 4042 self.login_as_lecturer() 4043 self.browser.open(self.edit_scores_url) 3988 4044 self.browser.getControl(name="scores", index=0).value = 'abc' 3989 4045 self.browser.getControl("Update scores").click() 3990 self.assertTrue('Error: Score(s) of Anna Tester have not be updated' 4046 self.assertTrue( 4047 'Error: Score(s) of Anna Tester have not be updated' 3991 4048 in self.browser.contents) 3992 # Scores can be removed. 3993 self.browser.open( 3994 'http://localhost/app/faculties/fac1/' 3995 'dep1/courses/COURSE1/edit_scores') 4049 4050 def test_scores_editing_allows_score_removal(self): 4051 # we can remove scores, once they were set 4052 self.login_as_lecturer() 4053 # without a prior value, we cannot remove 4054 self.student['studycourse']['100']['COURSE1'].score = None 4055 self.browser.open(self.edit_scores_url) 3996 4056 self.browser.getControl(name="scores", index=0).value = '' 3997 4057 self.browser.getControl("Update scores").click() 4058 logcontent = open(self.stud_log_path, 'r').read() 4059 self.assertFalse('COURSE1 score updated (None)' in logcontent) 4060 # now retry with some value set 4061 self.student['studycourse']['100']['COURSE1'].score = 55 4062 self.browser.getControl(name="scores", index=0).value = '' 4063 self.browser.getControl("Update scores").click() 4064 logcontent = open(self.stud_log_path, 'r').read() 4065 self.assertTrue('COURSE1 score updated (None)' in logcontent) 4066 4067 def test_lecturers_can_download_course_tickets(self): 4068 # A course ticket slip can be downloaded 4069 self.login_as_lecturer() 4070 pdf_url = '%s/coursetickets.pdf' % self.course_url 4071 self.browser.open(pdf_url) 4072 self.assertEqual(self.browser.headers['Status'], '200 Ok') 3998 4073 self.assertEqual( 3999 self.student['studycourse']['100']['COURSE1'].score, None) 4000 logcontent = open(logfile).read() 4001 self.assertTrue('mrslecturer - students.browser.EditScoresPage - ' 4002 'K1000000 100/COURSE1 score updated (None)' in logcontent) 4003 # A course ticket slip can be downloaded 4004 self.browser.open( 4005 'http://localhost/app/faculties/fac1/' 4006 'dep1/courses/COURSE1/coursetickets.pdf') 4007 self.assertEqual(self.browser.headers['Status'], '200 Ok') 4008 self.assertEqual(self.browser.headers['Content-Type'], 4009 'application/pdf') 4074 self.browser.headers['Content-Type'], 'application/pdf') 4010 4075 path = os.path.join(samples_dir(), 'coursetickets.pdf') 4011 4076 open(path, 'wb').write(self.browser.contents)
Note: See TracChangeset for help on using the changeset viewer.