Skip to content

Instantly share code, notes, and snippets.

@se1983
Created February 2, 2023 10:32
Show Gist options
  • Save se1983/6d11166fa85036dd87c05c183450cf64 to your computer and use it in GitHub Desktop.
Save se1983/6d11166fa85036dd87c05c183450cf64 to your computer and use it in GitHub Desktop.
import time
import requests
""" Develop an asynchronous REST API with any Python Framework you like. """
BONUS_POINTS = False
def test_api():
resp = requests.post("http://localhost:8000/elements/", data = {"name": "interview-success"})
assert resp.status_code == 200
assert list(resp.json().keys()) == ["href", "status"]
href = resp.json()["href"]
if BONUS_POINTS:
assert requests.get(url=href).status_code == 404
time.sleep(5)
resp = requests.get(url=href)
assert resp.status_code == 200
assert list(resp.json().keys()) == ["name", "id", "created"]
assert resp.json()["name"] == "INTERVIEW SUCCESS"
test_api()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment