-
Notifications
You must be signed in to change notification settings - Fork 17
/
tests.py
51 lines (42 loc) · 1.41 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
47
48
49
50
51
import unittest
import urllib2
import zipapiserver
from zipapiserver import PORT_NUMBER
class TestPostalCodeAPI(unittest.TestCase):
def setUp(self):
pass
def test_GET_variable_success(self):
url = "http://localhost:{0}/?zip=48867".format(PORT_NUMBER)
f = urllib2.urlopen(url)
self.assertEqual(f.read(), '{"city": "OWOSSO", "state": "MI", "country": "US"}')
def test_GET_variable_failure(self):
url = "http://localhost:{0}/?zip=4886234237".format(PORT_NUMBER)
try:
f = urllib2.urlopen(url)
self.fail
except urllib2.HTTPError:
pass
def test_path_variable_success(self):
url = "http://localhost:{0}/48867".format(PORT_NUMBER)
f = urllib2.urlopen(url)
self.assertEqual(f.read(), '{"city": "OWOSSO", "state": "MI", "country": "US"}')
def test_path_variable_failure(self):
url = "http://localhost:{0}/4886234237".format(PORT_NUMBER)
try:
f = urllib2.urlopen(url)
self.fail
except urllib2.HTTPError:
pass
def test_path_variable_with_country_success(self):
url = "http://localhost:{0}/v2/US/48867".format(PORT_NUMBER)
f = urllib2.urlopen(url)
self.assertEqual(f.read(), '{"city": "Owosso", "state": "Michigan", "country": "US"}')
def test_path_variable_with_country_failure(self):
url = "http://localhost:{0}/v2/WEFG/4886234237".format(PORT_NUMBER)
try:
f = urllib2.urlopen(url)
self.fail
except urllib2.HTTPError:
pass
if __name__ == '__main__':
unittest.main()