Changeset 10512
- Timestamp:
- 20 Aug 2013, 12:25:19 (11 years ago)
- Location:
- main/waeup.cas/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.cas/trunk/README.rst
r10421 r10512 37 37 You can generate coverage reports by:: 38 38 39 (py27)$ py.test --cov 39 (py27)$ py.test --cov . 40 40 41 41 This will dump reports on commandline. For HTML reports you can try:: 42 42 43 (py27)$ py.test --cov --cov-report=html43 (py27)$ py.test --cov . --cov-report=html 44 44 45 45 Please make sure, that coverage stays at 100%. -
main/waeup.cas/trunk/waeup/cas/tests/test_authenticators.py
r10511 r10512 88 88 url='http://localhost:6666/', 89 89 marker='^SCHOOL1-', 90 moodle_url = 'http://localhost /moodle',90 moodle_url = 'http://localhost:7777/', 91 91 ) 92 92 ) … … 166 166 self.register_function( 167 167 self._check_credentials, 'check_student_credentials') 168 self.register_function( 169 self._get_moodle_data, 'get_moodle_data') 168 170 169 171 def _check_credentials(self, username, password): … … 183 185 return None 184 186 185 186 class KofaAuthenticatorIntegrationTests(unittest.TestCase): 187 def _get_moodle_data(self, username): 188 # fake waeup.kofa get_moodle_data method. 189 if username == 'bird': 190 return dict(email='aa@aa.aa', 191 firstname='Charles', 192 lastname='Parker', 193 ) 194 if username == 'pig': 195 return dict(email='bb@bb.bb', 196 firstname='Ray', 197 lastname='Charles', 198 ) 199 return None 200 201 class FakeMoodleServer(SimpleXMLRPCServer): 202 # A fake Moodle server that provides only XMLRPC methods 203 204 allow_reuse_address = True 205 206 def __init__(self, *args, **kw): 207 kw.update(allow_none=True) 208 SimpleXMLRPCServer.__init__(self, *args, **kw) 209 self.register_function( 210 self._core_user_create_users, 'core_user_create_users') 211 self.register_function( 212 self._core_user_get_users, 'core_user_get_users') 213 self.register_function( 214 self._core_user_update_users, 'core_user_update_users') 215 216 def _core_user_create_users(self, list_of_dicts): 217 # fake Moodle core_user_create_users method. 218 return None 219 220 def _core_user_get_users(self, list_of_dicts): 221 # fake Moodle core_user_get_users method. 222 return {'users':[{'id':'any id'}]} 223 224 def _core_user_update_users(self, list_of_dicts): 225 # fake Moodle core_user_update_users method. 226 return None 227 228 class KofaAuthenticatorsIntegrationTests(unittest.TestCase): 187 229 # A test case where a fake Kofa server is started before tests (and 188 230 # shut down afterwards). 189 231 190 server = None 191 th = None 232 kofa_server = None 233 kofa_th = None 234 moodle_server = None 235 moodle_th = None 192 236 193 237 @classmethod 194 238 def setUpClass(cls): 195 239 # set up a fake kofa server 196 cls.server = FakeKofaServer(('localhost', 6666)) 197 cls.th = threading.Thread(target=cls.server.serve_forever) 198 cls.th.daemon = True 199 cls.th.start() 240 cls.kofa_server = FakeKofaServer(('localhost', 6666)) 241 cls.kofa_th = threading.Thread(target=cls.kofa_server.serve_forever) 242 cls.kofa_th.daemon = True 243 cls.kofa_th.start() 244 # set up a fake moodle server 245 cls.moodle_server = FakeMoodleServer(('localhost', 7777)) 246 cls.moodle_th = threading.Thread(target=cls.moodle_server.serve_forever) 247 cls.moodle_th.daemon = True 248 cls.moodle_th.start() 200 249 201 250 @classmethod 202 251 def tearDownClass(cls): 203 252 # tear down fake kofa server 204 cls.server.shutdown() 205 cls.server.server_close() 253 cls.kofa_server.shutdown() 254 cls.kofa_server.server_close() 255 # tear down fake moodle server 256 cls.moodle_server.shutdown() 257 cls.moodle_server.server_close() 206 258 207 259 def test_fake_kofa_works(self): … … 220 272 'id': 'pig', 221 273 'type': 'applicant'} 274 result = proxy.get_moodle_data('pig') 275 assert result == { 276 'lastname': 'Charles', 277 'email': 'bb@bb.bb', 278 'firstname': 'Ray', 279 } 222 280 return 223 281 224 def test_check_credentials(self): 282 def test_moodle_works(self): 283 # make sure the local fake moodle works 284 proxy = xmlrpclib.ServerProxy("http://localhost:7777", allow_none=True) 285 result = proxy.core_user_create_users([]) 286 assert result == None 287 result = proxy.core_user_get_users([]) 288 assert result == {'users':[{'id':'any id'}]} 289 result = proxy.core_user_update_users([]) 290 assert result == None 291 return 292 293 def test_check_credentials_1(self): 225 294 # we get real responses when querying Kofa instances 226 295 auth = KofaAuthenticator(auth_backends=str(BACKENDS2)) … … 232 301 assert result3 == (False, 'Invalid username or password.') 233 302 303 def test_check_credentials_2(self): 304 # we get real responses when querying Kofa instances 305 auth = KofaMoodleAuthenticator(auth_backends=str(BACKENDS3)) 306 result1 = auth.check_credentials('SCHOOL1-bird', 'bebop') 307 assert result1 == (True, '') 308 result2 = auth.check_credentials('SCHOOL1-foo', 'bar') 309 assert result2 == (False, 'Invalid username or password.') 310 result3 = auth.check_credentials('SCHOOL2-bar', 'baz') 311 assert result3 == (False, 'Invalid username or password.')
Note: See TracChangeset for help on using the changeset viewer.