Ignore:
Timestamp:
18 Mar 2013, 09:51:12 (12 years ago)
Author:
Henrik Bettermann
Message:

Add web service method which gets the course tickets registered by a student in a certain session.

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  
    11# Tests for webservices
    22import xmlrpclib
    3 import httplib
    4 import urllib
    5 import base64
    63from zope.app.testing.xmlrpc import ServerProxy
    74from zope.component import createObject
     
    118from waeup.kofa.testing import FunctionalLayer, FunctionalTestCase
    129from waeup.kofa.students.tests.test_browser import StudentsFullSetup
     10from waeup.kofa.students.studylevel import StudentStudyLevel, CourseTicket
    1311
    1412class XMLRPCTests(StudentsFullSetup):
     
    1614
    1715    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
    1836
    1937    def test_get_student_id_no_match(self):
     
    7694            'text/xml; charset=utf-8')
    7795        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  
    5959            return result[0].student_id
    6060        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.