Changeset 10036 for main/waeup.kofa/trunk/src/waeup/kofa
- Timestamp:
- 18 Mar 2013, 09:51:12 (12 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/students
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_webservices.py
r10035 r10036 1 1 # Tests for webservices 2 2 import xmlrpclib 3 import httplib4 import urllib5 import base646 3 from zope.app.testing.xmlrpc import ServerProxy 7 4 from zope.component import createObject … … 11 8 from waeup.kofa.testing import FunctionalLayer, FunctionalTestCase 12 9 from waeup.kofa.students.tests.test_browser import StudentsFullSetup 10 from waeup.kofa.students.studylevel import StudentStudyLevel, CourseTicket 13 11 14 12 class XMLRPCTests(StudentsFullSetup): … … 16 14 17 15 layer = FunctionalLayer 16 17 def setup_student(self, student): 18 study_level = StudentStudyLevel() 19 study_level.level_session = 2012 20 study_level.level_verdict = "A" 21 study_level.level = 100 22 student['studycourse'].addStudentStudyLevel( 23 self.certificate, study_level) 24 25 ticket = CourseTicket() 26 ticket.automatic = True 27 ticket.carry_over = True 28 ticket.code = u'CRS1' 29 ticket.title = u'Course 1' 30 ticket.fcode = u'FAC1' 31 ticket.dcode = u'DEP1' 32 ticket.credits = 100 33 ticket.passmark = 100 34 ticket.semester = 2 35 study_level[ticket.code] = ticket 18 36 19 37 def test_get_student_id_no_match(self): … … 76 94 'text/xml; charset=utf-8') 77 95 self.assertEqual(self.browser.contents, self.RESPONSE_XML) 96 97 def test_get_courses_by_session(self): 98 server = ServerProxy('http://mgr:mgrpw@localhost/app') 99 result = server.get_courses_by_session('K1000000') 100 self.assertEqual(result, None) 101 self.setup_student(self.student) 102 result = server.get_courses_by_session('K1000000', '2010') 103 self.assertEqual(result, None) 104 result = server.get_courses_by_session('K1000000', '2012') 105 self.assertEqual(result, 106 {'100|CRS1': 'Course 1', '100|COURSE1': 'Unnamed Course'}) 107 result = server.get_courses_by_session('K1000000') 108 self.assertEqual(result, 109 {'100|CRS1': 'Course 1', '100|COURSE1': 'Unnamed Course'}) 110 return -
main/waeup.kofa/trunk/src/waeup/kofa/students/webservices.py
r10033 r10036 59 59 return result[0].student_id 60 60 return None 61 62 @grok.require('waeup.xmlrpc') 63 def get_courses_by_session(self, student_id=None, session=None): 64 """Get the course tickets registered by a student in a certain session. 65 66 """ 67 if student_id is None: 68 return None 69 student = self.context['students'].get(student_id, None) 70 if student is None: 71 return None 72 try: 73 session = int(session) 74 except (TypeError, ValueError): 75 pass 76 sessionsearch = True 77 if session in (None, ''): 78 sessionsearch = False 79 studycourse = student['studycourse'] 80 coursetickets = {} 81 for level in studycourse.values(): 82 if sessionsearch and level.level_session != session: 83 continue 84 for ct in level.values(): 85 coursetickets.update( 86 {"%s|%s" % (level.level, ct.code): ct.title}) 87 if not coursetickets: 88 return None 89 return coursetickets
Note: See TracChangeset for help on using the changeset viewer.