Skip to content

Commit

Permalink
Improve the permanent_url test to ensure it handles mixing correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
fluffy-critter committed Aug 19, 2020
1 parent e5f08af commit b327a99
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,27 @@ def test_permanent_url(requests_mock):

req = requests.get('http://perm-308.example')
assert utils.permanent_url(req) == 'https://make-secure.example/308'

# make sure that it's the last pre-temporary redirect that counts
requests_mock.get('https://one/', status_code=301,
headers={'Location': 'https://two/'})
requests_mock.get('https://two/', status_code=302,
headers={'Location': 'https://three/'})
requests_mock.get('https://three/', status_code=301,
headers={'Location': 'https://four/'})
requests_mock.get('https://four/', text="done")

req = requests.get('https://one/')
assert req.url == 'https://four/'
assert utils.permanent_url(req) == 'https://two/'
assert req.text == 'done'

req = requests.get('https://two/')
assert req.url == 'https://four/'
assert utils.permanent_url(req) == 'https://two/'
assert req.text == 'done'

req = requests.get('https://three/')
assert req.url == 'https://four/'
assert utils.permanent_url(req) == 'https://four/'
assert req.text == 'done'

0 comments on commit b327a99

Please sign in to comment.