Skip to content

Commit

Permalink
test: Add load testing scenarios for tasks API
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhikharevAl committed Mar 2, 2024
1 parent 32ee9c8 commit f6a8ef2
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions load_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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}")

0 comments on commit f6a8ef2

Please sign in to comment.