Last active
December 7, 2021 11:45
-
-
Save smajda/005f34e88ffa998e02dd to your computer and use it in GitHub Desktop.
Simple example of using pytest and requests to test http requests
This file contains hidden or 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
# 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