Changeset 10040


Ignore:
Timestamp:
18 Mar 2013, 16:45:34 (12 years ago)
Author:
Henrik Bettermann
Message:

get_students_by_course: return list of lists.

Harmonize tests.

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

    r10038 r10040  
    3636        study_level[ticket.code] = ticket
    3737
     38    def XMLRPC_post(self, body):
     39        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     40        self.browser.addHeader('Content-Length', len(body))
     41        self.browser.post('http://localhost/app', body,
     42            'text/xml; charset=utf-8')
     43        return self.browser.contents
     44
    3845    def test_get_student_id_no_match(self):
    3946        # w/o any students we get none
     
    4956        self.assertEqual(result, 'K1000000')
    5057        self.assertEqual(self.student_id, result)
    51         return
    52 
    53     def test_get_student_id_block_unauthorized(self):
    54         # requests from unauthorized users are blocked
    55         # no username nor password
    56         server = ServerProxy('http://localhost/app')
    57         self.assertRaises(
    58             xmlrpclib.ProtocolError, server.get_student_id, '123')
    59         # wrong password
    60         server = ServerProxy('http://mgr:WRONGPW@localhost/app')
    61         self.assertRaises(
    62             xmlrpclib.ProtocolError, server.get_student_id, '123')
    63         # wrong username
    64         server = ServerProxy('http://WRONGUSER:mgrpw@localhost/app')
    65         self.assertRaises(
    66             xmlrpclib.ProtocolError, server.get_student_id, '123')
    67         return
    68 
    69     def test_XMLRPC_post_1(self):
    7058        REQUEST_XML="""\
    7159<?xml version="1.0"?>
     
    8876</methodResponse>
    8977"""
    90         self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    91         self.browser.addHeader('Content-Length', len(REQUEST_XML))
    92         self.browser.post('http://localhost/app', REQUEST_XML,
    93             'text/xml; charset=utf-8')
    94         self.assertEqual(self.browser.contents, RESPONSE_XML)
     78        xmlout = self.XMLRPC_post(REQUEST_XML)
     79        self.assertEqual(xmlout, RESPONSE_XML)
     80        return
     81
     82    def test_get_student_id_block_unauthorized(self):
     83        # requests from unauthorized users are blocked
     84        # no username nor password
     85        server = ServerProxy('http://localhost/app')
     86        self.assertRaises(
     87            xmlrpclib.ProtocolError, server.get_student_id, '123')
     88        # wrong password
     89        server = ServerProxy('http://mgr:WRONGPW@localhost/app')
     90        self.assertRaises(
     91            xmlrpclib.ProtocolError, server.get_student_id, '123')
     92        # wrong username
     93        server = ServerProxy('http://WRONGUSER:mgrpw@localhost/app')
     94        self.assertRaises(
     95            xmlrpclib.ProtocolError, server.get_student_id, '123')
    9596        return
    9697
     
    108109        self.assertEqual(result,
    109110            {'100|CRS1': 'Course 1', '100|COURSE1': 'Unnamed Course'})
    110         return
    111 
    112     def test_XMLRPC_post_2(self):
    113         self.setup_student(self.student)
    114111        REQUEST_XML="""\
    115112<?xml version="1.0"?>
     
    141138</methodResponse>
    142139"""
    143         self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    144         self.browser.addHeader('Content-Length', len(REQUEST_XML))
    145         self.browser.post('http://localhost/app', REQUEST_XML,
    146             'text/xml; charset=utf-8')
    147         self.assertEqual(self.browser.contents, RESPONSE_XML)
     140        xmlout = self.XMLRPC_post(REQUEST_XML)
     141        self.assertEqual(xmlout, RESPONSE_XML)
    148142        return
    149143
     
    154148        self.assertEqual(result, None)
    155149        result = server.get_students_by_course('CRS1', '2012')
    156         self.assertEqual(result, ['K1000000|234|my adviser'])
     150        self.assertEqual(result, [['K1000000', '234', 'my adviser'],])
    157151        result = server.get_students_by_course('CRS1')
    158         self.assertEqual(result, ['K1000000|234|my adviser'])
     152        self.assertEqual(result, [['K1000000', '234', 'my adviser'],])
     153        REQUEST_XML="""\
     154<?xml version="1.0"?>
     155<methodCall>
     156<methodName>get_students_by_course</methodName>
     157<params>
     158<param>
     159<value><string>CRS1</string></value>
     160<value><string>2012</string></value>
     161</param>
     162</params>
     163</methodCall>"""
     164        RESPONSE_XML="""\
     165<?xml version='1.0'?>
     166<methodResponse>
     167<params>
     168<param>
     169<value><array><data>
     170<value><array><data>
     171<value><string>K1000000</string></value>
     172<value><string>234</string></value>
     173<value><string>my adviser</string></value>
     174</data></array></value>
     175</data></array></value>
     176</param>
     177</params>
     178</methodResponse>
     179"""
     180        xmlout = self.XMLRPC_post(REQUEST_XML)
     181        self.assertEqual(xmlout, RESPONSE_XML)
    159182        return
  • main/waeup.kofa/trunk/src/waeup/kofa/students/webservices.py

    r10038 r10040  
    116116        hitlist = []
    117117        for ticket in coursetickets:
    118             hitlist.append('%s|%s|%s' % (
     118            hitlist.append((
    119119                ticket.student.student_id,
    120120                ticket.student.matric_number,
Note: See TracChangeset for help on using the changeset viewer.