source: main/kofacustom.unidel/trunk/src/kofacustom/unidel/students/tests/test_browser.py @ 17932

Last change on this file since 17932 was 17906, checked in by Henrik Bettermann, 3 months ago

Increase WAEAC charge.

  • Property svn:keywords set to Id
File size: 5.8 KB
Line 
1## $Id: test_browser.py 17906 2024-08-29 06:17:43Z henrik $
2##
3## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18import os
19import shutil
20import tempfile
21from StringIO import StringIO
22from hurry.workflow.interfaces import IWorkflowState, IWorkflowInfo
23from mechanize import LinkNotFoundError
24from zope.securitypolicy.interfaces import IPrincipalRoleManager
25from zope.component.hooks import setSite, clearSite
26from zope.component import getUtility, createObject
27from zope.interface import verify
28from zope.event import notify
29from waeup.kofa.authentication import LocalRoleSetEvent
30from waeup.kofa.app import University
31from waeup.kofa.students.tests.test_browser import StudentsFullSetup
32from waeup.kofa.students.accommodation import BedTicket
33from waeup.kofa.testing import FunctionalTestCase
34from waeup.kofa.interfaces import (
35    IExtFileStore, IFileStoreNameChooser)
36from waeup.kofa.interfaces import IUserAccount, IJobManager, VALIDATED, CREATED
37from waeup.kofa.browser.tests.test_pdf import samples_dir
38from waeup.kofa.students.interfaces import IStudentsUtils
39from waeup.kofa.tests.test_authentication import SECRET
40from kofacustom.unidel.testing import FunctionalLayer
41
42
43class StudentsContainerUITests(StudentsFullSetup):
44    # Tests for StudentsContainer class views and pages
45
46    layer = FunctionalLayer
47
48    def test_student_examclearance_slip(self):
49        self.certificate.study_mode = 'ug_ft'
50        # Student cant login if their password is not set
51        IWorkflowState(self.student).setState('courses registered')
52        self.browser.open(self.login_path)
53        self.browser.getControl(name="form.login").value = self.student_id
54        self.browser.getControl(name="form.password").value = 'spwd'
55        self.browser.getControl("Login").click()
56        self.assertMatches(
57            '...You logged in...', self.browser.contents)
58        self.browser.getLink("Base Data").click()
59        ## Unidel changed it's mind again and again
60        self.assertRaises(
61            LinkNotFoundError,
62            self.browser.getLink, 'Download examination clearance slip')
63        #self.browser.getLink("Download examination clearance slip").click()
64        #self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
65        #self.browser.getLink("Base Data").click()
66        #self.browser.getLink("Download examination clearance slip").click()
67        #self.assertEqual(self.browser.headers['Status'], '200 Ok')
68        #self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
69        #path = os.path.join(samples_dir(), 'examclearance_slip.pdf')
70        #open(path, 'wb').write(self.browser.contents)
71        #print "Sample exampclearance_slip.pdf written to %s" % path
72
73class LecturerUITests(StudentsFullSetup):
74
75    layer = FunctionalLayer
76
77    def login_as_lecturer(self):
78        self.app['users'].addUser('mrslecturer', SECRET)
79        self.app['users']['mrslecturer'].email = 'mrslecturer@foo.ng'
80        self.app['users']['mrslecturer'].title = u'Mercedes Benz'
81        # Add course ticket
82        self.studylevel = createObject(u'waeup.StudentStudyLevel')
83        self.studylevel.level = 100
84        self.studylevel.level_session = 2004
85        self.student['studycourse'].addStudentStudyLevel(
86            self.certificate, self.studylevel)
87        # Assign local Lecturer role for a course.
88        course = self.app['faculties']['fac1']['dep1'].courses['COURSE1']
89        prmlocal = IPrincipalRoleManager(course)
90        prmlocal.assignRoleToPrincipal('waeup.local.Lecturer', 'mrslecturer')
91        notify(LocalRoleSetEvent(
92            course, 'waeup.local.Lecturer', 'mrslecturer', granted=True))
93        # Login as lecturer.
94        self.browser.open(self.login_path)
95        self.browser.getControl(name="form.login").value = 'mrslecturer'
96        self.browser.getControl(
97            name="form.password").value = SECRET
98        self.browser.getControl("Login").click()
99        # Store reused urls/paths
100        self.course_url = (
101            'http://localhost/app/faculties/fac1/dep1/courses/COURSE1')
102        self.edit_scores_url = '%s/edit_scores' % self.course_url
103        # Set standard parameters
104        self.app['configuration'].current_academic_session = 2004
105        self.app['faculties']['fac1']['dep1'].score_editing_disabled = False
106        IWorkflowState(self.student).setState(VALIDATED)
107
108    def test_lecturers_can_download_attendance_sheet(self):
109        # A course ticket slip can be downloaded
110        self.course.title = (u'Lorem ipsum     dolor sit amet, consectetur     adipisici, '
111                             u'sed         eiusmod tempor    incidunt ut  labore et dolore')
112        self.student.firstname = u'Emmanuella Woyengifigha Mercy Onosemudiana'
113        self.student.lastname = u'OYAKEMIEGBEGHA'
114        self.student.matric_number = u'CMS/FBM/NSG/17/38186'
115        self.login_as_lecturer()
116        pdf_url = '%s/attendance.pdf' % self.course_url
117        self.browser.open(pdf_url)
118        self.assertEqual(self.browser.headers['Status'], '200 Ok')
119        self.assertEqual(
120            self.browser.headers['Content-Type'], 'application/pdf')
121        path = os.path.join(samples_dir(), 'attendance.pdf')
122        open(path, 'wb').write(self.browser.contents)
123        print "Sample PDF attendance.pdf written to %s" % path
Note: See TracBrowser for help on using the repository browser.