Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix link headers example in docs #469

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions docs/source/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ Link headers
second_url = "http://foo-api.com/data?page=2"
link_str = "<%s>; rel='next'" % second_url

# Performs a request to `first_url` followed by some testing
httpretty.register_uri(
httpretty.GET,
first_url,
Expand All @@ -138,21 +139,22 @@ Link headers
content_type="text/json",
adding_headers={"Link": link_str},
)

response = requests.get(first_url)
expect(response.json()).to.equal({"success": True})
expect(response.status_code).to.equal(200)
next_url = response.links["next"]["url"]
expect(next_url).to.equal(second_url)

# Follow the next URL and perform some testing.
httpretty.register_uri(
httpretty.GET,
second_url,
body='{"success": false}',
status=500,
content_type="text/json",
)
# Performs a request to `first_url` followed by some testing
response = requests.get(first_url)
expect(response.json()).to.equal({"success": True})
expect(response.status_code).to.equal(200)
next_url = response.links["next"]["url"]
expect(next_url).to.equal(second_url)

# Follow the next URL and perform some testing.
response2 = requests.get(next_url)
expect(response2.json()).to.equal({"success": False})
expect(response2.status_code).to.equal(500)
Expand Down