-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_test.py
39 lines (31 loc) · 1.32 KB
/
load_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from molotov import scenario
from generator.generator_person_data import generate_person_data
from logging_config import configure_logger
logger = configure_logger(__name__, "test.log")
_API = "http://127.0.0.1:8000/tasks"
@scenario(weight=40)
async def test_get_tasks(session):
try:
async with session.get(_API) as resp:
assert resp.status == 200, resp.status
assert (
resp.headers["content-type"] == "application/json"
), "Unexpected content type: {}".format(resp.headers["content-type"])
except Exception as e:
logger.error(f"An error occurred: {e}")
@scenario(weight=60)
async def test_post_task(session):
try:
person = generate_person_data()
async with session.post(
f"{_API}?name={person.name}&description={person.description}"
) as resp:
assert resp.status == 200, resp.status
assert (
resp.headers["content-type"] == "application/json"
), "Unexpected content type: {}".format(resp.headers["content-type"])
body = await resp.json()
assert "ok" in body, "Response body does not contain 'ok'"
assert "task_id" in body, "Response body does not contain 'task_id'"
except Exception as e:
logger.error(f"An error occurred: {e}")