This repository has been archived by the owner on Jul 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathroute53_ddns_test.py
82 lines (63 loc) · 2.17 KB
/
route53_ddns_test.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
import logging
import unittest
import route53_ddns
class TestRoute53DDNS(unittest.TestCase):
def test_get_source_ip(self):
event = {
'requestContext': {
'identity': {
'sourceIp': "173.73.171.92",
},
},
}
result = route53_ddns.get_source_ip(event)
self.assertEqual(result, "173.73.171.92")
def test_get_source_ip_noip(self):
event = {}
with self.assertRaises(route53_ddns.Error):
route53_ddns.get_source_ip(event)
def test_get_domain_candidates(self):
c = route53_ddns.get_domain_candidates('hostname.domain.com.')
self.assertEqual(
c,
['hostname.domain.com.', 'domain.com.', 'com.']
)
def test_parse_hostname_param(self):
cases = [
('test.hostname.com', ['test.hostname.com.']),
('test.hostname.com.', ['test.hostname.com.']),
('test.com.,test2.com',
['test.com.', 'test2.com.'])
]
for case in cases:
r = route53_ddns.parse_hostname_param(case[0])
self.assertEqual(case[1], r)
def test_handler_no_querystringparameters(self):
event = {}
response = route53_ddns.handler(event, {})
self.assertEqual(response['statusCode'], 400)
def test_handler_null_querystringparameters(self):
event = {
'queryStringParameters': None,
}
response = route53_ddns.handler(event, {})
self.assertEqual(response['statusCode'], 400)
def test_handler_no_hostname(self):
event = {
'queryStringParameters': {
},
}
response = route53_ddns.handler(event, {})
self.assertEqual(response['statusCode'], 400)
def test_handler_unknown_parameter(self):
event = {
'queryStringParameters': {
'hostname': 'test.internal',
'unknown': 123,
},
}
response = route53_ddns.handler(event, {})
self.assertEqual(response['statusCode'], 400)
if __name__ == '__main__':
logging.basicConfig()
unittest.main()