Ignore:
Timestamp:
3 Feb 2021, 21:26:18 (4 years ago)
Author:
Henrik Bettermann
Message:

Change webservice.

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

    r16391 r16392  
    55from cStringIO import StringIO
    66from zope.app.testing.xmlrpc import ServerProxy
    7 from zope.component import getUtility
     7from zope.component import getUtility, createObject
    88from waeup.kofa.interfaces import (
    99    IExtFileStore, IFileStoreNameChooser, IKofaUtils)
     
    1616
    1717class XMLRPCTests(StudentsFullSetup):
    18     # check XMLRPC services for university portal
    1918
    2019    layer = FunctionalLayer
     
    3433        ticket.code = u'CRS1'
    3534        ticket.title = u'Course 1'
    36         ticket.fcode = u'FAC1'
    37         ticket.dcode = u'DEP1'
     35        ticket.fcode = u'fac1'
     36        ticket.dcode = u'dep1'
    3837        ticket.credits = 100
    3938        ticket.passmark = 100
     
    224223
    225224    def test_get_students_by_department(self):
    226         self.setup_student(self.student)
    227         server = ServerProxy('http://mgr:mgrpw@localhost/app')
    228         result = server.get_students_by_department('fac1','dep1', '2012')
    229         self.assertEqual(result, [['COURSE1', 100, 2012, 'K1000000', '234', 'Anna Tester']])
     225        self.course2 = createObject('waeup.Course')
     226        self.course2.code = 'COURSE2'
     227        self.app['faculties']['fac1']['dep1'].courses.addCourse(
     228            self.course2)
     229        self.setup_student(self.student)
     230        ticket = CourseTicket()
     231        ticket.code = u'COURSE2'
     232        ticket.title = u'Course 2'
     233        ticket.fcode = u'fac1'
     234        ticket.dcode = u'fac1'
     235        self.student['studycourse']['100'][ticket.code] = ticket
     236        server = ServerProxy('http://mgr:mgrpw@localhost/app')
     237        result = server.get_students_by_department('fac1','dep1', '2011')
     238        self.assertEqual(result, {})
     239        result = server.get_students_by_department('fac1','dep1', '2012', '200')
     240        self.assertEqual(result, {})
     241        result = server.get_students_by_department('fac1','dep1', '2012', '100')
     242        self.assertEqual(
     243            result, {'K1000000': ['234', 'Anna Tester', ['COURSE1', 'COURSE2']]})
    230244        result = server.get_students_by_department('fac1','dep1')
    231         self.assertEqual(result, [['COURSE1', 100, 2012, 'K1000000', '234', 'Anna Tester']])
     245        self.assertEqual(
     246            result, {'K1000000': ['234', 'Anna Tester', ['COURSE1', 'COURSE2']]})
    232247        result = server.get_students_by_department('fac1','dep2')
    233248        self.assertEqual(result, None)
     
    248263<params>
    249264<param>
     265<value><struct>
     266<member>
     267<name>K1000000</name>
    250268<value><array><data>
     269<value><string>234</string></value>
     270<value><string>Anna Tester</string></value>
    251271<value><array><data>
    252272<value><string>COURSE1</string></value>
    253 <value><int>100</int></value>
    254 <value><int>2012</int></value>
    255 <value><string>K1000000</string></value>
    256 <value><string>234</string></value>
    257 <value><string>Anna Tester</string></value>
     273<value><string>COURSE2</string></value>
    258274</data></array></value>
    259275</data></array></value>
     276</member>
     277</struct></value>
    260278</param>
    261279</params>
  • main/waeup.kofa/trunk/src/waeup/kofa/students/webservices.py

    r16391 r16392  
    155155
    156156    @grok.require('waeup.xmlrpc')
    157     def get_students_by_department(self, faccode=None, depcode=None, session=None):
    158         """A webservice to pull student's registered courses in a department.
     157    def get_students_by_department(self, faccode=None, depcode=None,
     158                                   session=None, level=None):
     159        """A webservice to pull student's registered courses in a
     160        department
    159161        """
    160162        try:
    161163            session = int(session)
     164            level = int(level)
    162165        except (TypeError, ValueError):
    163166            pass
    164         sessionsearch = True
    165167        if session in (None, ''):
    166             sessionsearch = False
     168            session= None
     169        if level in (None, ''):
     170            level= None
    167171        try:
    168172            department =self.context['faculties'][faccode][depcode]
     
    171175        courses = department.courses.keys()
    172176        cat = queryUtility(ICatalog, name='coursetickets_catalog')
    173         hitlist = []
     177        hitdict = {}
    174178        for course in courses:
    175             if sessionsearch:
    176                 coursetickets = cat.searchResults(
    177                     session=(session, session),
    178                     code=(course, course))
    179             else:
    180                 coursetickets = cat.searchResults(
    181                     code=(course, course))
     179            coursetickets = cat.searchResults(
     180                session=(session, session),
     181                level=(level, level),
     182                code=(course, course))
    182183            for c_ticket in coursetickets:
    183                 hitlist.append((
    184                     c_ticket.code,
    185                     c_ticket.level,
    186                     c_ticket.level_session,
    187                     c_ticket.student.student_id,
    188                     c_ticket.student.matric_number,
    189                     c_ticket.student.display_fullname,
    190                     ))
    191         return list(set(hitlist))
     184                if not c_ticket.student.student_id in hitdict.keys():
     185                    hitdict[c_ticket.student.student_id] = (
     186                        c_ticket.student.matric_number,
     187                        c_ticket.student.display_fullname,
     188                        [c_ticket.code,])
     189                else:
     190                    hitdict[c_ticket.student.student_id][2].append(
     191                        c_ticket.code,)
     192        return hitdict
    192193
    193194    @grok.require('waeup.xmlrpc')
Note: See TracChangeset for help on using the changeset viewer.