Changeset 10040
- Timestamp:
- 18 Mar 2013, 16:45:34 (12 years ago)
- 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 36 36 study_level[ticket.code] = ticket 37 37 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 38 45 def test_get_student_id_no_match(self): 39 46 # w/o any students we get none … … 49 56 self.assertEqual(result, 'K1000000') 50 57 self.assertEqual(self.student_id, result) 51 return52 53 def test_get_student_id_block_unauthorized(self):54 # requests from unauthorized users are blocked55 # no username nor password56 server = ServerProxy('http://localhost/app')57 self.assertRaises(58 xmlrpclib.ProtocolError, server.get_student_id, '123')59 # wrong password60 server = ServerProxy('http://mgr:WRONGPW@localhost/app')61 self.assertRaises(62 xmlrpclib.ProtocolError, server.get_student_id, '123')63 # wrong username64 server = ServerProxy('http://WRONGUSER:mgrpw@localhost/app')65 self.assertRaises(66 xmlrpclib.ProtocolError, server.get_student_id, '123')67 return68 69 def test_XMLRPC_post_1(self):70 58 REQUEST_XML="""\ 71 59 <?xml version="1.0"?> … … 88 76 </methodResponse> 89 77 """ 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') 95 96 return 96 97 … … 108 109 self.assertEqual(result, 109 110 {'100|CRS1': 'Course 1', '100|COURSE1': 'Unnamed Course'}) 110 return111 112 def test_XMLRPC_post_2(self):113 self.setup_student(self.student)114 111 REQUEST_XML="""\ 115 112 <?xml version="1.0"?> … … 141 138 </methodResponse> 142 139 """ 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) 148 142 return 149 143 … … 154 148 self.assertEqual(result, None) 155 149 result = server.get_students_by_course('CRS1', '2012') 156 self.assertEqual(result, [ 'K1000000|234|my adviser'])150 self.assertEqual(result, [['K1000000', '234', 'my adviser'],]) 157 151 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) 159 182 return -
main/waeup.kofa/trunk/src/waeup/kofa/students/webservices.py
r10038 r10040 116 116 hitlist = [] 117 117 for ticket in coursetickets: 118 hitlist.append( '%s|%s|%s' %(118 hitlist.append(( 119 119 ticket.student.student_id, 120 120 ticket.student.matric_number,
Note: See TracChangeset for help on using the changeset viewer.