Changeset 10526 for main/waeup.cas/trunk/waeup/cas/tests
- Timestamp:
- 22 Aug 2013, 21:21:52 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.cas/trunk/waeup/cas/tests/test_authenticators.py
r10524 r10526 186 186 'type': 'applicant'} 187 187 if username in ( 188 'fault1', 'fault2', 'fault3', 'fault4', 'fault7') and password == 'biz': 188 'fault1', 'fault2', 189 'fault3', 'fault4', 'fault7') and password == 'biz': 189 190 return {'type': 'student'} 190 191 if username == 'fault5' and password == 'biz': … … 231 232 # fake Moodle core_user_create_users method. 232 233 if arg[0]['username'] == 'school1-fault1': 233 raise xmlrpclib.Fault('faultCode', 'faultString') 234 if arg[0]['username'] in ('school1-fault4', 'school1-fault5'): 235 raise xmlrpclib.Fault('faultCode', 'Username already exists') 234 raise xmlrpclib.Fault('faultCode', 'core_user_create_users failed') 236 235 if arg[0]['username'] == 'school1-fault7': 237 236 raise xmlrpclib.Fault('faultCode', 'Email address already exists') 238 return None237 return [{'username': 'any name', 'id': 37}] 239 238 240 239 def _core_user_get_users(self, arg): 241 240 # fake Moodle core_user_get_users method. 242 241 if arg[0]['value'] == 'SCHOOL1-fault2': 243 raise xmlrpclib.Fault('faultCode', ' faultString')242 raise xmlrpclib.Fault('faultCode', 'core_user_get_users failed') 244 243 if arg[0]['value'] == 'SCHOOL1-fault3': 245 244 return {'users':[{'id':'SCHOOL1-fault3'}]} 246 return {'users':[{'id':'any id'}]} 245 if arg[0]['value'] in ('SCHOOL1-fault4', 'SCHOOL1-fault5'): 246 return {'users':[{'id': 123}]} 247 return {'users': []} 247 248 248 249 def _core_user_update_users(self, arg): 249 250 # fake Moodle core_user_update_users method. 250 251 if arg[0]['id'] == 'SCHOOL1-fault3': 251 raise xmlrpclib.Fault('faultCode', ' faultString')252 raise xmlrpclib.Fault('faultCode', 'core_user_update_users failed') 252 253 return None 253 254 … … 318 319 result = proxy.core_user_create_users( 319 320 [{'username': 'any name'}]) 320 assert result == None321 assert result == [{'id': 37, 'username': 'any name'}] 321 322 self.assertRaises( 322 323 xmlrpclib.Fault, proxy.core_user_create_users, … … 326 327 [{'username': 'school1-fault7'}]) 327 328 # test core_user_get_users 328 result = proxy.core_user_get_users(329 [{'key': 'username', 'value': 'any name'}])330 assert result == {'users':[{'id':'any id'}]}331 329 self.assertRaises( 332 330 xmlrpclib.Fault, proxy.core_user_get_users, … … 334 332 # test core_user_update_users 335 333 result = proxy.core_user_update_users( 336 [{'id': 'any id'}])334 [{'id': 234}]) 337 335 assert result == None 338 336 self.assertRaises( … … 358 356 result1a = auth.check_credentials('SCHOOL1-pig', 'pog') 359 357 assert result1a == (True, '') 358 # user does not exist 360 359 result2s = auth.check_credentials('SCHOOL1-foo', 'bar') 361 360 assert result2s == (False, 'Invalid username or password') 361 # school does not exist 362 362 result3s = auth.check_credentials('SCHOOL2-bar', 'baz') 363 363 assert result3s == (False, 'Invalid username or password') 364 # user is neither a student nor an applicant 364 365 result8 = auth.check_credentials('SCHOOL1-fault6', 'biz') 365 366 assert result8 == (False, 'User not eligible') 367 # user has an existing email address 366 368 result9 = auth.check_credentials('SCHOOL1-fault7', 'biz') 367 369 assert result9 == (False, … … 369 371 ' Email addresses can\'t be used twice in Moodle.') 370 372 371 # exception s are raised in the following cases373 # exception is catched if core_user_create_users fails 372 374 result4s = auth.check_credentials('SCHOOL1-fault1', 'biz') 373 assert result4s == (False, 'faultString') 375 assert result4s == (False, 'core_user_create_users failed') 376 # exception is catched if core_user_get_users fails 374 377 result5s = auth.check_credentials('SCHOOL1-fault2', 'biz') 375 assert result5s == (False, 'faultString') 378 assert result5s == (False, 'core_user_get_users failed') 379 # exception is catched if core_user_update_users fails 376 380 result6s = auth.check_credentials('SCHOOL1-fault3', 'biz') 377 assert result6s == (False, ' faultString')378 379 # no exception i f user exists381 assert result6s == (False, 'core_user_update_users failed') 382 383 # no exception is raised if user exists 380 384 result7s = auth.check_credentials('SCHOOL1-fault4', 'biz') 381 385 assert result7s == (True, '') … … 383 387 assert result7a == (True, '') 384 388 385 # If marker is an empty sringschool markers are neither386 # checked nor removed .389 # if marker is an empty string, school markers are neither 390 # checked nor removed 387 391 BACKENDS3['inst1']['marker'] = '' 388 392 auth = KofaMoodleAuthenticator(auth_backends=str(BACKENDS3))
Note: See TracChangeset for help on using the changeset viewer.