diff options
author | Folker Bernitt <fbernitt@thoughtworks.com> | 2014-08-06 11:41:11 +0200 |
---|---|---|
committer | Folker Bernitt <fbernitt@thoughtworks.com> | 2014-08-06 11:41:11 +0200 |
commit | 1e1fd328bc43e820e178de7c08f626b1488505e1 (patch) | |
tree | d6525d978d88422b3ab53425c4e98b30fe732b3e /service/test/bitmask_libraries/leap_srp_test.py | |
parent | 26cbb616eb3ada3a0fb82e3156737b43cd2bc1ac (diff) |
Added register to leap_srp.
- Not yet called from anywhere
Diffstat (limited to 'service/test/bitmask_libraries/leap_srp_test.py')
-rw-r--r-- | service/test/bitmask_libraries/leap_srp_test.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/service/test/bitmask_libraries/leap_srp_test.py b/service/test/bitmask_libraries/leap_srp_test.py index e10be216..f02344f3 100644 --- a/service/test/bitmask_libraries/leap_srp_test.py +++ b/service/test/bitmask_libraries/leap_srp_test.py @@ -100,3 +100,44 @@ class LeapSRPTest(unittest.TestCase): with HTTMock(timeout_mock): lrsp = LeapSecureRemotePassword() self.assertRaises(LeapAuthException, lrsp.authenticate, 'https://api.leap.local', 'username', 'password') + + def test_register_raises_auth_exception_on_error(self): + with HTTMock(not_found_mock): + lsrp = LeapSecureRemotePassword() + self.assertRaises(LeapAuthException, lsrp.register, 'https://api.leap.local', 'username', 'password') + + def test_register(self): + @urlmatch(netloc=r'(.*\.)?leap\.local$', path='/1/users') + def register_success(url, request): + + content = { + 'login': 'username', + 'ok': True + } + + return {'status_code': 201, + 'content': content} + + with HTTMock(register_success, not_found_mock): + lsrp = LeapSecureRemotePassword() + self.assertTrue(lsrp.register('https://api.leap.local', 'username', 'password')) + + def test_register_user_exists(self): + @urlmatch(netloc=r'(.*\.)?leap\.local$', path='/1/users') + def register_error_user_exists(url, request): + content = {"errors": { + "login": [ + "has already been taken", "has already been taken", "has already been taken" + ]}} + + return {'status_code': 422, + 'content': content} + + with HTTMock(register_error_user_exists, not_found_mock): + lsrp = LeapSecureRemotePassword() + self.assertRaises(LeapAuthException, lsrp.register, 'https://api.leap.local', 'username', 'password') + + def test_registration_timeout(self): + with HTTMock(timeout_mock): + lsrp = LeapSecureRemotePassword() + self.assertRaises(LeapAuthException, lsrp.register, 'https://api.leap.local', 'username', 'password') |