Feat: add e2e test for api
This commit is contained in:
59
tests/e2e/test_api.py
Normal file
59
tests/e2e/test_api.py
Normal file
@@ -0,0 +1,59 @@
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
from backend import config
|
||||
from tests.model.fakes import build_tribes
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("restart_api")
|
||||
@pytest.mark.usefixtures("clean_db")
|
||||
def test_api_post_tribe():
|
||||
data = {"name": "tribe", "level": "2nd"}
|
||||
|
||||
url = config.get_api_url()
|
||||
r = requests.post(f"{url}/tribes", json=data)
|
||||
|
||||
assert r.status_code == 201
|
||||
assert r.json() == {
|
||||
"assessments": [],
|
||||
"level": "2nd",
|
||||
"name": "tribe",
|
||||
"students": [],
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("restart_api")
|
||||
@pytest.mark.usefixtures("clean_db")
|
||||
def test_api_post_list_tribe():
|
||||
tribe = build_tribes(1)[0]
|
||||
|
||||
url = config.get_api_url()
|
||||
r = requests.post(f"{url}/tribes", json=tribe.to_dict())
|
||||
|
||||
assert r.status_code == 201
|
||||
|
||||
r = requests.get(f"{url}/tribes")
|
||||
assert r.json() == [
|
||||
{
|
||||
"assessments": [],
|
||||
"level": tribe.level,
|
||||
"name": tribe.name,
|
||||
"students": [],
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("restart_api")
|
||||
@pytest.mark.usefixtures("clean_db")
|
||||
def test_api_post_student():
|
||||
url = config.get_api_url()
|
||||
tribe = build_tribes(1)[0]
|
||||
requests.post(f"{url}/tribes", json=tribe.to_dict())
|
||||
|
||||
data = {"name": "zart", "tribe_name": tribe.name}
|
||||
r = requests.post(f"{url}/students", json=data)
|
||||
|
||||
assert r.status_code == 201
|
||||
assert r.json()["name"] == "zart"
|
||||
assert r.json()["tribe_name"] == tribe.name
|
||||
assert r.json()["id"]
|
||||
Reference in New Issue
Block a user