From 0db19f22728072c320a994b762921d8738947037 Mon Sep 17 00:00:00 2001 From: shycoldii Date: Thu, 22 Dec 2022 18:08:30 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=D0=B0=20un?= =?UTF-8?q?it-=D1=82=D0=B5=D1=81=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B4=D0=BB=D1=8F=20=D1=81=D0=BA=D0=B8=D0=BB?= =?UTF-8?q?=D0=BB=D0=BE=D0=B2/=D0=B3=D1=80=D0=B5=D0=B9=D0=B4=D0=BE=D0=B2/?= =?UTF-8?q?=D1=80=D0=BE=D0=BB=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tests/unit/career/__init__.py | 0 src/tests/unit/career/test_grade.py | 95 +++++++++++++++++++++++++ src/tests/unit/career/test_role.py | 102 +++++++++++++++++++++++++++ src/tests/unit/career/test_skill.py | 103 ++++++++++++++++++++++++++++ 4 files changed, 300 insertions(+) create mode 100644 src/tests/unit/career/__init__.py create mode 100644 src/tests/unit/career/test_grade.py create mode 100644 src/tests/unit/career/test_role.py create mode 100644 src/tests/unit/career/test_skill.py diff --git a/src/tests/unit/career/__init__.py b/src/tests/unit/career/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/tests/unit/career/test_grade.py b/src/tests/unit/career/test_grade.py new file mode 100644 index 0000000..f68aa23 --- /dev/null +++ b/src/tests/unit/career/test_grade.py @@ -0,0 +1,95 @@ +import pytest +from httpx import AsyncClient + +from app.cli.db import init_dev + + +@pytest.fixture +def init_data(): + init_dev() + + +@pytest.fixture +def grades_url() -> str: + return "/v1/grades" + + +@pytest.fixture +def grades_by_id_url() -> str: + return "/v1/grades/{value}" + + +@pytest.mark.anyio +@pytest.mark.use_case +@pytest.mark.usefixtures("runtime_db", "init_data") +async def test_create_grade(client: AsyncClient, grades_url: str): + + resp = await client.post( + grades_url, + json={"name": "senior1"}, + ) + new_grade = resp.json() + + assert resp.status_code == 201 + assert new_grade["name"] == "senior1" + + +@pytest.mark.anyio +@pytest.mark.use_case +@pytest.mark.usefixtures("runtime_db", "init_data") +async def test_get_grade_by_id(client: AsyncClient, grades_by_id_url: str): + + resp = await client.get(grades_by_id_url.format(value=1)) + grade = resp.json() + + assert resp.status_code == 200 + assert grade["id"] == 1 + + +@pytest.mark.anyio +@pytest.mark.use_case +@pytest.mark.usefixtures("runtime_db", "init_data") +async def test_delete_grade_by_id(client: AsyncClient, grades_by_id_url: str): + resp = await client.get(grades_by_id_url.format(value=1)) + assert resp.status_code == 200 + + await client.delete(grades_by_id_url.format(value=1)) + + resp = await client.get(grades_by_id_url.format(value=1)) + assert resp.status_code == 404 + + +@pytest.mark.anyio +@pytest.mark.use_case +@pytest.mark.usefixtures("runtime_db", "init_data") +async def test_get_grades(client: AsyncClient, grades_url: str): + + resp = await client.get(grades_url) + grades = resp.json() + + assert resp.status_code == 200 + assert len(grades) == 5 + + +@pytest.mark.anyio +@pytest.mark.use_case +@pytest.mark.usefixtures("runtime_db", "init_data") +async def test_update_grade(client: AsyncClient, grades_url: str, grades_by_id_url: str): + + # создание грейда + resp = await client.post( + grades_url, + json={"name": "senior2"}, + ) + new_grade = resp.json() + + assert resp.status_code == 201 + + # обновление грейда + resp = await client.patch( + grades_by_id_url.format(value=new_grade["id"]), + json={"name": "senior3"}, + ) + new_grade = resp.json() + assert resp.status_code == 200 + assert new_grade["name"] == "senior3" diff --git a/src/tests/unit/career/test_role.py b/src/tests/unit/career/test_role.py new file mode 100644 index 0000000..edd935e --- /dev/null +++ b/src/tests/unit/career/test_role.py @@ -0,0 +1,102 @@ +import pytest +from httpx import AsyncClient + +from app.cli.db import init_dev + + +@pytest.fixture +def init_data(): + init_dev() + + +@pytest.fixture +def roles_url() -> str: + return "/v1/roles" + + +@pytest.fixture +def roles_by_id_url() -> str: + return "/v1/roles/{value}" + + +@pytest.mark.anyio +@pytest.mark.use_case +@pytest.mark.usefixtures("runtime_db", "init_data") +async def test_create_role(client: AsyncClient, roles_url: str): + + # получение грейдов из начального наполнения + resp = await client.get(f"/v1/grades") + grades = resp.json() + our_grades = [grades[0], grades[1]] + + # создание роли + resp = await client.post( + roles_url, + json={"name": "cashier", "grades": [{"id": grade["id"]} for grade in our_grades]}, + ) + new_role = resp.json() + + assert resp.status_code == 201 + assert new_role["name"] == "cashier" + assert len(new_role["grades"]) == 2 + + +@pytest.mark.anyio +@pytest.mark.use_case +@pytest.mark.usefixtures("runtime_db", "init_data") +async def test_get_role_by_id(client: AsyncClient, roles_by_id_url: str): + + resp = await client.get(roles_by_id_url.format(value=1)) + role = resp.json() + + assert resp.status_code == 200 + assert role["id"] == 1 + + +@pytest.mark.anyio +@pytest.mark.use_case +@pytest.mark.usefixtures("runtime_db", "init_data") +async def test_delete_role_by_id(client: AsyncClient, roles_by_id_url: str): + resp = await client.get(roles_by_id_url.format(value=1)) + assert resp.status_code == 200 + + await client.delete(roles_by_id_url.format(value=1)) + + resp = await client.get(roles_by_id_url.format(value=1)) + assert resp.status_code == 404 + + +@pytest.mark.anyio +@pytest.mark.use_case +@pytest.mark.usefixtures("runtime_db", "init_data") +async def test_get_roles(client: AsyncClient, roles_url: str): + + resp = await client.get(roles_url) + roles = resp.json() + + assert resp.status_code == 200 + assert len(roles) == 5 + + +@pytest.mark.anyio +@pytest.mark.use_case +@pytest.mark.usefixtures("runtime_db", "init_data") +async def test_update_role(client: AsyncClient, roles_url: str, roles_by_id_url: str): + + # создание роли + resp = await client.post( + roles_url, + json={"name": "assistent"}, + ) + new_role = resp.json() + + assert resp.status_code == 201 + + # обновление роли + resp = await client.patch( + roles_by_id_url.format(value=new_role["id"]), + json={"name": "assistent2"}, + ) + new_role = resp.json() + assert resp.status_code == 200 + assert new_role["name"] == "assistent2" diff --git a/src/tests/unit/career/test_skill.py b/src/tests/unit/career/test_skill.py new file mode 100644 index 0000000..ac1f2df --- /dev/null +++ b/src/tests/unit/career/test_skill.py @@ -0,0 +1,103 @@ +import pytest +from httpx import AsyncClient + +from app.cli.db import init_dev + + +@pytest.fixture +def init_data(): + init_dev() + + +@pytest.fixture +def skills_url() -> str: + return "/v1/skills" + + +@pytest.fixture +def skills_by_id_url() -> str: + return "/v1/skills/{value}" + + +@pytest.mark.anyio +@pytest.mark.use_case +@pytest.mark.usefixtures("runtime_db", "init_data") +async def test_create_skill(client: AsyncClient, skills_url: str): + + resp = await client.post( + skills_url, + json={ + "name": "java", + "max_score": 5, + }, + ) + new_skill = resp.json() + + assert resp.status_code == 201 + assert new_skill["name"] == "java" + assert new_skill["max_score"] == 5 + + +@pytest.mark.anyio +@pytest.mark.use_case +@pytest.mark.usefixtures("runtime_db", "init_data") +async def test_get_skill_by_id(client: AsyncClient, skills_by_id_url: str): + + resp = await client.get(skills_by_id_url.format(value=1)) + skill = resp.json() + + assert resp.status_code == 200 + assert skill["id"] == 1 + + +@pytest.mark.anyio +@pytest.mark.use_case +@pytest.mark.usefixtures("runtime_db", "init_data") +async def test_delete_skill_by_id(client: AsyncClient, skills_by_id_url: str): + resp = await client.get(skills_by_id_url.format(value=1)) + assert resp.status_code == 200 + + await client.delete(skills_by_id_url.format(value=1)) + + resp = await client.get(skills_by_id_url.format(value=1)) + assert resp.status_code == 404 + + +@pytest.mark.anyio +@pytest.mark.use_case +@pytest.mark.usefixtures("runtime_db", "init_data") +async def test_get_skills(client: AsyncClient, skills_url: str): + + resp = await client.get(skills_url) + skills = resp.json() + + assert resp.status_code == 200 + assert len(skills) == 13 + + +@pytest.mark.anyio +@pytest.mark.use_case +@pytest.mark.usefixtures("runtime_db", "init_data") +async def test_update_skill(client: AsyncClient, skills_url: str, skills_by_id_url: str): + + # создание скилла + resp = await client.post( + skills_url, + json={ + "name": "java", + "max_score": 5, + }, + ) + new_skill = resp.json() + + assert resp.status_code == 201 + + # обновление скилла + resp = await client.patch( + skills_by_id_url.format(value=new_skill["id"]), + json={"name": "c#"}, + ) + new_skill = resp.json() + + assert resp.status_code == 200 + assert new_skill["name"] == "c#"