This repository was archived by the owner on May 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathtest_phones.py
More file actions
73 lines (54 loc) · 2.41 KB
/
Copy pathtest_phones.py
File metadata and controls
73 lines (54 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import six
import sys
import test_helper
import unittest
if six.PY3:
from unittest.mock import MagicMock
else:
from mock import MagicMock
from authy import AuthyException, AuthyFormatException
from authy.api import AuthyApiClient
from authy.api.resources import Phones
from authy.api.resources import Phone
class PhonesTest(unittest.TestCase):
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)
def test_phones(self):
self.assertIsInstance(self.phones, Phones)
def test_verification_start(self):
phone = self.phones.verification_start(
self.phone_number, self.country_code)
self.assertTrue(phone.ok())
self.assertEqual(phone.errors(), {})
def test_verification_start_with_code_length(self):
cl = self.phones.__validate_code_length(self.phones, code_length=7)
self.assertEqual(cl, 7)
def test_verification_start_with_str_code_length(self):
cl = self.phones.__validate_code_length(self.phones, code_length='7')
self.assertEqual(cl, 7)
def test_verification_start_with_non_numeric_code_length(self):
self.assertRaises(AuthyFormatException,
self.phones.__validate_code_length,
self.phones,
code_length='foo')
def test_verification_start_with_too_short_code_length(self):
self.assertRaises(AuthyFormatException,
self.phones.__validate_code_length,
self.phones,
code_length=2)
def test_verification_start_with_too_long_code_length(self):
self.assertRaises(AuthyFormatException,
self.phones.__validate_code_length,
self.phones,
code_length=12)
if __name__ == "__main__":
unittest.main()