Skip to content

Commit

Permalink
Merge pull request #68 from FASoftwareEngineering/unit/career
Browse files Browse the repository at this point in the history
unit-тестирование для скиллов/грейдов/ролей
  • Loading branch information
belo4ya authored Dec 24, 2022
2 parents c90b945 + 0db19f2 commit 162f816
Show file tree
Hide file tree
Showing 4 changed files with 300 additions and 0 deletions.
Empty file.
95 changes: 95 additions & 0 deletions src/tests/unit/career/test_grade.py
Original file line number Diff line number Diff line change
@@ -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"
102 changes: 102 additions & 0 deletions src/tests/unit/career/test_role.py
Original file line number Diff line number Diff line change
@@ -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"
103 changes: 103 additions & 0 deletions src/tests/unit/career/test_skill.py
Original file line number Diff line number Diff line change
@@ -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#"

0 comments on commit 162f816

Please sign in to comment.