Skip to content

Commit

Permalink
Fixes #1618 - Removes JSON-P callback from test_api_comments_link_hea…
Browse files Browse the repository at this point in the history
…der_auth.
  • Loading branch information
brizental committed Aug 9, 2017
1 parent d3fed76 commit 40328bf
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions tests/test_api_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from mock import patch, MagicMock
from mock import MagicMock
from requests import Response
from requests.structures import CaseInsensitiveDict

import webcompat

Expand All @@ -24,15 +25,20 @@

def mock_api_response(response_config={}):
''' Helper method to create a mock response from the Github API.'''
api_response = MagicMock(spec=Response)
api_response.content_type = 'application/json'
api_response.headers = {
headers = {
'ETag': 'W/"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"',
'Cache-Control': 'public, max-age=60, s-maxage=60',
'Content-Type': 'application/json; charset=utf-8'
}
api_response = MagicMock(spec=Response)
api_response.content_type = 'application/json'
for k, v in response_config.iteritems():
if k == 'headers':
headers.update(v)
setattr(api_response, k, v)
# Request headers are case insenstive dicts,
# so we need to turn our mock headers into one.
api_response.headers = CaseInsensitiveDict(headers)
return api_response


Expand Down Expand Up @@ -98,28 +104,25 @@ def test_api_comments_link_header_auth(self):
github_data.side_effect = [
mock_api_response({
'status_code': 200,
'content': '[{"Link":[["https://api.github.com/repositories/17839063/issues/398/comments?callback=foo&page=2",{"rel":"next"}],["https://api.github.com/repositories/17839063/issues/398/comments?callback=foo&page=4",{"rel":"last"}]]}]' # nopep8
'content': '[]',
'headers': {
'Link': '<https://api.github.com/repositories/17839063/issues/398/comments?page=2>; rel="next", <https://api.github.com/repositories/17839063/issues/398/comments?page=4>; rel="last"', # nopep8
},
}),
mock_api_response({'status_code': 200, 'content': '[]'})
]
# Force a JSONP callback response with `query_string`
# because it gives us the header properties we want to test.
query_string = {'callback': 'foo'}
rv = self.app.get('/api/issues/398/comments',
query_string=query_string, environ_base=headers)
# Make sure that rv.data is not empty.
self.assertTrue(len(rv.data) > 0)
self.assertTrue = all(x in rv.data for x in ['Link', 'rel', 'next',
'last', 'page'])
rv = self.app.get('/api/issues/398/comments', environ_base=headers)
self.assertTrue(
'link' in rv.headers and all(
x in rv.headers.get('link') for x in [
'page', 'next', 'last']))
self.assertEqual(rv.status_code, 200)
self.assertEqual(rv.content_type, 'application/json')
# API access to comments for an issue
# with < 30 does not return link a header in
# the response (until GitHub changes it....?)
rv = self.app.get('/api/issues/4/comments',
query_string=query_string, environ_base=headers)
self.assertTrue = not all(
x in rv.data for x in ['Link', 'rel', 'next', 'last', 'page'])
rv = self.app.get('/api/issues/4/comments', environ_base=headers)
self.assertTrue('link' not in rv.headers)
self.assertEqual(rv.status_code, 200)
self.assertEqual(rv.content_type, 'application/json')

Expand Down

0 comments on commit 40328bf

Please sign in to comment.