From 90b5e2c91b3b5723e3ba58d35a01c539fef53995 Mon Sep 17 00:00:00 2001 From: GabrielCarvalho Date: Thu, 23 May 2024 18:50:40 -0300 Subject: [PATCH] test(UserSkill): Adding testes for user skill ROUTE --- app/services/user_skill_service.py | 6 ++ tests/factories.py | 2 +- tests/routes/v1/test_skill_route.py | 1 + tests/routes/v1/test_user_skill_route.py | 89 ++++++++++++++++++++++++ 4 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 tests/routes/v1/test_user_skill_route.py diff --git a/app/services/user_skill_service.py b/app/services/user_skill_service.py index 0b60236..3f65a5c 100644 --- a/app/services/user_skill_service.py +++ b/app/services/user_skill_service.py @@ -1,4 +1,7 @@ +from uuid import UUID + from app.repository.user_skill_repository import UserSkillRepository +from app.schemas.base_schema import FindBase from app.services.base_service import BaseService @@ -6,3 +9,6 @@ class UserSkillService(BaseService): def __init__(self, user_skill_repository: UserSkillRepository): self.user_skill_repository = user_skill_repository super().__init__(user_skill_repository) + + async def get_skill_by_user(self, user_id: UUID, find_query: FindBase): + return await self.user_skill_repository.read_skills_by_user_id(user_id, find_query) diff --git a/tests/factories.py b/tests/factories.py index 8370066..478a45f 100644 --- a/tests/factories.py +++ b/tests/factories.py @@ -56,7 +56,7 @@ class Meta: users_id = None skill_id = None skill_level = fuzzy.FuzzyChoice(SkillLevel) - skill_years_experience = factory.Faker("pyint", min_value=0, max_value=1000) + skill_years_experience = factory.Faker("pyint", min_value=0, max_value=70) skill = None user = None diff --git a/tests/routes/v1/test_skill_route.py b/tests/routes/v1/test_skill_route.py index a7e2267..de449f7 100644 --- a/tests/routes/v1/test_skill_route.py +++ b/tests/routes/v1/test_skill_route.py @@ -82,6 +82,7 @@ async def test_get_all_skills_should_return_200_OK_GET(session, client, default_ assert response.status_code == 200 assert len(response_founds) == 8 assert response_json["search_options"] == default_search_options | {"total_count": 8} + ic(response_founds, clean_skills) assert all( [ skill.skill_name == response_founds[count]["skill_name"] diff --git a/tests/routes/v1/test_user_skill_route.py b/tests/routes/v1/test_user_skill_route.py new file mode 100644 index 0000000..508046e --- /dev/null +++ b/tests/routes/v1/test_user_skill_route.py @@ -0,0 +1,89 @@ +# import pytest +# from icecream import ic + +# from tests.conftest import get_normal_token_header +# from tests.conftest import setup_skill_data +# from tests.conftest import setup_users_data +# from tests.conftest import validate_datetime +# from tests.routes.v1.test_skill_route import get_skill_by_index +# from tests.routes.v1.test_user_route import get_user_by_index + +# base_url = "v1/user-skill" + + +# async def get_search_normal_user_skill_data(client, session, normal_users: int = 1, skills_qty: int = 1, **kwargs): +# await setup_users_data(session, normal_users=normal_users, **kwargs) +# await setup_skill_data(session, skills_qty) + +# user_search = await get_user_by_index(client) +# skill_search = await get_skill_by_index(client) + +# return user_search, skill_search + + +# @pytest.mark.anyio +# async def test_create_normal_user_skills_should_return_201_POST(client, session, factory_user_skill): +# token_header = await get_normal_token_header(client, session) +# user_search, skill_search = await get_search_normal_user_skill_data(client, session) + +# response = await client.post( +# f"{base_url}/", +# json={ +# "users_id": user_search["id"], +# "skill_id": skill_search["id"], +# "skill_level": factory_user_skill.skill_level, +# "skill_years_experience": factory_user_skill.skill_years_experience, +# }, +# headers=token_header, +# ) +# response_json = response.json() +# ic(response_json, response) +# validate_datetime +# assert False + + +# ic + +# assert response.status_code == 201 +# assert response_json["skill_name"] == factory_skill.skill_name +# assert response_json["category"] == factory_skill.category +# assert validate_datetime(response_json["created_at"]) +# assert validate_datetime(response_json["updated_at"]) + + +# @pytest.mark.anyio +# async def test_create_normal_skill_should_return_422_unprocessable_entity_POST(client, session): +# token_header = await get_admin_token_header(client, session) +# response = await client.post(f"{base_url}/", headers=token_header) + +# assert response.status_code == 422 + + +# @pytest.mark.anyio +# async def test_create_normal_skill_should_return_409_email_already_registered_POST(client, session): +# token_header = await get_admin_token_header(client, session) +# clean_skills = await setup_skill_data(session, 1) +# clean_skill = clean_skills[0] +# response = await client.post( +# f"{base_url}/", +# json={"skill_name": clean_skill.skill_name, "category": clean_skill.category}, +# headers=token_header, +# ) + +# assert response.status_code == 409 +# assert response.json() == {"detail": "Skill already registered"} + + +# @pytest.mark.anyio +# async def test_create_skill_should_return_409_email_already_registered_POST(client, session): +# token_header = await get_admin_token_header(client, session) +# clean_skills = await setup_skill_data(session) +# clean_skill = clean_skills[0] +# response = await client.post( +# f"{base_url}/", +# json={"skill_name": clean_skill.skill_name, "category": clean_skill.category}, +# headers=token_header, +# ) + +# assert response.status_code == 409 +# assert response.json() == {"detail": "Skill already registered"}