-
Notifications
You must be signed in to change notification settings - Fork 710
Expand file tree
/
Copy pathtest_endpoints.py
More file actions
171 lines (142 loc) · 7.03 KB
/
Copy pathtest_endpoints.py
File metadata and controls
171 lines (142 loc) · 7.03 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import unittest
from betamax import Betamax
from app import app
with Betamax.configure() as config:
config.cassette_library_dir = 'test/fixtures'
test_auth_token = '42Kq726Vv6lzJ0TMhXWsgUulVjRsxh'
test_auth_code = 'eIzpzFBUv1X57AFmoKPSMBZrAnb4nK'
class TestCases(unittest.TestCase):
def setUp(self):
# Necessary to disable SSLify
app.debug = True
self.test_app = app.test_client()
self.session = app.requests_session
def test_health_endpoint(self):
"""Assert that the health endpoint works."""
response = app.test_client().get('/health')
self.assertEquals(response.data, ';-)')
def test_root_endpoint(self):
"""Assert that the / endpoint correctly redirects to login.uber.com."""
response = app.test_client().get('/')
self.assertIn('login.uber.com', response.data)
def test_submit_endpoint_success(self):
"""Assert that the / endpoint correctly redirects to login.uber.com."""
with app.test_client() as client:
with client.session_transaction() as session:
session['access_token'] = test_auth_token
with Betamax(app.requests_session).use_cassette('submit_success'):
response = client.get('/submit?code=%s' % test_auth_code)
self.assertEquals(response.status_code, 200)
def test_submit_endpoint_failure(self):
"""Assert that the submit endpoint returns no code in the response."""
with app.test_client() as client:
with client.session_transaction() as session:
session['access_token'] = test_auth_token
with Betamax(app.requests_session).use_cassette('submit_failure'):
response = client.get('/submit?code=not_a_code')
self.assertIn('None', response.data)
def test_products_endpoint_returns_success(self):
"""Assert that the products endpoint returns success.
When a valid key is passed in.
"""
with app.test_client() as client:
with client.session_transaction() as session:
session['access_token'] = test_auth_token
with Betamax(app.requests_session).use_cassette('products_success'):
response = client.get('/products')
self.assertIn('products', response.data)
self.assertEquals(response.status_code, 200)
def test_products_endpoint_returns_failure(self):
"""Assert that the products endpoint returns failure.
When an invalid key is passed in.
"""
with app.test_client() as client:
with client.session_transaction() as session:
session['access_token'] = 'NOT_A_CODE'
with Betamax(self.session).use_cassette('products_failure'):
response = client.get('/products')
self.assertEquals(response.status_code, 401)
def test_time_estimates_endpoint_returns_success(self):
"""Assert that the time estimates endpoint returns success.
When a valid key is passed in.
"""
with app.test_client() as client:
with client.session_transaction() as session:
session['access_token'] = test_auth_token
with Betamax(app.requests_session).use_cassette('time_estimates_success'):
response = client.get('/time')
self.assertIn('times', response.data)
self.assertEquals(response.status_code, 200)
def test_time_estimates_endpoint_returns_failure(self):
"""Assert that the time estimates endpoint returns failure.
When an invalid key is passed in.
"""
with app.test_client() as client:
with client.session_transaction() as session:
session['access_token'] = 'NOT_A_CODE'
with Betamax(app.requests_session).use_cassette('time_estimates_failure'):
response = client.get('/time')
self.assertEquals(response.status_code, 401)
def test_price_estimates_endpoint_returns_success(self):
"""Assert that the price estimates endpoint returns success.
When a valid key is passed in.
"""
with app.test_client() as client:
with client.session_transaction() as session:
session['access_token'] = test_auth_token
with Betamax(app.requests_session).use_cassette('price_estimates_success'):
response = client.get('/price')
self.assertIn('prices', response.data)
self.assertEquals(response.status_code, 200)
def test_price_estimates_endpoint_returns_failure(self):
"""Assert that the price estimates endpoint returns failure.
When an invalid key is passed in.
"""
with app.test_client() as client:
with client.session_transaction() as session:
session['access_token'] = 'NOT_A_CODE'
with Betamax(app.requests_session).use_cassette('price_estimates_failure'):
response = client.get('/price')
self.assertEquals(response.status_code, 401)
def test_history_endpoint_returns_success(self):
"""Assert that the history endpoint returns success.
When a valid key is passed in.
"""
with app.test_client() as client:
with client.session_transaction() as session:
session['access_token'] = test_auth_token
with Betamax(app.requests_session).use_cassette('history_success'):
response = client.get('/history')
self.assertIn('history', response.data)
self.assertEquals(response.status_code, 200)
def test_history_endpoint_returns_failure(self):
"""Assert that the price estimates endpoint returns failure.
When an invalid key is passed in.
"""
with app.test_client() as client:
with client.session_transaction() as session:
session['access_token'] = 'NOT_A_CODE'
with Betamax(app.requests_session).use_cassette('history_failure'):
response = client.get('/history')
self.assertEquals(response.status_code, 401)
def test_me_endpoint_returns_success(self):
"""Assert that the me endpoint returns success.
When a valid key is passed in.
"""
with app.test_client() as client:
with client.session_transaction() as session:
session['access_token'] = test_auth_token
with Betamax(app.requests_session).use_cassette('me_success'):
response = client.get('/me')
self.assertIn('picture', response.data)
self.assertEquals(response.status_code, 200)
def test_me_endpoint_returns_failure(self):
"""Assert that the me endpoint returns failure.
When an invalid key is passed in.
"""
with app.test_client() as client:
with client.session_transaction() as session:
session['access_token'] = 'NOT_A_CODE'
with Betamax(app.requests_session).use_cassette('me_failure'):
response = client.get('/me')
self.assertEquals(response.status_code, 401)