Skip to content

Instantly share code, notes, and snippets.

@smajda
Last active December 7, 2021 11:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save smajda/005f34e88ffa998e02dd to your computer and use it in GitHub Desktop.
Save smajda/005f34e88ffa998e02dd to your computer and use it in GitHub Desktop.
Simple example of using pytest and requests to test http requests
# pip install pytest requests
# py.test
import requests
def test_home():
"GET request to url returns a 200"
url = 'https://monitorial.com/'
resp = requests.get(url)
assert resp.status_code == 200
def test_http_to_https_redirect():
"HTTP requests should be redirected to HTTPS"
url = 'http://monitorial.com/'
resp = requests.get(url)
assert resp.url == 'https://monitorial.com/'
assert resp.history[0].status_code == 301
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment