예제 #1
0
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(), {})
예제 #2
0
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())
예제 #3
0
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(), {})
예제 #4
0
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(), {})
예제 #5
0
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(), {})
예제 #6
0
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(), {})
예제 #7
0
 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
예제 #8
0
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.')
예제 #9
0
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.')
예제 #10
0
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.')
예제 #11
0
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.')
예제 #12
0
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())
예제 #13
0
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())
예제 #14
0
    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)
예제 #15
0
 def setUp(self):
     self.resource = Users(test_helper.API_URL, test_helper.API_KEY)
예제 #16
0
 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)
예제 #17
0
 def setUp(self):
     self.resource = Users("http://sandbox-api.authy.com", 'bf12974d70818a08199d17d5e2bae630')
예제 #18
0
 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)
예제 #19
0
 def setUp(self):
     self.resource = Users("http://sandbox-api.authy.com",
                           'bf12974d70818a08199d17d5e2bae630')
예제 #20
0
 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)
예제 #21
0
 def setUp(self):
     self.resource = Users(test_helper.API_URL, test_helper.API_KEY)