Skip to content

Commit f810084

Browse files
committed
Merge pull request #21 from uber/zh/fix-scopes
Fix scopes
2 parents 2fedc3c + 1311113 commit f810084

10 files changed

+11
-24
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.DEFAULT_GOAL := test
33

44
test: clean lint
5-
@py.test --cov app.py -s test/
5+
@py.test test/ --cov app.py -s
66

77
lint:
88
@flake8 .

app.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def signup():
5454
params = {
5555
'response_type': 'code',
5656
'redirect_uri': get_redirect_uri(request),
57-
'scope': ','.join(config.get('scopes')),
57+
'scopes': ','.join(config.get('scopes')),
5858
}
5959
url = generate_oauth_service().get_authorize_url(**params)
6060
return redirect(url)
@@ -72,7 +72,6 @@ def submit():
7272
'code': request.args.get('code'),
7373
'grant_type': 'authorization_code'
7474
}
75-
7675
response = app.requests_session.post(
7776
config.get('access_token_url'),
7877
auth=(
@@ -82,6 +81,7 @@ def submit():
8281
data=params,
8382
)
8483
session['access_token'] = response.json().get('access_token')
84+
8585
return render_template(
8686
'success.html',
8787
token=response.json().get('access_token')
@@ -180,7 +180,7 @@ def price():
180180
@app.route('/history', methods=['GET'])
181181
def history():
182182
"""Return the last 5 trips made by the logged in user."""
183-
url = config.get('base_uber_url') + 'history'
183+
url = config.get('base_uber_url_v1_1') + 'history'
184184
params = {
185185
'offset': 0,
186186
'limit': 5,

config.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
"access_token_url": "https://login.uber.com/oauth/token",
33
"authorize_url": "https://login.uber.com/oauth/authorize",
44
"base_url": "https://login.uber.com/",
5-
"scopes": ["profile"],
5+
"scopes": ["profile", "history_lite"],
66
"name": "Sample app",
77
"base_uber_url": "https://api.uber.com/v1/",
8+
"base_uber_url_v1_1" : "https://api.uber.com/v1.1/",
89
"start_latitude": "37.781955",
910
"start_longitude": "-122.402367",
1011
"end_latitude": "37.744352",

requirements-test.txt

-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
# Test harness
22
pytest==2.5.2
3-
43
# Coverage
54
pytest-cov==1.6
6-
75
# HTTP Fixtures
86
betamax==0.4.0
9-
107
# LINT OR DIE
118
flake8==2.1.0
129
pep8==1.5.6
1310
pyflakes==0.8.1
14-
1511
# Coveralls
1612
coveralls==0.4.2

setup.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
[flake8]
22
max-line-length = 100
3+
exclude = env

test/fixtures/history_failure.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"http_interactions": [{"request": {"body": {"string": "", "encoding": "utf-8"}, "headers": {"Accept": ["*/*"], "Content-Type": ["application/json"], "Accept-Encoding": ["gzip, deflate"], "Authorization": ["bearer NOT_A_CODE"], "User-Agent": ["python-requests/2.3.0 CPython/2.7.5 Darwin/13.2.0"]}, "method": "GET", "uri": "https://api.uber.com/v1/history?limit=5&offset=0"}, "response": {"body": {"string": "{\"message\":\"Invalid OAuth 2.0 credentials provided.\",\"code\":\"unauthorized\"}", "encoding": null}, "headers": {"content-length": ["75"], "server": ["nginx"], "connection": ["keep-alive"], "date": ["Fri, 01 Aug 2014 20:22:08 GMT"], "x-uber-app": ["uberex-nonsandbox"], "content-type": ["application/json"]}, "status": {"message": "Unauthorized", "code": 401}, "url": "https://api.uber.com/v1/history?limit=5&offset=0"}, "recorded_at": "2014-08-01T20:22:08"}], "recorded_with": "betamax/0.4.0"}
1+
{"http_interactions": [{"request": {"body": {"string": "", "encoding": "utf-8"}, "headers": {"Accept": ["*/*"], "Content-Type": ["application/json"], "Accept-Encoding": ["gzip, deflate"], "Authorization": ["bearer NOT_A_CODE"], "User-Agent": ["python-requests/2.3.0 CPython/2.7.5 Darwin/13.4.0"]}, "method": "GET", "uri": "https://api.uber.com/v1.1/history?limit=5&offset=0"}, "response": {"body": {"string": "{\"message\":\"Invalid OAuth 2.0 credentials provided.\",\"code\":\"unauthorized\"}", "encoding": null}, "headers": {"content-length": ["75"], "server": ["nginx"], "connection": ["keep-alive"], "date": ["Mon, 06 Oct 2014 16:58:57 GMT"], "x-uber-app": ["uberex-nonsandbox"], "content-type": ["application/json"]}, "status": {"message": "Unauthorized", "code": 401}, "url": "https://api.uber.com/v1.1/history?limit=5&offset=0"}, "recorded_at": "2014-10-06T16:58:57"}], "recorded_with": "betamax/0.4.0"}

test/fixtures/history_success.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"http_interactions": [{"request": {"body": {"string": "", "encoding": "utf-8"}, "headers": {"Accept": ["*/*"], "Content-Type": ["application/json"], "Accept-Encoding": ["gzip, deflate"], "Authorization": ["bearer 42Kq726Vv6lzJ0TMhXWsgUulVjRsxh"], "User-Agent": ["python-requests/2.3.0 CPython/2.7.5 Darwin/13.2.0"]}, "method": "GET", "uri": "https://api.uber.com/v1/history?limit=5&offset=0"}, "response": {"body": {"base64_string": "H4sIAAAAAAAAA62VUWvcMAzHv0rIc1xsybaseyuDbU9jUNjLGMWJnTZwd+lyydgo/e7TraXd7dJe1u3NEEey9Pv/pduy6aftWK58VfZtu8ty1FW57jadnFxVXne7sR9+lKvPt+VujOO0K1fyz+ZmncecyqpMciFum1yu4MwGBq+Nx6qcpi7JTTKhBY+tYjakLDk5Oc9KAxsOZOrWWQkiIYbxcuw2EsZY7Vmz51CVN0Ofpma8/BVrqvPwXS7nbfr9qtEIcvU+xLpv4tj123J1W67lNE5JQiKdkSXPTIal0HW/vXr4ogzIs7UP6ANJuTGlIe/2NQZbfMxDXI+xOP+Wt1Ouiou4Ld4OUmy3a/qqeHNe3t2/5vms5MARW4SZrCZYZgA+yKpAF8aM18XFOOQ8PpN0yF+nvPujY2jdXbWAEhptHEqLHylFTE1os1Ym1kLJglDyiRRlxoQYHaZ6hlIADEyLKAWwDuTqaUqktRedzPRLe2IQhR30C/4TJQb0diapQDKMVlTzmzReCykABOIFkIxokow1AcwjpBCw8dS0ygk8sZJuVPSxVgJKN7mus4E5K1Hw5JZBIjGkFu+egiQW1+iClrcdWcmQgWDtoah1KC76SUT9SRz0Qfz1L5ayJBIBu1fTUXbtvfVMh7T0Mokce0pa5ywswIVnyM44zfYJl28ptRGtqhtyyno0KmhtxGKoM1MMNsUZTxEGApnACyYfoVQqRjmFSyYf7cPON8xRcF4+PcmbjEzrZT3bj+KXhp9kRdwPmiNS4ivQJhyMXFJgXjX8pDpgXAjKaJEPSOKHFRUsNT6ZWjWNrZVt66xqTFE50OhdFs9yngEl2yT4haC0lpl7GhQxMnsAseBRvwAt2f2EeuLknVayJYt3/XR1Yl+8zMkGH9h6Pb8aCeAgrehcVOyAi/dxc7O77ob8t8tqv4kd3n25+wkeOPQwfwgAAA==", "encoding": null}, "headers": {"x-rate-limit-remaining": ["4990"], "content-language": ["en"], "content-encoding": ["gzip"], "transfer-encoding": ["chunked"], "strict-transport-security": ["max-age=2592000"], "server": ["nginx"], "connection": ["keep-alive"], "x-rate-limit-reset": ["1406926800"], "x-uber-app": ["uberex-nonsandbox"], "date": ["Fri, 01 Aug 2014 20:22:09 GMT"], "x-rate-limit-limit": ["5000"], "content-type": ["application/json"]}, "status": {"message": "OK", "code": 200}, "url": "https://api.uber.com/v1/history?limit=5&offset=0"}, "recorded_at": "2014-08-01T20:22:09"}], "recorded_with": "betamax/0.4.0"}
1+
{"http_interactions": [{"request": {"body": {"string": "", "encoding": "utf-8"}, "headers": {"Accept": ["*/*"], "Content-Type": ["application/json"], "Accept-Encoding": ["gzip, deflate"], "Authorization": ["bearer MLth87eHvSAaCQ1vn7jTd0xA9Kapo5"], "User-Agent": ["python-requests/2.3.0 CPython/2.7.5 Darwin/13.4.0"]}, "method": "GET", "uri": "https://api.uber.com/v1.1/history?limit=5&offset=0"}, "response": {"body": {"base64_string": "H4sIAAAAAAAAA62TTW7bMBBG78K1aHB+yOH4KkURUBSJGojtxJYWReC7d5SFi9gGaqDRjuLokW++0Yerx+Uwu20UHNyx93OzRRjc626/W18P7tfuPB9Pv932x4c7z2Vezm5rX+3fXtvcJje4yQrKoTa3BdhIzFGFMw9uWXaTlbYWShtz9TFS8Jwq+kKZfW9x7KI1tKpGMcZpfpl3+5XDgFbNRIN7Ox2npc4vn6wC9lRjVcFPFvlsdR57nSahEDisN2qH6QuJE5ndqb0v7XxzBgFdhn+L4QZDRFXQv2LcU9fCwVcu3TPW4jV08hFUEiXRVPIjMYKwUr5BjDCG9FCMAos+IYYb0IyUrd3XwEJhqG0KPvVaPRcZvSaiNbreKcaecW3ybWDMwGiU//cyUmbr0H1gtkPIT3jxBpk0RYGrFkdoHdEGr49sMoheI3dfa5NWiGxm4YEWqVnJd2gZScFI91q2AyRPaOEmZEg5iOjVq/SeRonox1p0DSn4cQT10ssIQkUCyAMv1Bjo1mviMpbSxHeekmcwqoINgRifmh0dCxvr6/9lJEl2n3svtN5lvvy8/AHuOYdTZwQAAA==", "encoding": null}, "headers": {"x-rate-limit-remaining": ["999"], "content-language": ["en"], "content-encoding": ["gzip"], "transfer-encoding": ["chunked"], "strict-transport-security": ["max-age=2592000"], "server": ["nginx"], "connection": ["keep-alive"], "x-rate-limit-reset": ["1412618400"], "x-uber-app": ["uberex-nonsandbox"], "date": ["Mon, 06 Oct 2014 17:12:33 GMT"], "x-rate-limit-limit": ["1000"], "content-type": ["application/json"]}, "status": {"message": "OK", "code": 200}, "url": "https://api.uber.com/v1.1/history?limit=5&offset=0"}, "recorded_at": "2014-10-06T17:12:33"}], "recorded_with": "betamax/0.4.0"}

test/fixtures/submit_failure.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"http_interactions": [{"request": {"body": {"string": "code=not_a_code&redirect_uri=https%3A%2F%2Flocalhost%3ANone%2Fsubmit&grant_type=authorization_code", "encoding": "utf-8"}, "headers": {"Content-Length": ["98"], "Accept-Encoding": ["gzip, deflate"], "Accept": ["*/*"], "User-Agent": ["python-requests/2.3.0 CPython/2.7.5 Darwin/13.2.0"], "Content-Type": ["application/x-www-form-urlencoded"], "Authorization": ["Basic X3Y1QmNlNGZ6U0xsTWlJcTgyT05YWGtnZFcwOFBYSlc6QzJkZW1iY3JJV3ljWlBYcVE0SzY1RW1pTFRzRWFOSnAwS045VkJLUQ=="]}, "method": "POST", "uri": "https://login.uber.com/oauth/token"}, "response": {"body": {"string": "{\"error\": \"invalid_grant\"}", "encoding": null}, "headers": {"content-length": ["26"], "server": ["nginx"], "connection": ["keep-alive"], "pragma": ["no-cache"], "cache-control": ["no-store"], "date": ["Fri, 22 Aug 2014 18:40:19 GMT"], "x-uber-app": ["login"], "content-type": ["application/json"]}, "status": {"message": "BAD REQUEST", "code": 400}, "url": "https://login.uber.com/oauth/token"}, "recorded_at": "2014-08-22T18:40:19"}], "recorded_with": "betamax/0.4.0"}
1+
{"http_interactions": [{"request": {"body": {"string": "code=not_a_code&redirect_uri=http%3A%2F%2Flocalhost%3ANone%2Fsubmit&grant_type=authorization_code", "encoding": "utf-8"}, "headers": {"Content-Length": ["97"], "Accept-Encoding": ["gzip, deflate"], "Accept": ["*/*"], "User-Agent": ["python-requests/2.3.0 CPython/2.7.5 Darwin/13.4.0"], "Content-Type": ["application/x-www-form-urlencoded"], "Authorization": ["Basic MW14R3hFR1JxcXU3Z1g5OTE2Rnc0azkwVmlHcTdLVzA6SV8wNW9tRFNIbjM5MHFISDJreE5zd04wb004bUZlc3pBQnREckQ0RQ=="]}, "method": "POST", "uri": "https://login.uber.com/oauth/token"}, "response": {"body": {"string": "{\"error\": \"invalid_grant\"}", "encoding": null}, "headers": {"content-length": ["26"], "server": ["nginx"], "connection": ["keep-alive"], "pragma": ["no-cache"], "cache-control": ["no-store"], "date": ["Mon, 06 Oct 2014 17:11:05 GMT"], "x-uber-app": ["login"], "content-type": ["application/json"]}, "status": {"message": "BAD REQUEST", "code": 400}, "url": "https://login.uber.com/oauth/token"}, "recorded_at": "2014-10-06T17:11:05"}], "recorded_with": "betamax/0.4.0"}

test/fixtures/submit_success.json

-1
This file was deleted.

test/test_endpoints.py

+1-11
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
with Betamax.configure() as config:
77
config.cassette_library_dir = 'test/fixtures'
88

9-
test_auth_token = '42Kq726Vv6lzJ0TMhXWsgUulVjRsxh'
10-
test_auth_code = 'eIzpzFBUv1X57AFmoKPSMBZrAnb4nK'
9+
test_auth_token = 'MLth87eHvSAaCQ1vn7jTd0xA9Kapo5'
1110

1211

1312
class TestCases(unittest.TestCase):
@@ -27,15 +26,6 @@ def test_root_endpoint(self):
2726
response = app.test_client().get('/')
2827
self.assertIn('login.uber.com', response.data)
2928

30-
def test_submit_endpoint_success(self):
31-
"""Assert that the / endpoint correctly redirects to login.uber.com."""
32-
with app.test_client() as client:
33-
with client.session_transaction() as session:
34-
session['access_token'] = test_auth_token
35-
with Betamax(app.requests_session).use_cassette('submit_success'):
36-
response = client.get('/submit?code=%s' % test_auth_code)
37-
self.assertEquals(response.status_code, 200)
38-
3929
def test_submit_endpoint_failure(self):
4030
"""Assert that the submit endpoint returns no code in the response."""
4131
with app.test_client() as client:

0 commit comments

Comments
 (0)