Skip to content

Commit

Permalink
webcompat#451 Putting the tests at the right place
Browse files Browse the repository at this point in the history
  • Loading branch information
karlcow committed Feb 3, 2015
1 parent 13a24f7 commit 3d2b4ed
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 27 deletions.
15 changes: 15 additions & 0 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
sys.path.append(os.path.realpath(os.pardir))

import webcompat
from webcompat.helpers import format_link_header
from webcompat.helpers import normalize_api_params
from webcompat.helpers import parse_link_header
from webcompat.helpers import rewrite_and_sanitize_link
from webcompat.helpers import rewrite_links
from webcompat.helpers import sanitize_link



ACCESS_TOKEN_LINK = '<https://api.github.com/repositories/17839063/issues?per_page=50&page=3&access_token=12345>; rel="next", <https://api.github.com/repositories/17839063/issues?access_token=12345&per_page=50&page=4>; rel="last", <https://api.github.com/repositories/17839063/issues?per_page=50&access_token=12345&page=1>; rel="first", <https://api.github.com/repositories/17839063/issues?per_page=50&page=1&access_token=12345>; rel="prev"'
GITHUB_ISSUES_LINK_HEADER = '<https://api.github.com/repositories/17839063/issues?per_page=50&page=3>; rel="next", <https://api.github.com/repositories/17839063/issues?per_page=50&page=4>; rel="last", <https://api.github.com/repositories/17839063/issues?per_page=50&page=1>; rel="first", <https://api.github.com/repositories/17839063/issues?per_page=50&page=1>; rel="prev"'
GITHUB_SEARCH_LINK_HEADER = '<https://api.github.com/search/issues?q=taco&page=2>; rel="next", <https://api.github.com/search/issues?q=taco&page=26>; rel="last"'
Expand Down Expand Up @@ -94,5 +97,17 @@ def test_normalize_api_params_ignores_unknown_params(self):
normalize_api_params({'foo': u'bar',
'direction': u'desc'}))

def test_parse_http_link_headers(self):
'''Test HTTP Links parsing for GitHub only.'''
parsed_headers = [{'link': 'https://api.github.com/repositories/17914657/issues?page=2', 'rel': 'next'}, {'link': 'https://api.github.com/repositories/17914657/issues?page=11', 'rel': 'last'}]
link_header = '<https://api.github.com/repositories/17914657/issues?page=2>; rel="next", <https://api.github.com/repositories/17914657/issues?page=11>; rel="last"'
self.assertEqual(parse_link_header(link_header), parsed_headers)

def test_format_http_link_headers(self):
'''Test HTTP Links formating.'''
parsed_headers = [{'link': 'https://api.github.com/repositories/17914657/issues?page=2', 'rel': 'next'}, {'link': 'https://api.github.com/repositories/17914657/issues?page=11', 'rel': 'last'}]
link_header = '<https://api.github.com/repositories/17914657/issues?page=2>; rel="next", <https://api.github.com/repositories/17914657/issues?page=11>; rel="last"'
self.assertEqual(format_link_header(parsed_headers), link_header)

if __name__ == '__main__':
unittest.main()
27 changes: 0 additions & 27 deletions tests/test_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
import webcompat

from webcompat.issues import filter_new
from webcompat.helpers import format_link_header
from webcompat.helpers import parse_link_header
from webcompat.helpers import rewrite_links
from webcompat.helpers import sanitize_link

# Any request that depends on parsing HTTP Headers (basically anything
# on the index route, will need to include the following: environ_base=headers
Expand Down Expand Up @@ -109,29 +105,6 @@ def test_issues_new(self):
result = '[{"labels": [{"name": "bug"}, {"name": "help wanted"}], "id": 0, "title": "fake bug 0"}, {"labels": [], "id": 1, "title": "fake bug 1"}]'
self.assertEqual(filter_new(issues), result)

def test_parse_http_link_headers(self):
'''Test HTTP Links parsing for GitHub only.'''
parsed_headers = [{'link': 'https://api.github.com/repositories/17914657/issues?page=2', 'rel': 'next'}, {'link': 'https://api.github.com/repositories/17914657/issues?page=11', 'rel': 'last'}]
link_header = '<https://api.github.com/repositories/17914657/issues?page=2>; rel="next", <https://api.github.com/repositories/17914657/issues?page=11>; rel="last"'
self.assertEqual(parse_link_header(link_header), parsed_headers)

def test_format_http_link_headers(self):
'''Test HTTP Links formating.'''
parsed_headers = [{'link': 'https://api.github.com/repositories/17914657/issues?page=2', 'rel': 'next'}, {'link': 'https://api.github.com/repositories/17914657/issues?page=11', 'rel': 'last'}]
link_header = '<https://api.github.com/repositories/17914657/issues?page=2>; rel="next", <https://api.github.com/repositories/17914657/issues?page=11>; rel="last"'
self.assertEqual(format_link_header(parsed_headers), link_header)

def test_rewrite_links(self):
'''Test the rewriting is correct.'''
link_header_1 = '<https://api.github.com/repositories/17914657/issues?page=2>; rel="next", <https://api.github.com/repositories/17914657/issues?page=11>; rel="last"'
rewritten_header_1 = '</api/issues?page=2>; rel="next", </api/issues?page=11>; rel="last"'
self.assertEqual(rewrite_links(link_header_1), rewritten_header_1)

def test_sanitize_link(self):
'''Test the sanitization.'''
link_header = '<https://api.github.com/repositories/17914657/issues?page=2&access_token=abc123>; rel="next", <https://api.github.com/repositories/17914657/issues?page=11&access_token=abc123>; rel="last"'
rewritten_header = '<https://api.github.com/repositories/17914657/issues?page=2>; rel="next", <https://api.github.com/repositories/17914657/issues?page=11>; rel="last"'
self.assertEqual(sanitize_link(link_header), rewritten_header)

if __name__ == '__main__':
unittest.main()

0 comments on commit 3d2b4ed

Please sign in to comment.