-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtests.py
46 lines (37 loc) · 1.67 KB
/
tests.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
import unittest
import os
import sys
from tourcms import Connection
if os.getenv('TOURCMS_PRIVATE_KEY', None) is None:
sys.stderr.write("You must set the 'TOURCMS_PRIVATE_KEY' environment variable to run tests\n")
sys.exit(1)
if os.getenv('TOURCMS_CHANNEL_KEY', None) is None:
sys.stderr.write("You need to set 'TOURCMS_CHANNEL_KEY' to run tests\n")
sys.exit(1)
class TestConnection(unittest.TestCase):
def setUp(self):
self.conn = Connection(0, os.getenv(u'TOURCMS_PRIVATE_KEY'))
def test_generate_signature(self):
verb = 'GET'
channel = 1234
outbound_time = 325234534
test_strings = {
('/index.xml', verb, channel, outbound_time): 'Y9Q4RxaAzC6pRHJq9etfj3219Y440V3kU9tIAnymsQY%3D',
('/foo.xml', verb, channel, outbound_time): 'c5FX7dLAMLZCj2NvuU4Q166T77jbYuBkh9%2Fta%2Bm%2FaIY%3D',
('/bar.xml', 'POST', channel, outbound_time): 'xMXPzacqAdYyY%2BDBxVA8c9Gd%2Bkpb18bjmBcmMkfwWDs%3D',
('/foo-bar/index.xml', verb, channel, outbound_time): 'pVP5MLjLcPltHPpt7klBon8ggb5Iwj7gRbUQor1Odj0%3D',
}
for args, output in test_strings.items():
signed_str = self.conn._generate_signature(*args)
self.assertEqual(
signed_str, output,
"Failed for '{0}'. '{1}' != '{2}'".format(args[0], signed_str, output)
)
def test_i_can_authenticate(self):
try:
resp = self.conn.api_rate_limit_status(os.getenv(u'TOURCMS_CHANNEL_KEY'))
except Exception:
#e = sys.exc_info()[1].args[0]
self.fail("Unable to check api rate limit.")
if __name__ == '__main__':
unittest.main()