Created
December 2, 2012 23:42
-
-
Save deontologician/4191608 to your computer and use it in GitHub Desktop.
E2E test for link header parsing in requests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
def test_multiple_rels_per_link(): | |
r = requests.get('http://www.httpbin.org/response-headers?link=' | |
'</two-rel>;rel="alternate self";title="The Title"') | |
assert r.links == {'alternate': [{'href' : '/two-rel', | |
'rel': 'alternate', | |
'title': 'The Title'}], | |
'self' : [{'href' : '/two-rel', | |
'rel': 'self', | |
'title': 'The Title'}]} | |
def test_multiple_links_per_rel(): | |
r = requests.get('http://www.httpbin.org/response-headers?link=' | |
'</same-rel-1>;rel=alternate,' | |
'</same-rel-2>;rel="alternate"') | |
assert r.links == {'alternate': [{'href': '/same-rel-1', | |
'rel': 'alternate'}, | |
{'href': '/same-rel-2', | |
'rel': 'alternate'}]} | |
if __name__ == '__main__': | |
test_multiple_rels_per_link() | |
test_multiple_links_per_rel() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment