Skip to content

Commit 8ce454f

Browse files
karlcowMike Taylor
authored and
Mike Taylor
committed
test for rewrite_links #451
1 parent 56c7a69 commit 8ce454f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

tests/test_urls.py

+13
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from webcompat.issues import filter_new
1818
from webcompat.helpers import format_link_header
1919
from webcompat.helpers import parse_link_header
20+
from webcompat.helpers import rewrite_links
2021

2122
# Any request that depends on parsing HTTP Headers (basically anything
2223
# on the index route, will need to include the following: environ_base=headers
@@ -119,5 +120,17 @@ def test_format_http_link_headers(self):
119120
link_header = '<https://api.github.com/repositories/17914657/issues?page=2>; rel="next", <https://api.github.com/repositories/17914657/issues?page=11>; rel="last"'
120121
self.assertEqual(format_link_header(parsed_headers), link_header)
121122

123+
def test_rewrite_links(self):
124+
'''Test the rewriting is correct.'''
125+
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"'
126+
rewritten_header_1 = '</api/issues?page=2>; rel="next", </api/issues?page=11>; rel="last"'
127+
self.assertEqual(rewrite_links(link_header_1), rewritten_header_1)
128+
129+
def test_sanitize_link(self):
130+
'''Test the sanitization.'''
131+
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"'
132+
rewritten_header = '<https://api.github.com/repositories/17914657/issues?page=2>; rel="next", <https://api.github.com/repositories/17914657/issues?page=11>; rel="last"'
133+
self.assertEqual(sanitize_link(link_header), rewritten_header)
134+
122135
if __name__ == '__main__':
123136
unittest.main()

0 commit comments

Comments
 (0)