Ignore:
Timestamp:
11 Jun 2016, 21:16:34 (8 years ago)
Author:
uli
Message:

Split overlong test and move into own TestCase?.

Lecturers certainly deserve an own test case.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/branches/uli-scores-upload/src/waeup/kofa/students/tests/test_browser.py

    r13908 r13917  
    18071807        self.assertTrue(self.student_id in self.browser.contents)
    18081808
    1809     def test_handle_courses_by_lecturer(self):
    1810         self.app['users'].addUser('mrslecturer', 'mrslecturersecret')
    1811         self.app['users']['mrslecturer'].email = 'mrslecturer@foo.ng'
    1812         self.app['users']['mrslecturer'].title = u'Mercedes Benz'
    1813         # Add course ticket
    1814         studylevel = createObject(u'waeup.StudentStudyLevel')
    1815         studylevel.level = 100
    1816         studylevel.level_session = 2004
    1817         self.student['studycourse'].addStudentStudyLevel(
    1818             self.certificate, studylevel)
    1819         # Assign local Lecturer role for a certificate.
    1820         course = self.app['faculties']['fac1']['dep1'].courses['COURSE1']
    1821         prmlocal = IPrincipalRoleManager(course)
    1822         prmlocal.assignRoleToPrincipal('waeup.local.Lecturer', 'mrslecturer')
    1823         notify(LocalRoleSetEvent(
    1824             course, 'waeup.local.Lecturer', 'mrslecturer', granted=True))
    1825         # Login as lecturer.
    1826         self.browser.open(self.login_path)
    1827         self.browser.getControl(name="form.login").value = 'mrslecturer'
    1828         self.browser.getControl(
    1829             name="form.password").value = 'mrslecturersecret'
    1830         self.browser.getControl("Login").click()
    1831         self.assertMatches('...You logged in...', self.browser.contents)
    1832         # Lecturer is on landing page
    1833         self.assertTrue('(<span>COURSE1</span>)' in self.browser.contents)
    1834         # Lecturer can click the 'My Roles' link.
    1835         self.browser.getLink("My Roles").click()
    1836         self.assertMatches(
    1837             '...<div>Academics Officer (view only)</div>...',
    1838             self.browser.contents)
    1839         self.assertMatches(
    1840             '...<a href="http://localhost/app/'
    1841             'faculties/fac1/dep1/courses/COURSE1">...',
    1842             self.browser.contents)
    1843         self.assertFalse('(<span>COURSE1</span>)' in self.browser.contents)
    1844         # Lecturer can click the 'My Courses' link ...
    1845         self.browser.getLink("My Courses").click()
    1846         # ... and is is back on landing page
    1847         self.assertTrue('(<span>COURSE1</span>)' in self.browser.contents)
    1848         # The lecturer can go to her course ...
    1849         self.browser.getLink("COURSE1").click()
    1850         # Lecturers can neither filter students ...
    1851         self.assertRaises(
    1852             Unauthorized, self.browser.open,
    1853             "http://localhost/app/faculties/fac1/dep1/courses/COURSE1/students")
    1854         # ... nor access the student ...
    1855         self.assertRaises(
    1856             Unauthorized, self.browser.open, self.student_path)
    1857         # ... nor the respective course ticket since
    1858         # editing course tickets by lecturers is not feasible.
    1859         self.assertTrue('COURSE1' in self.student['studycourse']['100'].keys())
    1860         course_ticket_path = self.student_path + '/studycourse/100/COURSE1'
    1861         self.assertRaises(
    1862             Unauthorized, self.browser.open, course_ticket_path)
    1863         # Course results can be batch edited via the edit_courses view.
    1864         self.app['faculties']['fac1']['dep1'].score_editing_disabled = True
    1865         self.browser.open(
    1866             "http://localhost/app/faculties/fac1/dep1/courses/COURSE1")
    1867         self.browser.getLink("Update scores").click()
    1868         self.assertTrue('Score editing disabled' in self.browser.contents)
    1869         self.app['faculties']['fac1']['dep1'].score_editing_disabled = False
    1870         self.browser.getLink("Update scores").click()
    1871         self.assertTrue(
    1872             'Current academic session not set' in self.browser.contents)
    1873         self.app['configuration'].current_academic_session = 2004
    1874         self.browser.getLink("Update scores").click()
    1875         self.assertFalse(
    1876             '<input type="text" name="scores" class="span1" />'
    1877             in self.browser.contents)
    1878         IWorkflowState(self.student).setState('courses validated')
    1879         # Student must be in state 'courses validated'.
    1880         self.browser.open(
    1881             'http://localhost/app/faculties/fac1/'
    1882             'dep1/courses/COURSE1/edit_scores')
    1883         self.assertTrue(
    1884             'input type="text" name="scores"' in self.browser.contents)
    1885         self.browser.getControl(name="scores", index=0).value = '55'
    1886         self.browser.getControl("Update scores").click()
    1887         # New score has been set.
    1888         self.assertEqual(
    1889             self.student['studycourse']['100']['COURSE1'].score, 55)
    1890         # Score editing has been logged.
    1891         logfile = os.path.join(
    1892             self.app['datacenter'].storage, 'logs', 'students.log')
    1893         logcontent = open(logfile).read()
    1894         self.assertTrue('mrslecturer - students.browser.EditScoresPage - '
    1895             'K1000000 100/COURSE1 score updated (55)' in logcontent)
    1896         # Non-integer scores won't be accepted.
    1897         self.browser.open(
    1898             'http://localhost/app/faculties/fac1/'
    1899             'dep1/courses/COURSE1/edit_scores')
    1900         self.assertTrue('value="55" />' in self.browser.contents)
    1901         self.browser.getControl(name="scores", index=0).value = 'abc'
    1902         self.browser.getControl("Update scores").click()
    1903         self.assertTrue('Error: Score(s) of Anna Tester have not be updated'
    1904             in self.browser.contents)
    1905         # Scores can be removed.
    1906         self.browser.open(
    1907             'http://localhost/app/faculties/fac1/'
    1908             'dep1/courses/COURSE1/edit_scores')
    1909         self.browser.getControl(name="scores", index=0).value = ''
    1910         self.browser.getControl("Update scores").click()
    1911         self.assertEqual(
    1912             self.student['studycourse']['100']['COURSE1'].score, None)
    1913         logcontent = open(logfile).read()
    1914         self.assertTrue('mrslecturer - students.browser.EditScoresPage - '
    1915             'K1000000 100/COURSE1 score updated (None)' in logcontent)
    1916         # A course ticket slip can be downloaded
    1917         self.browser.open(
    1918             'http://localhost/app/faculties/fac1/'
    1919             'dep1/courses/COURSE1/coursetickets.pdf')
    1920         self.assertEqual(self.browser.headers['Status'], '200 Ok')
    1921         self.assertEqual(self.browser.headers['Content-Type'],
    1922                          'application/pdf')
    1923         path = os.path.join(samples_dir(), 'coursetickets.pdf')
    1924         open(path, 'wb').write(self.browser.contents)
    1925         print "Sample PDF coursetickets.pdf written to %s" % path
    1926 
    19271809    def test_change_current_mode(self):
    19281810        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     
    40043886        self.browser.getControl("Discard").click()
    40053887        self.assertEqual(len(self.app['datacenter'].running_exports), 0)
     3888
     3889
     3890class LecturerUITests(StudentsFullSetup):
     3891    # Tests for UI actions when acting as lecturer.
     3892
     3893    def login_as_lecturer(self):
     3894        self.app['users'].addUser('mrslecturer', 'mrslecturersecret')
     3895        self.app['users']['mrslecturer'].email = 'mrslecturer@foo.ng'
     3896        self.app['users']['mrslecturer'].title = u'Mercedes Benz'
     3897        # Add course ticket
     3898        studylevel = createObject(u'waeup.StudentStudyLevel')
     3899        studylevel.level = 100
     3900        studylevel.level_session = 2004
     3901        self.student['studycourse'].addStudentStudyLevel(
     3902            self.certificate, studylevel)
     3903        # Assign local Lecturer role for a certificate.
     3904        course = self.app['faculties']['fac1']['dep1'].courses['COURSE1']
     3905        prmlocal = IPrincipalRoleManager(course)
     3906        prmlocal.assignRoleToPrincipal('waeup.local.Lecturer', 'mrslecturer')
     3907        notify(LocalRoleSetEvent(
     3908            course, 'waeup.local.Lecturer', 'mrslecturer', granted=True))
     3909        # Login as lecturer.
     3910        self.browser.open(self.login_path)
     3911        self.browser.getControl(name="form.login").value = 'mrslecturer'
     3912        self.browser.getControl(
     3913            name="form.password").value = 'mrslecturersecret'
     3914        self.browser.getControl("Login").click()
     3915
     3916    def test_handle_courses_by_lecturer(self):
     3917        self.login_as_lecturer()
     3918        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.
     3922        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 ...
     3932        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 ...
     3936        self.browser.getLink("COURSE1").click()
     3937        # Lecturers can neither filter students ...
     3938        self.assertRaises(
     3939            Unauthorized, self.browser.open,
     3940            "http://localhost/app/faculties/fac1/dep1/courses/COURSE1/students")
     3941        # ... nor access the student ...
     3942        self.assertRaises(
     3943            Unauthorized, self.browser.open, self.student_path)
     3944        # ... nor the respective course ticket since
     3945        # editing course tickets by lecturers is not feasible.
     3946        self.assertTrue('COURSE1' in self.student['studycourse']['100'].keys())
     3947        course_ticket_path = self.student_path + '/studycourse/100/COURSE1'
     3948        self.assertRaises(
     3949            Unauthorized, self.browser.open, course_ticket_path)
     3950        # Course results can be batch edited via the edit_courses view.
     3951        self.app['faculties']['fac1']['dep1'].score_editing_disabled = True
     3952        self.browser.open(
     3953            "http://localhost/app/faculties/fac1/dep1/courses/COURSE1")
     3954        self.browser.getLink("Update scores").click()
     3955        self.assertTrue('Score editing disabled' in self.browser.contents)
     3956        self.app['faculties']['fac1']['dep1'].score_editing_disabled = False
     3957        self.browser.getLink("Update scores").click()
     3958        self.assertTrue(
     3959            'Current academic session not set' in self.browser.contents)
     3960        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)
     3972        self.browser.getControl(name="scores", index=0).value = '55'
     3973        self.browser.getControl("Update scores").click()
     3974        # New score has been set.
     3975        self.assertEqual(
     3976            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)
     3983        # 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)
     3988        self.browser.getControl(name="scores", index=0).value = 'abc'
     3989        self.browser.getControl("Update scores").click()
     3990        self.assertTrue('Error: Score(s) of Anna Tester have not be updated'
     3991            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')
     3996        self.browser.getControl(name="scores", index=0).value = ''
     3997        self.browser.getControl("Update scores").click()
     3998        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')
     4010        path = os.path.join(samples_dir(), 'coursetickets.pdf')
     4011        open(path, 'wb').write(self.browser.contents)
     4012        print "Sample PDF coursetickets.pdf written to %s" % path
Note: See TracChangeset for help on using the changeset viewer.