Skip to content

Commit 0ccbe17

Browse files
committed
Merge pull request #7 from uber/pytest
Fix test runner and instructions
2 parents 2f481a3 + 22b87c2 commit 0ccbe17

File tree

7 files changed

+61
-32
lines changed

7 files changed

+61
-32
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.pyc
2+
*.egg-info

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,15 @@ How To Use This
2424
Testing
2525
-------
2626

27-
1. Install the dependencies with `pip install -r requirements.txt`
28-
2. Run the command `nosetests -v`
27+
1. Install the dependencies with:
28+
29+
```bash
30+
pip install -r requirements.txt
31+
pip install -r requirements-test.txt
32+
python setup.py develop
33+
```
34+
35+
2. Run the command `py.test test/`
2936
3. If you delete the fixtures, or decide to add some of your own, you’ll have to re-generate them, and the way this is done is by running the app, getting an auth_token from the main page of the app. Paste that token in place of the `test_auth_token` at the top of the `test_endpoints.py` file, then run the tests.
3037

3138

@@ -35,7 +42,7 @@ Development
3542
If you want to work on this application we’d love your pull requests and tickets on GitHub!
3643

3744
1. If you open up a ticket, please make sure it describes the problem or feature request fully.
38-
2. If you send us a pull request, make sure you add a test for what you added, and make sure the full test suite runs with `nosetests -v`.
45+
2. If you send us a pull request, make sure you add a test for what you added, and make sure the full test suite runs with `py.test`.
3946

4047
Deploy to Heroku
4148
----------------

app.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121

2222
def generate_oauth_service():
23-
"""Prepares the OAuth2Service that is used to make requests later."""
23+
"""Prepare the OAuth2Service that is used to make requests later."""
2424
return OAuth2Service(
2525
client_id=os.environ.get('UBER_CLIENT_ID'),
2626
client_secret=os.environ.get('UBER_CLIENT_SECRET'),
@@ -32,7 +32,7 @@ def generate_oauth_service():
3232

3333

3434
def generate_ride_headers(token):
35-
"""Generates the header object that is used to make api requests."""
35+
"""Generate the header object that is used to make api requests."""
3636
return {
3737
'Authorization': 'bearer %s' % token,
3838
'Content-Type': 'application/json',
@@ -41,7 +41,7 @@ def generate_ride_headers(token):
4141

4242
@app.route('/health', methods=['GET'])
4343
def health():
44-
"""Used to check the status of this application."""
44+
"""Check the status of this application."""
4545
return ';-)'
4646

4747

@@ -96,10 +96,10 @@ def demo():
9696

9797
@app.route('/products', methods=['GET'])
9898
def products():
99-
'''Example call to the products endpoint.
99+
"""Example call to the products endpoint.
100100
101101
Returns all the products currently available in San Francisco.
102-
'''
102+
"""
103103
url = config.get('base_uber_url') + 'products'
104104
params = {
105105
'latitude': config.get('start_latitude'),
@@ -179,7 +179,7 @@ def price():
179179

180180
@app.route('/history', methods=['GET'])
181181
def history():
182-
"""Returns the last 5 trips made by the logged in user."""
182+
"""Return the last 5 trips made by the logged in user."""
183183
url = config.get('base_uber_url') + 'history'
184184
params = {
185185
'offset': 0,
@@ -203,7 +203,7 @@ def history():
203203

204204
@app.route('/me', methods=['GET'])
205205
def me():
206-
"""Returns user information including name, picture and email."""
206+
"""Return user information including name, picture and email."""
207207
url = config.get('base_uber_url') + 'me'
208208
response = app.requests_session.get(
209209
url,
@@ -218,8 +218,9 @@ def me():
218218
data=response.text,
219219
)
220220

221+
221222
def get_redirect_uri(request):
222-
"""Returns OAuth redirect URI."""
223+
"""Return OAuth redirect URI."""
223224
parsed_url = urlparse(request.url)
224225
if parsed_url.hostname == 'localhost':
225226
return 'http://{hostname}:{port}/submit'.format(hostname=parsed_url.hostname, port=parsed_url.port)

requirements-test.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Test harness
2+
pytest==2.5.2
3+
4+
# Coverage
5+
pytest-cov==1.6
6+
7+
# HTTP Fixtures
8+
betamax==0.4.0

requirements.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ Flask==0.10.1
22
Jinja2==2.7.3
33
MarkupSafe==0.23
44
Werkzeug==0.9.6
5-
betamax==0.4.0
65
gnureadline==6.3.3
76
itsdangerous==0.24
8-
nose==1.3.3
97
rauth==0.7.0
108
requests==2.3.0
119
wsgiref==0.1.2
1210

1311
gunicorn==18.0
14-
Flask-SSLify==0.1.4
12+
Flask-SSLify==0.1.4

setup.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from setuptools import setup, find_packages
2+
3+
setup(
4+
name='Python-Sample-Application',
5+
version='0.0.1',
6+
author='Uber Engineering',
7+
author_email='[email protected]',
8+
packages=find_packages(),
9+
description='Python sample application',
10+
)

test/test_endpoints.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,28 @@
88

99
test_auth_token = '42Kq726Vv6lzJ0TMhXWsgUulVjRsxh'
1010

11+
1112
class TestCases(unittest.TestCase):
1213
def setUp(self):
14+
# Necessary to disable SSLify
15+
app.debug = True
1316
self.test_app = app.test_client()
1417
self.session = app.requests_session
1518

1619
def test_health_endpoint(self):
17-
"""Asserts that the health endpoint works."""
20+
"""Assert that the health endpoint works."""
1821
response = app.test_client().get('/health')
1922
self.assertEquals(response.data, ';-)')
2023

2124
def test_root_endpoint(self):
22-
"""Asserts that the / endpoint correctly redirects to login.uber.com."""
25+
"""Assert that the / endpoint correctly redirects to login.uber.com."""
2326
response = app.test_client().get('/')
2427
self.assertIn('login.uber.com', response.data)
2528

2629
def test_products_endpoint_returns_success(self):
27-
"""Asserts that the products endpoint returns success
30+
"""Assert that the products endpoint returns success.
2831
29-
when a valid key is passed in.
32+
When a valid key is passed in.
3033
"""
3134
with app.test_client() as client:
3235
with client.session_transaction() as session:
@@ -36,9 +39,9 @@ def test_products_endpoint_returns_success(self):
3639
self.assertEquals(response.status_code, 200)
3740

3841
def test_products_endpoint_returns_failure(self):
39-
"""Asserts that the products endpoint returns failure
42+
"""Assert that the products endpoint returns failure.
4043
41-
when an invalid key is passed in.
44+
When an invalid key is passed in.
4245
"""
4346
with app.test_client() as client:
4447
with client.session_transaction() as session:
@@ -48,9 +51,9 @@ def test_products_endpoint_returns_failure(self):
4851
self.assertEquals(response.status_code, 401)
4952

5053
def test_time_estimates_endpoint_returns_success(self):
51-
"""Asserts that the time estimates endpoint returns success
54+
"""Assert that the time estimates endpoint returns success.
5255
53-
when a valid key is passed in.
56+
When a valid key is passed in.
5457
"""
5558
with app.test_client() as client:
5659
with client.session_transaction() as session:
@@ -60,9 +63,9 @@ def test_time_estimates_endpoint_returns_success(self):
6063
self.assertEquals(response.status_code, 200)
6164

6265
def test_time_estimates_endpoint_returns_failure(self):
63-
"""Asserts that the time estimates endpoint returns failure
66+
"""Assert that the time estimates endpoint returns failure.
6467
65-
when an invalid key is passed in.
68+
When an invalid key is passed in.
6669
"""
6770
with app.test_client() as client:
6871
with client.session_transaction() as session:
@@ -72,9 +75,9 @@ def test_time_estimates_endpoint_returns_failure(self):
7275
self.assertEquals(response.status_code, 401)
7376

7477
def test_price_estimates_endpoint_returns_success(self):
75-
"""Asserts that the price estimates endpoint returns success
78+
"""Assert that the price estimates endpoint returns success.
7679
77-
when a valid key is passed in.
80+
When a valid key is passed in.
7881
"""
7982
with app.test_client() as client:
8083
with client.session_transaction() as session:
@@ -84,9 +87,9 @@ def test_price_estimates_endpoint_returns_success(self):
8487
self.assertEquals(response.status_code, 200)
8588

8689
def test_price_estimates_endpoint_returns_failure(self):
87-
"""Asserts that the price estimates endpoint returns failure
90+
"""Assert that the price estimates endpoint returns failure.
8891
89-
when an invalid key is passed in.
92+
When an invalid key is passed in.
9093
"""
9194
with app.test_client() as client:
9295
with client.session_transaction() as session:
@@ -96,9 +99,9 @@ def test_price_estimates_endpoint_returns_failure(self):
9699
self.assertEquals(response.status_code, 401)
97100

98101
def test_history_endpoint_returns_success(self):
99-
"""Asserts that the history endpoint returns success
102+
"""Assert that the history endpoint returns success.
100103
101-
when a valid key is passed in.
104+
When a valid key is passed in.
102105
"""
103106
with app.test_client() as client:
104107
with client.session_transaction() as session:
@@ -108,9 +111,9 @@ def test_history_endpoint_returns_success(self):
108111
self.assertEquals(response.status_code, 200)
109112

110113
def test_history_endpoint_returns_failure(self):
111-
"""Asserts that the price estimates endpoint returns failure
114+
"""Assert that the price estimates endpoint returns failure.
112115
113-
when an invalid key is passed in.
116+
When an invalid key is passed in.
114117
"""
115118
with app.test_client() as client:
116119
with client.session_transaction() as session:

0 commit comments

Comments
 (0)