Ejemplo n.º 1
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())
Ejemplo n.º 2
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(), {})
Ejemplo n.º 3
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.')
Ejemplo n.º 4
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.')
Ejemplo n.º 5
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.')
Ejemplo n.º 6
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.')
Ejemplo n.º 7
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(), {})
Ejemplo n.º 8
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())
Ejemplo n.º 9
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())
Ejemplo n.º 10
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(), {})
Ejemplo n.º 11
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(), {})
Ejemplo n.º 12
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(), {})