-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathapi.py
More file actions
101 lines (81 loc) · 2.93 KB
/
Copy pathapi.py
File metadata and controls
101 lines (81 loc) · 2.93 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
from unittest import main, TestCase
from flask.ext.webtest import TestApp
import json
from app import app
class IssPassTest(TestCase):
"""Test ISS-pass API"""
def setUp(self):
self.app = app
self.w = TestApp(self.app)
self.endpoint = '/iss-pass.json'
def format_uri(self, lat, lon):
return self.endpoint + '?lat={0}&lon={1}'.format(lat, lon)
def test_berkeley(self):
berkeley = self.format_uri(37.8715926, -122.27274699999998)
r = self.w.get(berkeley)
r.charset = 'utf8'
data = json.loads(r.text)
self.assertEqual(r.status_code, 200)
def test_no_passes_found(self):
mcmurdo_station = self.format_uri(-77.8418779, 166.6863449)
r = self.w.get(mcmurdo_station)
self.assertEqual(r.status_code, 200)
data = r.json
self.assertEqual(len(data['response']), 0)
def test_bad_lat(self):
bad_lat = self.format_uri(-91, 50)
r = self.w.get(bad_lat, expect_errors=True)
self.assertEqual(r.status_code, 400)
class IssNowTest(TestCase):
"""Test the ISS-now API"""
def setUp(self):
self.app = app
self.w = TestApp(self.app)
def test_load(self):
# Test the endpoints
r = self.w.get('/iss-now.json')
self.assertFalse(r.flashes)
r = self.w.get('/iss-now/')
self.assertFalse(r.flashes)
r = self.w.get('/iss-now/v1')
self.assertFalse(r.flashes)
def test_data(self):
r = self.w.get('/iss-now.json')
r.charset = 'utf8'
try:
data = json.loads(r.text)
except:
self.fail("ISS API not a valid JSON response")
# Success message
self.assertEqual(data['message'], "success", "ISS API Did not return 'sucess' message")
# timestamp exists
self.assertTrue('timestamp' in data)
# position data
self.assertTrue('iss_position' in data)
self.assertTrue('latitude' in data['iss_position'])
self.assertTrue('longitude' in data['iss_position'])
class AstrosTest(TestCase):
"""Test the number of astros API"""
def setUp(self):
self.app = app
self.w = TestApp(self.app)
def test_load_astros(self):
r = self.w.get('/astros.json')
self.assertFalse(r.flashes)
r = self.w.get('/astros/')
self.assertFalse(r.flashes)
r = self.w.get('/astros/v1')
self.assertFalse(r.flashes)
def test_data(self):
r = self.w.get('/astros.json')
r.charset = 'utf8'
try:
data = json.loads(r.text)
except:
self.fail("ISS API not a valid JSON responce")
# Success message
self.assertEqual(data['message'], "success", "ISS API Did not return 'sucess' message")
# data exists
self.assertTrue('number' in data)
self.assertEqual(type(data['number']), int)
self.assertTrue('people' in data)