-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_api.py
89 lines (67 loc) · 2.24 KB
/
test_api.py
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import os
import time
import unittest
from phaxio import PhaxioApi
try:
raw_input
except NameError:
raw_input = input
class APITestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
super(APITestCase, cls).setUpClass()
key = raw_input('Enter test API key: ')
secret = raw_input('Enter secret: ')
cls.api = PhaxioApi(key, secret, raise_errors=True)
def setUp(self):
super(APITestCase, self).setUp()
# Due to Phaxio's API rate limiting,
# we will wait 1 second between each test
time.sleep(1)
def test_sending_long_fax(self):
r = self.api.send(
to='4147654321',
string_data='Hello World! ' * 8000,
string_data_type='text'
)
self.assertTrue(r['success'])
def test_sending_multiple_recipients(self):
r = self.api.send(
to=['4147654321', '5147654321', '6157654321'],
string_data='Hello World!',
string_data_type='text'
)
self.assertTrue(r['success'])
def test_sending_files(self):
llama = os.path.join(os.path.dirname(__file__), 'llama.pdf')
alpaca = os.path.join(os.path.dirname(__file__), 'alpaca.pdf')
f = open(alpaca, 'rb')
r = self.api.send(to='4147654321', files=(llama, f))
self.assertTrue(r['success'])
def test_receive(self):
llama = os.path.join(os.path.dirname(__file__), 'llama.pdf')
r = self.api.testReceive(files=llama)
self.assertTrue(r['success'])
def test_fax_status(self):
r = self.api.send(
to='4147654321',
string_data='Hello World!',
string_data_type='text'
)
fax_id = r.get('faxId')
time.sleep(1) # due to rate limiting
r = self.api.faxStatus(id=fax_id)
self.assertTrue(r['success'])
def test_fax_file(self):
r = self.api.send(
to='4147654321',
string_data='Hello World!',
string_data_type='text'
)
fax_id = r.get('faxId')
# have to wait for Phaxio to process file
time.sleep(3)
r = self.api.faxFile(id=fax_id)
self.assertIsNotNone(r)
if __name__ == '__main__':
unittest.main()