class UsersTest(unittest.TestCase): def setUp(self): self.resource = Users("http://sandbox-api.authy.com", 'bf12974d70818a08199d17d5e2bae630') def test_create_valid_user(self): user = self.resource.create('*****@*****.**', '3457824988', 1) self.assertIsInstance(user, User) self.assertTrue(user.ok()) self.assertTrue('user' in user.content) self.assertIsNotNone(user.id) self.assertEqual(user.errors(), {}) def test_create_invalid_user(self): user = self.resource.create('testexample.com', '782392032', 1) self.assertFalse(user.ok()) self.assertIsInstance(user, User) self.assertEqual(user.errors()['email'], 'is invalid') self.assertIsNone(user.id) def test_request_sms_token(self): user = self.resource.create('*****@*****.**', '3107810860', 1) sms = self.resource.request_sms(user.id) self.assertTrue(sms.ok()) self.assertTrue(sms.content['success']) self.assertEqual(sms.errors(), {}) self.assertEqual(user.errors(), {})
class TokensTest(unittest.TestCase): def setUp(self): self.users = Users("http://sandbox-api.authy.com", 'bf12974d70818a08199d17d5e2bae630') self.resource = Tokens("http://sandbox-api.authy.com", 'bf12974d70818a08199d17d5e2bae630') def test_verify_invalid_token(self): user = self.users.create('*****@*****.**', '310-781-0860', 1) token = self.resource.verify(user.id, 'token') self.assertIsInstance(token, Token) self.assertFalse(token.ok()) self.assertEqual(token.response.status_code, 401) self.assertEqual(token.errors()['message'], 'Token is invalid.') def test_verify_valid_token(self): user = self.users.create('*****@*****.**', '345-782-4988', 1) token = self.resource.verify(user.id, '0000000') self.assertIsInstance(token, Token) self.assertTrue(token.ok()) def test_force_verify_token(self): user = self.users.create('*****@*****.**', '345-782-4988', 1) token = self.resource.verify(user.id, '0000000', {"force": True}) self.assertIsInstance(token, Token) self.assertTrue(token.ok())
class UsersTest(unittest.TestCase): def setUp(self): self.api = AuthyApiClient(test_helper.API_KEY, test_helper.API_URL) self.users = Users(test_helper.API_URL, test_helper.API_KEY) def test_users(self): self.assertIsInstance(self.api.users, Users) def test_create_valid_user(self): user = self.users.create('*****@*****.**', '3457824988', 1) self.assertEqual(user.errors(), {}) self.assertIsInstance(user, User) self.assertTrue(user.ok()) self.assertTrue('user' in user.content) self.assertIsNotNone(user.id) def test_create_invalid_user(self): user = self.users.create('testexample.com', '782392032', 1) self.assertFalse(user.ok()) self.assertIsInstance(user, User) self.assertEqual(user.errors()['email'], 'is invalid') self.assertIsNone(user.id) def test_request_sms_token(self): user = self.users.create('*****@*****.**', '202-555-0158', 1) sms = self.users.request_sms(user.id) self.assertTrue(sms.ok()) self.assertTrue(sms.content['success']) self.assertEqual(sms.errors(), {}) self.assertEqual(user.errors(), {}) def test_sms_ignored(self): user = self.users.create('*****@*****.**', '202-555-0197', 1) sms = self.users.request_sms(user.id) self.assertTrue(sms.ok()) # fake 'ignored' field in JSON response sms.content['ignored'] = 'true' self.assertTrue(sms.ignored()) def test_get_user_status(self): user = self.users.create('*****@*****.**', '3107810860', 1) status = self.users.status(user.id) self.assertTrue(status.ok(), msg="errors: {0}".format(status.errors())) self.assertTrue(status.content['success']) self.assertEqual(status.errors(), {}) def test_delete_user(self): user = self.users.create('*****@*****.**', '3107810860', 1) user = self.users.delete(user.id) self.assertTrue(user.ok()) self.assertTrue(user.content['success']) self.assertEqual(user.errors(), {})
class UsersTest(unittest.TestCase): def setUp(self): self.resource = Users("http://sandbox-api.authy.com", 'bf12974d70818a08199d17d5e2bae630') def test_create_valid_user(self): user = self.resource.create('*****@*****.**', '3457824988', 1) self.assertIsInstance(user, User) self.assertTrue(user.ok()) self.assertTrue('user' in user.content) self.assertIsNotNone(user.id) self.assertEqual(user.errors(), {}) def test_create_invalid_user(self): user = self.resource.create('testexample.com', '782392032', 1) self.assertFalse(user.ok()) self.assertIsInstance(user, User) self.assertEqual(user.errors()['email'], 'is invalid') self.assertIsNone(user.id) def test_request_sms_token(self): user = self.resource.create('*****@*****.**', '3107810860', 1) sms = self.resource.request_sms(user.id) self.assertTrue(sms.ok()) self.assertTrue(sms.content['success']) self.assertEqual(sms.errors(), {}) self.assertEqual(user.errors(), {}) def test_sms_ignored(self): user = self.resource.create('*****@*****.**', '3107810860', 1) sms = self.resource.request_sms(user.id) self.assertTrue(sms.ok()) # fake 'ignored' field in JSON response sms.content['ignored'] = 'true' self.assertTrue(sms.ignored()) def test_get_user_status(self): user = self.resource.create('*****@*****.**', '3107810860', 1) status = self.resource.status(user.id) self.assertTrue(status.ok(), msg="errors: {0}".format(status.errors())) self.assertTrue(status.content['success']) self.assertEqual(status.errors(), {}) def test_delete_user(self): user = self.resource.create('*****@*****.**', '3107810860', 1) user = self.resource.delete(user.id) self.assertTrue(user.ok()) self.assertTrue(user.content['success']) self.assertEqual(user.errors(), {})
class UsersTest(unittest.TestCase): def setUp(self): self.resource = Users(test_helper.API_URL, test_helper.API_KEY) def test_create_valid_user(self): user = self.resource.create("*****@*****.**", "3457824988", 1) self.assertIsInstance(user, User) self.assertTrue(user.ok()) self.assertTrue("user" in user.content) self.assertIsNotNone(user.id) self.assertEqual(user.errors(), {}) def test_create_invalid_user(self): user = self.resource.create("testexample.com", "782392032", 1) self.assertFalse(user.ok()) self.assertIsInstance(user, User) self.assertEqual(user.errors()["email"], "is invalid") self.assertIsNone(user.id) def test_request_sms_token(self): user = self.resource.create("*****@*****.**", "202-555-0158", 1) sms = self.resource.request_sms(user.id) self.assertTrue(sms.ok()) self.assertTrue(sms.content["success"]) self.assertEqual(sms.errors(), {}) self.assertEqual(user.errors(), {}) def test_sms_ignored(self): user = self.resource.create("*****@*****.**", "202-555-0197", 1) sms = self.resource.request_sms(user.id) self.assertTrue(sms.ok()) # fake 'ignored' field in JSON response sms.content["ignored"] = "true" self.assertTrue(sms.ignored()) def test_get_user_status(self): user = self.resource.create("*****@*****.**", "3107810860", 1) status = self.resource.status(user.id) self.assertTrue(status.ok(), msg="errors: {0}".format(status.errors())) self.assertTrue(status.content["success"]) self.assertEqual(status.errors(), {}) def test_delete_user(self): user = self.resource.create("*****@*****.**", "3107810860", 1) user = self.resource.delete(user.id) self.assertTrue(user.ok()) self.assertTrue(user.content["success"]) self.assertEqual(user.errors(), {})
def __init__(self, api_key, api_uri="https://api.authy.com"): """ Create a Authy REST API client. """ self.api_uri = api_uri self.users = Users(api_uri, api_key) self.tokens = Tokens(api_uri, api_key) self.apps = Apps(api_uri, api_key) self.stats = StatsResource(api_uri, api_key) self.phones = Phones(api_uri, api_key) self.api_key = api_key
class TokensTest(unittest.TestCase): def setUp(self): self.users = Users(test_helper.API_URL, test_helper.API_KEY) self.resource = Tokens(test_helper.API_URL, test_helper.API_KEY) def test_verify_digits_token(self): user = self.users.create('*****@*****.**', '310-781-0860', 1) try: token = self.resource.verify(user.id, 'token') self.fail() except Exception, e: self.assertIsInstance(e, AuthyFormatException) self.assertEqual(e.message, 'Invalid Token. Only digits accepted.')
class TokensTest(unittest.TestCase): def setUp(self): self.users = Users("http://sandbox-api.authy.com", 'bf12974d70818a08199d17d5e2bae630') self.resource = Tokens("http://sandbox-api.authy.com", 'bf12974d70818a08199d17d5e2bae630') def test_verify_digits_token(self): user = self.users.create('*****@*****.**', '310-781-0860', 1) try: token = self.resource.verify(user.id, 'token') self.fail() except Exception, e: self.assertIsInstance(e, AuthyFormatException) self.assertEqual(e.message, 'Invalid Token. Only digits accepted.')
class TokensTest(unittest.TestCase): def setUp(self): self.users = Users("http://sandbox-api.authy.com", 'bf12974d70818a08199d17d5e2bae630') self.resource = Tokens("http://sandbox-api.authy.com", 'bf12974d70818a08199d17d5e2bae630') def test_verify_digits_token(self): user = self.users.create('*****@*****.**', '310-781-0860', 1) try: token = self.resource.verify(user.id, 'token') self.fail() except Exception as e: self.assertIsInstance(e, AuthyFormatException) self.assertEqual(str(e), 'Invalid Token. Only digits accepted.') def test_verify_digits_authy_id(self): user = self.users.create('*****@*****.**', '310-781-0860', 1) try: token = self.resource.verify('user.id', '0000000') self.fail() except Exception as e: self.assertIsInstance(e, AuthyFormatException) self.assertEqual(str(e), 'Invalid Authy id. Only digits accepted.') def test_verify_longer_token(self): user = self.users.create('*****@*****.**', '310-781-0860', 1) try: token = self.resource.verify(user.id, '00000001111') self.fail() except Exception as e: self.assertIsInstance(e, AuthyFormatException) self.assertEqual(str(e), 'Invalid Token. Unexpected length.') def test_verify_invalid_token(self): user = self.users.create('*****@*****.**', '310-781-0860', 1) token = self.resource.verify(user.id, '1111111') self.assertIsInstance(token, Token) self.assertFalse(token.ok()) self.assertEqual(token.response.status_code, 401) self.assertEqual(token.errors()['message'], 'Token is invalid.') def test_verify_valid_token(self): user = self.users.create('*****@*****.**', '345-782-4988', 1) token = self.resource.verify(user.id, '0000000') self.assertIsInstance(token, Token) self.assertTrue(token.ok()) def test_force_verify_token(self): user = self.users.create('*****@*****.**', '345-782-4988', 1) token = self.resource.verify(user.id, '0000000', {"force": True}) self.assertIsInstance(token, Token) self.assertTrue(token.ok())
def setUp(self): self.users = MagicMock(Users(test_helper.API_URL, test_helper.API_KEY)) self.response = MagicMock() user = MagicMock(User(self.users, self.response)) user.content = { "user": { "id": test_helper.API_USER_ID }, "success": True, "message": "something" } user.errors = MagicMock(return_value={}) user.ok = MagicMock(return_value=True) user.id = MagicMock(return_value=test_helper.API_USER_ID) sms = MagicMock(Sms(self.users, self.response)) sms.errors = MagicMock(return_value={}) self.users.create = MagicMock(return_value=user) self.users.delete = MagicMock(return_value=user) self.users.status = MagicMock(return_value=user) self.users.request_sms = MagicMock(return_value=sms)
def setUp(self): self.resource = Users(test_helper.API_URL, test_helper.API_KEY)
def setUp(self): self.users = Users(test_helper.API_URL, test_helper.API_KEY) self.resource = Tokens(test_helper.API_URL, test_helper.API_KEY)
def setUp(self): self.resource = Users("http://sandbox-api.authy.com", 'bf12974d70818a08199d17d5e2bae630')
def setUp(self): self.api = AuthyApiClient(test_helper.API_KEY, test_helper.API_URL) self.users = Users(test_helper.API_URL, test_helper.API_KEY)