Skip to content

Commit

Permalink
issue webcompat#3204 - fixes tests and function for get requests
Browse files Browse the repository at this point in the history
  • Loading branch information
karlcow committed May 14, 2020
1 parent 6a2e2d5 commit 66fa020
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions tests/unit/test_api_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,18 @@ def test_api_proxy_issues(self):
'content': '[{"here": "an escaped json"})]',
'headers': {'link': '<issues?page=2>; rel="next", <issues?page=41>; rel="last"'}, # noqa
})
rv = self.app.get('/api/issues')
rv = self.app.get('/api/issues', environ_base=headers)
assert rv.status_code == 200
assert rv.content_type == 'application/json'
assert '</api/issues?page=2>' in rv.headers['link']
assert rv.data == b'[{"here": "an escaped json"})]'

def test_api_proxy_issues_with_q_404(self):
"""Check list of issues with a parameter for non-auth users."""
rv = self.app.get('/api/issues?q=foo')
rv = self.app.get('/api/issues?q=foo', environ_base=headers)
assert rv.status_code == 404
assert rv.content_type == 'text/plain'
assert rv.data == b'Nope'
assert rv.content_type == 'application/json'
assert b'"message": "Not Found. Lost in Punk Cat Space"' in rv.data

def test_api_proxy_issues_with_q(self):
"""Check list of issues with a parameter for non-auth users."""
Expand All @@ -217,8 +218,9 @@ def test_api_proxy_issues_with_q(self):
user.user_id = 'punkCat'
g.user = user
with patch('webcompat.api.endpoints.get_search_results') as resp:
# we just want to test that it is calling get_search_results
resp.return_value = 'call get_search_results'
rv = self.app.get('/api/issues?q=foo')
rv = self.app.get('/api/issues?q=foo', environ_base=headers)
assert rv.data == b'call get_search_results'


Expand Down
2 changes: 1 addition & 1 deletion webcompat/api/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def proxy_issues():
# Non-authed users should never get here--the request is made to
# GitHub client-side)--but return out of paranoia anyways.
elif params.get('q'):
abort(Response('Nope', status=404, content_type='text/plain'))
abort(404)
path = 'repos/{0}'.format(ISSUES_PATH)
return api_request('get', path, params=params)

Expand Down

0 comments on commit 66fa020

Please sign in to comment.