-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunittest_app.py
57 lines (48 loc) · 2.21 KB
/
unittest_app.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
import unittest
import json
import geojson
from shoeboxlocation import app
class TestIntegrations(unittest.TestCase):
def setUp(self):
"""Set up the testclient and prepare testdata"""
self.app = app.test_client()
self.test_location = {"type": "Feature",
"properties": {
"name": "Shoebox"
},
"geometry": {
"type": "Point",
"coordinates": [
4.5703125,
51.83577752045248
]
}}
self.test_str = json.dumps(self.test_location)
self.test_tuple = '4.5703125,51.83577752045248'
def test_here_status(self):
"""Test if the 'here' endpoint is handling incoming post requests."""
res = self.app.post('/here', data=self.test_str)
self.assertEqual(res.status_code, 200, msg=res.get_data(as_text=True))
def test_here_tuple(self):
"""Test if the 'here' endpoint rejects post requests with tuple of coordinates."""
res = self.app.post('/here', data=self.test_tuple)
self.assertEqual(res.status_code, 400, msg=res.get_data(as_text=True))
def test_here_empty(self):
"""Test if the 'here' endpoint rejects post requests without a post body."""
res = self.app.post('/here')
self.assertEqual(res.status_code, 400, msg=res.get_data(as_text=True))
def test_where_status(self):
"""Test if the 'where' endpoint is handling incoming get requests."""
res = self.app.get('/where')
self.assertEqual(res.status_code, 200, msg=res.get_data(as_text=True))
def test_where_coordinates(self):
"""Test if the 'where' endpoint is returning a json string with coordinates"""
res = self.app.get('/where')
try:
data = geojson.loads(res.get_data(as_text=True))
self.assertTrue(isinstance(data, geojson.feature.Feature),
msg="Expected geojson feature, got {}".format(type(data)))
except:
raise
if __name__ == '__main__':
unittest.main()