コード例 #1
0
class PhonesTest(unittest.TestCase):

    def setUp(self):
        self.api = AuthyApiClient(test_helper.API_KEY, test_helper.API_URL)
        self.phones = Phones(test_helper.API_URL, test_helper.API_KEY)

    def test_phones(self):
        self.assertIsInstance(self.api.phones, Phones)

    def test_verification_start_without_via(self):
        phone = self.phones.verification_start('202-555-0189', '1')
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegexpMatches(phone['message'], 'Text message sent')

    def test_verification_start(self):
        phone = self.phones.verification_start('202-555-0189', '1', 'sms')
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegexpMatches(phone['message'], 'Text message sent')

    def test_verification_check_incorrect_code(self):
        phone = self.phones.verification_check('202-555-0189', '1', '1234')
        self.assertFalse(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegexpMatches(phone.errors()['message'], 'Verification code is incorrect.')

    def test_verification_check(self):
        phone = self.phones.verification_check('202-555-0189', '1', '0000')
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegexpMatches(phone['message'], 'Verification code is correct')

    def test_phone_info(self):
        phone = self.phones.info('7754615609', '1')
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegexpMatches(phone['message'], 'Phone number information as of')
        self.assertRegexpMatches(phone['type'], 'landline')
        self.assertFalse(phone['ported'])
コード例 #2
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
コード例 #3
0
class PhonesTest(unittest.TestCase):
    def setUp(self):
        self.api = AuthyApiClient("bf12974d70818a08199d17d5e2bae630",
                                  "http://sandbox-api.authy.com")
        self.phones = Phones("http://sandbox-api.authy.com",
                             'bf12974d70818a08199d17d5e2bae630')

    def test_phones(self):
        self.assertIsInstance(self.api.phones, Phones)

    def test_verification_start_without_via(self):
        phone = self.phones.verification_start('111-111-1111', '1')
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegexpMatches(phone['message'], 'Text message sent')

    def test_verification_start(self):
        phone = self.phones.verification_start('111-111-1111', '1', 'sms')
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegexpMatches(phone['message'], 'Text message sent')

    def test_verification_check_incorrect_code(self):
        phone = self.phones.verification_check('111-111-1111', '1', '1234')
        self.assertFalse(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegexpMatches(phone.errors()['message'],
                                 'Verification code is incorrect.')

    def test_verification_check(self):
        phone = self.phones.verification_check('111-111-1111', '1', '0000')
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegexpMatches(phone['message'],
                                 'Verification code is correct')

    def test_phone_info(self):
        phone = self.phones.info('7754615609', '1')
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegexpMatches(phone['message'],
                                 'Phone number information as of')
        self.assertRegexpMatches(phone['type'], 'voip')
        self.assertRegexpMatches(phone['provider'], 'Google Voice')
        self.assertFalse(phone['ported'])
コード例 #4
0
ファイル: test_phones.py プロジェクト: 17twenty/authy-python
class PhonesTest(unittest.TestCase):
    def setUp(self):
        self.api = AuthyApiClient(test_helper.API_KEY, test_helper.API_URL)
        self.phones = Phones(test_helper.API_URL, test_helper.API_KEY)

    def test_phones(self):
        self.assertIsInstance(self.api.phones, Phones)

    def test_verification_start_without_via(self):
        phone = self.phones.verification_start('111-111-1111', '1')
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegexpMatches(phone['message'], 'Text message sent')

    def test_verification_start(self):
        phone = self.phones.verification_start('111-111-1111', '1', 'sms')
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegexpMatches(phone['message'], 'Text message sent')

    def test_verification_check_incorrect_code(self):
        phone = self.phones.verification_check('111-111-1111', '1', '1234')
        self.assertFalse(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegexpMatches(phone.errors()['message'],
                                 'Verification code is incorrect.')

    def test_verification_check(self):
        phone = self.phones.verification_check('111-111-1111', '1', '0000')
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegexpMatches(phone['message'],
                                 'Verification code is correct')

    def test_phone_info(self):
        phone = self.phones.info('7754615609', '1')
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegexpMatches(phone['message'],
                                 'Phone number information as of')
        self.assertRegexpMatches(phone['type'], 'voip')
        self.assertRegexpMatches(phone['provider'], 'Google Voice')
        self.assertFalse(phone['ported'])
コード例 #5
0
ファイル: test_phones.py プロジェクト: FloorLamp/authy-python
class PhonesTest(unittest.TestCase):

    def setUp(self):
        self.api = AuthyApiClient("bf12974d70818a08199d17d5e2bae630", "http://sandbox-api.authy.com")
        self.phones = Phones("http://sandbox-api.authy.com", 'bf12974d70818a08199d17d5e2bae630')

    def test_phones(self):
        self.assertIsInstance(self.api.phones, Phones)

    def test_verification_start_without_via(self):
        phone = self.phones.verification_start('111-111-1111', '1')
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegexpMatches(phone['message'], 'Text message sent')

    def test_verification_start(self):
        phone = self.phones.verification_start('111-111-1111', '1', 'sms')
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegexpMatches(phone['message'], 'Text message sent')

    def test_verification_check_incorrect_code(self):
        phone = self.phones.verification_check('111-111-1111', '1', '1234')
        self.assertFalse(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegexpMatches(phone.errors()['message'], 'Verification code is incorrect.')

    def test_verification_check(self):
        phone = self.phones.verification_check('111-111-1111', '1', '0000')
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegexpMatches(phone['message'], 'Verification code is correct')

    def test_phone_info(self):
        phone = self.phones.info('7754615609', '1')
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegexpMatches(phone['message'], 'Phone number information as of')
        self.assertRegexpMatches(phone['type'], 'voip')
        self.assertRegexpMatches(phone['provider'], 'Google Voice')
        self.assertFalse(phone['ported'])
コード例 #6
0
    def setUp(self):
        
        self.phones = MagicMock(Phones(test_helper.API_URL, test_helper.API_KEY))
        self.response = MagicMock()

        phone = MagicMock(Phone(self.phones, self.response))
        phone.ok = MagicMock(return_value=True)
        phone.errors = MagicMock(return_value={})

        self.phone_number = test_helper.PHONE_NUMBER
        self.country_code = test_helper.COUNTRY_CODE

        self.phones.__validate_channel = Phones._Phones__validate_channel
        self.phones.__validate_code_length = Phones._Phones__validate_code_length
        self.phones.verification_start = MagicMock(return_value = phone)
コード例 #7
0
ファイル: test_phones.py プロジェクト: Belle-1/RPOSS
class PhonesTest(unittest.TestCase):
    def setUp(self):
        self.api = AuthyApiClient(test_helper.API_KEY, test_helper.API_URL)
        self.phones = Phones(test_helper.API_URL, test_helper.API_KEY)
        self.phone_number = test_helper.PHONE_NUMBER
        self.country_code = test_helper.COUNTRY_CODE

    def test_phones(self):
        self.assertIsInstance(self.api.phones, Phones)

    def test_verification_start_without_via(self):
        phone = self.phones.verification_start(self.phone_number,
                                               self.country_code, 'sms')
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegexpMatches(phone['message'], 'Text message sent')

    def test_verification_start(self):
        phone = self.phones.verification_start(self.phone_number,
                                               self.country_code)
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegexpMatches(phone['message'], 'Text message sent')

    def test_verification_check_incorrect_code(self):
        phone = self.phones.verification_check(self.phone_number,
                                               self.country_code, '1234')
        self.assertFalse(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegexpMatches(phone.errors()['message'],
                                 'Verification code is incorrect.')

    def test_verification_check(self):
        self.phones.verification_start(self.phone_number, self.country_code)
        phone = self.phones.verification_check(self.phone_number,
                                               self.country_code, '0000')
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegexpMatches(phone['message'],
                                 'Verification code is correct')

    def test_phone_info(self):
        phone = self.phones.info(self.phone_number, self.country_code)
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegexpMatches(phone['message'],
                                 'Phone number information as of')
        self.assertRegexpMatches(phone['type'], 'landline')
        self.assertFalse(phone['ported'])
コード例 #8
0
 def setUp(self):
     self.api = AuthyApiClient(test_helper.API_KEY, test_helper.API_URL)
     self.phones = Phones(test_helper.API_URL, test_helper.API_KEY)
コード例 #9
0
 def setUp(self):
     self.api = AuthyApiClient(test_helper.API_KEY, test_helper.API_URL)
     self.phones = Phones(test_helper.API_URL, test_helper.API_KEY)
コード例 #10
0
ファイル: test_phones.py プロジェクト: Belle-1/RPOSS
 def setUp(self):
     self.api = AuthyApiClient(test_helper.API_KEY, test_helper.API_URL)
     self.phones = Phones(test_helper.API_URL, test_helper.API_KEY)
     self.phone_number = test_helper.PHONE_NUMBER
     self.country_code = test_helper.COUNTRY_CODE
コード例 #11
0
ファイル: test_phones.py プロジェクト: FloorLamp/authy-python
 def setUp(self):
     self.api = AuthyApiClient("bf12974d70818a08199d17d5e2bae630", "http://sandbox-api.authy.com")
     self.phones = Phones("http://sandbox-api.authy.com", 'bf12974d70818a08199d17d5e2bae630')
コード例 #12
0
class PhonesTest(unittest.TestCase):
    def setUp(self):
        self.api = AuthyApiClient(test_helper.API_KEY, test_helper.API_URL)
        self.phones = Phones(test_helper.API_URL, test_helper.API_KEY)
        self.phone_number = test_helper.PHONE_NUMBER
        self.country_code = test_helper.COUNTRY_CODE

    def test_phones(self):
        self.assertIsInstance(self.api.phones, Phones)

    def test_verification_start_without_via(self):
        phone = self.phones.verification_start(self.phone_number,
                                               self.country_code, 'sms')
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertEquals(phone['message'],
                          'Text message sent to +1 305-456-2345.')

    def test_verification_start(self):
        phone = self.phones.verification_start(self.phone_number,
                                               self.country_code)
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertEquals(phone['message'],
                          'Text message sent to +1 305-456-2345.')

    def test_verification_start_with_code_length(self):
        phone = self.phones.verification_start(self.phone_number,
                                               self.country_code,
                                               code_length=7)
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegexpMatches(phone['message'], 'Text message sent')

    def test_verification_start_with_str_code_length(self):
        phone = self.phones.verification_start(self.phone_number,
                                               self.country_code,
                                               code_length='7')
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegexpMatches(phone['message'], 'Text message sent')

    def test_verification_start_with_non_numeric_code_length(self):
        self.assertRaises(AuthyFormatException,
                          self.phones.verification_start,
                          self.phone_number,
                          self.country_code,
                          code_length='foo')

    def test_verification_start_with_too_short_code_length(self):
        self.assertRaises(AuthyFormatException,
                          self.phones.verification_start,
                          self.phone_number,
                          self.country_code,
                          code_length=2)

    def test_verification_start_with_too_long_code_length(self):
        self.assertRaises(AuthyFormatException,
                          self.phones.verification_start,
                          self.phone_number,
                          self.country_code,
                          code_length=12)

    def test_verification_check_incorrect_code(self):
        when(self.phones).verification_check(
            self.phone_number, self.country_code,
            '1234').thenReturn('Verification code is incorrect.')

        response = self.phones.verification_check(self.phone_number,
                                                  self.country_code, '1234')
        self.assertEqual(response, 'Verification code is incorrect.')

    def test_verification_check(self):
        when(self.phones).verification_check(
            self.phone_number, self.country_code,
            '0000').thenReturn('Verification code is correct.')

        response = self.phones.verification_check(self.phone_number,
                                                  self.country_code, '0000')
        self.assertEqual(response, 'Verification code is correct.')

    def test_phone_info(self):
        phone = self.phones.info(self.phone_number, self.country_code)
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertTrue('Phone number information as of' in phone['message'])
        self.assertEquals(phone['type'], 'landline')
        self.assertFalse(phone['ported'])
コード例 #13
0
 def setUp(self):
     self.api = AuthyApiClient("bf12974d70818a08199d17d5e2bae630",
                               "http://sandbox-api.authy.com")
     self.phones = Phones("http://sandbox-api.authy.com",
                          'bf12974d70818a08199d17d5e2bae630')
コード例 #14
0
ファイル: test_phones.py プロジェクト: authy/authy-python
 def setUp(self):
     self.api = AuthyApiClient(test_helper.API_KEY, test_helper.API_URL)
     self.phones = Phones(test_helper.API_URL, test_helper.API_KEY)
     self.phone_number = test_helper.PHONE_NUMBER
     self.country_code = test_helper.COUNTRY_CODE
コード例 #15
0
ファイル: test_phones.py プロジェクト: authy/authy-python
class PhonesTest(unittest.TestCase):

    def setUp(self):
        self.api = AuthyApiClient(test_helper.API_KEY, test_helper.API_URL)
        self.phones = Phones(test_helper.API_URL, test_helper.API_KEY)
        self.phone_number = test_helper.PHONE_NUMBER
        self.country_code = test_helper.COUNTRY_CODE

    def test_phones(self):
        self.assertIsInstance(self.api.phones, Phones)

    def test_verification_start_without_via(self):
        phone = self.phones.verification_start(
            self.phone_number, self.country_code, 'sms')
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertEquals(phone['message'],
                          'Text message sent to +1 305-456-2345.')

    def test_verification_start(self):
        phone = self.phones.verification_start(
            self.phone_number, self.country_code)
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertEquals(phone['message'],
                          'Text message sent to +1 305-456-2345.')

    def test_verification_start_with_code_length(self):
        phone = self.phones.verification_start(self.phone_number, self.country_code,
                                               code_length=7)
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegexpMatches(phone['message'], 'Text message sent')

    def test_verification_start_with_str_code_length(self):
        phone = self.phones.verification_start(self.phone_number, self.country_code,
                                               code_length='7')
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegexpMatches(phone['message'], 'Text message sent')

    def test_verification_start_with_non_numeric_code_length(self):
        self.assertRaises(AuthyFormatException,
                          self.phones.verification_start,
                          self.phone_number,
                          self.country_code,
                          code_length='foo')

    def test_verification_start_with_too_short_code_length(self):
        self.assertRaises(AuthyFormatException,
                          self.phones.verification_start,
                          self.phone_number,
                          self.country_code,
                          code_length=2)

    def test_verification_start_with_too_long_code_length(self):
        self.assertRaises(AuthyFormatException,
                          self.phones.verification_start,
                          self.phone_number,
                          self.country_code,
                          code_length=12)

    def test_verification_check_incorrect_code(self):
        when(self.phones).verification_check(self.phone_number, self.country_code, '1234').thenReturn(
            'Verification code is incorrect.')

        response = self.phones.verification_check(
            self.phone_number, self.country_code, '1234')
        self.assertEqual(response, 'Verification code is incorrect.')

    def test_verification_check(self):
        when(self.phones).verification_check(self.phone_number, self.country_code, '0000').thenReturn(
            'Verification code is correct.')

        response = self.phones.verification_check(
            self.phone_number, self.country_code, '0000')
        self.assertEqual(response, 'Verification code is correct.')

    def test_phone_info(self):
        phone = self.phones.info(self.phone_number, self.country_code)
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertTrue('Phone number information as of' in phone['message'])
        self.assertEquals(phone['type'], 'landline')
        self.assertFalse(phone['ported'])