Changeset 10035
- Timestamp:
- 18 Mar 2013, 09:05:35 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_webservices.py
r10034 r10035 1 1 # Tests for webservices 2 2 import xmlrpclib 3 import httplib 4 import urllib 5 import base64 3 6 from zope.app.testing.xmlrpc import ServerProxy 4 7 from zope.component import createObject … … 7 10 from waeup.kofa.app import University 8 11 from waeup.kofa.testing import FunctionalLayer, FunctionalTestCase 12 from waeup.kofa.students.tests.test_browser import StudentsFullSetup 9 13 10 class XMLRPCTests( FunctionalTestCase):14 class XMLRPCTests(StudentsFullSetup): 11 15 # check XMLRPC services for university portal 12 16 13 17 layer = FunctionalLayer 14 18 15 def setUp(self):16 super(XMLRPCTests, self).setUp()17 # create a site18 self.root = self.getRootFolder()19 self.app = University()20 self.root['app'] = self.app21 return22 23 def create_student(self, reg_no=u'REG123'):24 # create a student in site25 setSite(self.app) # needed to create a student26 stud = createObject('waeup.Student')27 stud.reg_number = reg_no28 self.app['students'].addStudent(stud)29 setSite(None) # make sure no site is set when returning30 return stud31 32 19 def test_get_student_id_no_match(self): 33 20 # w/o any students we get none 34 21 server = ServerProxy('http://mgr:mgrpw@localhost/app') 35 result = server.get_student_id(' R123')22 result = server.get_student_id('Nonsense') 36 23 self.assertTrue(result is None) 37 24 return … … 39 26 def test_get_student_id_regno_exists(self): 40 27 # we can get the id of an existing student with matching reg_no 41 stud1 = self.create_student(reg_no=u'R123')42 28 server = ServerProxy('http://mgr:mgrpw@localhost/app') 43 result = server.get_student_id(' R123')29 result = server.get_student_id('123') 44 30 self.assertEqual(result, 'K1000000') 45 self.assertEqual(s tud1.student_id, result)31 self.assertEqual(self.student_id, result) 46 32 return 47 33 … … 51 37 server = ServerProxy('http://localhost/app') 52 38 self.assertRaises( 53 xmlrpclib.ProtocolError, server.get_student_id, ' R123')39 xmlrpclib.ProtocolError, server.get_student_id, '123') 54 40 # wrong password 55 41 server = ServerProxy('http://mgr:WRONGPW@localhost/app') 56 42 self.assertRaises( 57 xmlrpclib.ProtocolError, server.get_student_id, ' R123')43 xmlrpclib.ProtocolError, server.get_student_id, '123') 58 44 # wrong username 59 45 server = ServerProxy('http://WRONGUSER:mgrpw@localhost/app') 60 46 self.assertRaises( 61 xmlrpclib.ProtocolError, server.get_student_id, ' R123')47 xmlrpclib.ProtocolError, server.get_student_id, '123') 62 48 return 49 50 REQUEST_XML="""\ 51 <?xml version="1.0"?> 52 <methodCall> 53 <methodName>get_student_id</methodName> 54 <params> 55 <param> 56 <value><string>123</string></value> 57 </param> 58 </params> 59 </methodCall>""" 60 61 RESPONSE_XML="""\ 62 <?xml version='1.0'?> 63 <methodResponse> 64 <params> 65 <param> 66 <value><string>K1000000</string></value> 67 </param> 68 </params> 69 </methodResponse> 70 """ 71 72 def test_XMLRPC_post(self): 73 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 74 self.browser.addHeader('Content-Length', len(self.REQUEST_XML)) 75 self.browser.post('http://localhost/app', self.REQUEST_XML, 76 'text/xml; charset=utf-8') 77 self.assertEqual(self.browser.contents, self.RESPONSE_XML)
Note: See TracChangeset for help on using the changeset viewer.