Skip to content

Commit

Permalink
test(UserSkill): Adding testes for user skill ROUTE
Browse files Browse the repository at this point in the history
  • Loading branch information
gabszs committed May 23, 2024
1 parent e2d751f commit 90b5e2c
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/services/user_skill_service.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
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


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)
2 changes: 1 addition & 1 deletion tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions tests/routes/v1/test_skill_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
89 changes: 89 additions & 0 deletions tests/routes/v1/test_user_skill_route.py
Original file line number Diff line number Diff line change
@@ -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"}

0 comments on commit 90b5e2c

Please sign in to comment.