Skip to content

Commit

Permalink
Fixes #1618 - Fixes some style inconsistencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
brizental committed Aug 8, 2017
1 parent b05d2ae commit f3fbd17
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions tests/test_api_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import unittest

from mock import patch, MagicMock
from mock import MagicMock
from requests import Response

import webcompat
Expand All @@ -21,16 +22,18 @@
'HTTP_ACCEPT': 'application/json'}


def mock_api_response(dict):
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 = {
'etag': 'thisisatest',
'cache-control': 'thisisatest',
'content-type': 'application/json'
'ETag': 'W/"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"',
'Cache-Control': 'public, max-age=60, s-maxage=60',
'Content-Type': 'application/json; charset=utf-8'
}
for k, v in dict.iteritems():
for k, v in response_config.iteritems():
if k == 'headers':
v.update(api_response.headers)
setattr(api_response, k, v)
return api_response

Expand All @@ -56,7 +59,7 @@ def test_api_issues_out_of_range(self):
with patch('webcompat.helpers.proxy_request') as github_data:
github_data.return_value = mock_api_response({
'status_code': 404,
'content': '{"message":"Not Found","documentation_url":"https://developer.github.com/v3"}' # nopep8
'content': '[{"message":"Not Found","documentation_url":"https://developer.github.com/v3"}]' # nopep8
})
rv = self.app.get('/api/issues/1', environ_base=headers)
json_body = json.loads(rv.data)
Expand Down Expand Up @@ -84,7 +87,7 @@ def test_api_labels_without_auth(self):
'''API access to labels without auth returns JSON 200.'''
with patch('webcompat.helpers.proxy_request') as github_data:
github_data.return_value = mock_api_response(
{'status_code': 200, 'content': '{}'})
{'status_code': 200, 'content': '[]'})
rv = self.app.get('/api/issues/labels', environ_base=headers)
self.assertEqual(rv.status_code, 200)
self.assertEqual(rv.content_type, 'application/json')
Expand All @@ -99,13 +102,15 @@ def test_api_comments_link_header_auth(self):
'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
}),
mock_api_response({'status_code': 200, 'content': '{}'})
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'])
self.assertEqual(rv.status_code, 200)
Expand All @@ -116,8 +121,7 @@ def test_api_comments_link_header_auth(self):
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'])
x in rv.data for x in ['Link', 'rel', 'next', 'last', 'page'])
self.assertEqual(rv.status_code, 200)
self.assertEqual(rv.content_type, 'application/json')

Expand Down

0 comments on commit f3fbd17

Please sign in to comment.