Ignore:
Timestamp:
21 Mar 2013, 16:12:06 (12 years ago)
Author:
Henrik Bettermann
Message:

Add two more webservice methods.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_webservices.py

    r10041 r10042  
    11# Tests for webservices
    22import xmlrpclib
     3import os
     4from cStringIO import StringIO
    35from zope.app.testing.xmlrpc import ServerProxy
    4 from zope.component import createObject
     6from zope.component import createObject, getUtility
    57from zope.component.hooks import setSite
    68from zope.testbrowser.testing import Browser
    79from waeup.kofa.app import University
     10from waeup.kofa.interfaces import IExtFileStore, IFileStoreNameChooser
    811from waeup.kofa.testing import FunctionalLayer, FunctionalTestCase
    912from waeup.kofa.students.tests.test_browser import StudentsFullSetup
     
    3538        ticket.semester = 2
    3639        study_level[ticket.code] = ticket
     40
     41    def create_passport_img(self, student):
     42        # create some passport file for `student`
     43        storage = getUtility(IExtFileStore)
     44        image_path = os.path.join(os.path.dirname(__file__), 'test_image.jpg')
     45        self.image_contents = open(image_path, 'rb').read()
     46        file_id = IFileStoreNameChooser(student).chooseName(
     47            attr='passport.jpg')
     48        storage.createFile(file_id, StringIO(self.image_contents))
    3749
    3850    def XMLRPC_post(self, body):
     
    191203        self.assertEqual(xmlout, RESPONSE_XML)
    192204        return
     205
     206    def test_get_student_info(self):
     207        server = ServerProxy('http://mgr:mgrpw@localhost/app')
     208        self.setup_student(self.student)
     209        result = server.get_student_info('123')
     210        self.assertEqual(result,
     211            ['Anna Tester', 'CERT1', '1234', 'aa@aa.ng'])
     212        REQUEST_XML="""\
     213<?xml version="1.0"?>
     214<methodCall>
     215<methodName>get_student_info</methodName>
     216<params>
     217<param>
     218<value><string>K1000000</string></value>
     219</param>
     220</params>
     221</methodCall>"""
     222        RESPONSE_XML="""\
     223<?xml version='1.0'?>
     224<methodResponse>
     225<params>
     226<param>
     227<value><array><data>
     228<value><string>Anna Tester</string></value>
     229<value><string>CERT1</string></value>
     230<value><string>1234</string></value>
     231<value><string>aa@aa.ng</string></value>
     232</data></array></value>
     233</param>
     234</params>
     235</methodResponse>
     236"""
     237        xmlout = self.XMLRPC_post(REQUEST_XML)
     238        self.assertEqual(xmlout, RESPONSE_XML)
     239        return
     240
     241    def test_get_student_passport(self):
     242        server = ServerProxy('http://mgr:mgrpw@localhost/app')
     243        self.setup_student(self.student)
     244        self.create_passport_img(self.student)
     245        result = server.get_student_passport('123')
     246        img = getUtility(IExtFileStore).getFileByContext(
     247            self.student, attr='passport.jpg')
     248        binary = img.read()
     249        self.assertEqual(binary, result)
     250        REQUEST_XML="""\
     251<?xml version="1.0"?>
     252<methodCall>
     253<methodName>get_student_passport</methodName>
     254<params>
     255<param>
     256<value><string>K1000000</string></value>
     257</param>
     258</params>
     259</methodCall>"""
     260        RESPONSE_XML="""\
     261<?xml version='1.0'?>
     262<methodResponse>
     263<params>
     264<param>
     265<value><base64>
     266/9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAAPAAA/+4ADkFkb2JlAGTAAAAAAf/b
     267"""
     268        xmlout = self.XMLRPC_post(REQUEST_XML)
     269        self.assertTrue(xmlout.startswith(RESPONSE_XML))
Note: See TracChangeset for help on using the changeset viewer.