-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
145 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from typing import Any | ||
from typing import Any, List | ||
|
||
import pytest | ||
from fastapi import FastAPI | ||
|
@@ -36,6 +36,18 @@ class UserServiceDummy: | |
async def create_user(self, user: Any) -> UserModel: | ||
return USER_MODEL | ||
|
||
async def list_users(self) -> List[UserModel]: | ||
return [USER_MODEL] | ||
|
||
async def get_user_by_id(self, id: int) -> UserModel: | ||
return USER_MODEL | ||
|
||
async def update_user(self, id: int, new_user: Any) -> UserModel: | ||
return USER_MODEL | ||
|
||
async def remove_user(self, id: int) -> UserModel: | ||
return USER_MODEL | ||
|
||
|
||
def get_user_services_dummy() -> UserServiceDummy: | ||
return UserServiceDummy() | ||
|
@@ -79,3 +91,44 @@ def test_user_create_valide( | |
) | ||
assert response.status_code == status.HTTP_200_OK | ||
assert response.json() == user_schema.__dict__ | ||
|
||
def test_user_update( | ||
self, user_model: UserModel, user_schema: UserDBSchema | ||
) -> None: | ||
|
||
response = client.put( | ||
"/users/1", | ||
json={ | ||
"email": "[email protected]", | ||
"full_name": "test", | ||
"password": "test", | ||
"is_active": True, | ||
"is_superuser": False, | ||
"created_date": "1/1/2020", | ||
}) | ||
assert response.status_code == status.HTTP_200_OK | ||
assert response.json() == user_schema.__dict__ | ||
|
||
def test_user_delete( | ||
self, user_model: UserModel, user_schema: UserDBSchema | ||
) -> None: | ||
|
||
response = client.delete("/users/1") | ||
assert response.status_code == status.HTTP_200_OK | ||
assert response.json() == user_schema.__dict__ | ||
|
||
def test_user_list_all( | ||
self, user_model: UserModel, user_schema: UserDBSchema | ||
) -> None: | ||
|
||
response = client.get("/users/all") | ||
assert response.status_code == status.HTTP_200_OK | ||
assert response.json() == [user_schema.__dict__] | ||
|
||
def test_user_get_byid( | ||
self, user_model: UserModel, user_schema: UserDBSchema | ||
) -> None: | ||
|
||
response = client.get("/users/1") | ||
assert response.status_code == status.HTTP_200_OK | ||
assert response.json() == user_schema.__dict__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
from typing import Any | ||
from typing import Any, List | ||
|
||
import pytest | ||
|
||
from src.domain.userManagment.schema.user import UserCreateSchema, UserDBSchema | ||
from src.domain.userManagment.schema.user import UserCreateSchema, UserDBSchema, UserUpdateSchema | ||
from src.domain.userManagment.service.userService import UserService | ||
from src.infrastructure.database.models.user import UserModel | ||
|
||
|
@@ -21,6 +21,18 @@ class UserQueriesDummy: | |
async def create_user(self, user: Any) -> UserModel: | ||
return USER_MODEL | ||
|
||
async def update_user(self, old_user: Any, new_user: Any) -> UserModel: | ||
return USER_MODEL | ||
|
||
async def delete_user(self, user_id: int) -> UserModel: | ||
return USER_MODEL | ||
|
||
async def get_user_byid(self, user_id: int) -> UserModel: | ||
return USER_MODEL | ||
|
||
async def get_all_users(self) -> List[UserModel]: | ||
return [USER_MODEL] | ||
|
||
|
||
@pytest.fixture | ||
def user_model() -> UserModel: | ||
|
@@ -40,6 +52,19 @@ def user_schema() -> UserCreateSchema: | |
) | ||
|
||
|
||
@pytest.fixture | ||
def user_update_schema() -> UserUpdateSchema: | ||
return UserUpdateSchema( | ||
user_id=1, | ||
email="[email protected]", | ||
full_name="test", | ||
password="test", | ||
is_active=True, | ||
is_superuser=False, | ||
created_date="1/1/2020", | ||
) | ||
|
||
|
||
class TestUserService: | ||
@pytest.mark.asyncio | ||
async def test_user_create_valide( | ||
|
@@ -56,3 +81,67 @@ async def test_user_create_valide( | |
is_superuser=False, | ||
created_date="1/1/2020", | ||
) | ||
|
||
@pytest.mark.asyncio | ||
async def test_user_list_users( | ||
self, user_model: UserModel, user_schema: UserCreateSchema | ||
) -> None: | ||
user_service = UserService(UserQueriesDummy()) | ||
|
||
result = await user_service.list_users() | ||
assert result == [UserDBSchema( | ||
user_id=1, | ||
email="[email protected]", | ||
full_name="test", | ||
is_active=True, | ||
is_superuser=False, | ||
created_date="1/1/2020", | ||
)] | ||
|
||
@pytest.mark.asyncio | ||
async def test_user_update_user( | ||
self, user_model: UserModel, user_update_schema: UserUpdateSchema | ||
) -> None: | ||
user_service = UserService(UserQueriesDummy()) | ||
|
||
result = await user_service.update_user(1, user_update_schema) | ||
assert result == UserDBSchema( | ||
user_id=1, | ||
email="[email protected]", | ||
full_name="test", | ||
is_active=True, | ||
is_superuser=False, | ||
created_date="1/1/2020", | ||
) | ||
|
||
@pytest.mark.asyncio | ||
async def test_user_remove_user( | ||
self, user_model: UserModel, user_schema: UserCreateSchema | ||
) -> None: | ||
user_service = UserService(UserQueriesDummy()) | ||
|
||
result = await user_service.remove_user(1) | ||
assert result == UserDBSchema( | ||
user_id=1, | ||
email="[email protected]", | ||
full_name="test", | ||
is_active=True, | ||
is_superuser=False, | ||
created_date="1/1/2020", | ||
) | ||
|
||
@pytest.mark.asyncio | ||
async def test_user_get_user_by_id( | ||
self, user_model: UserModel, user_schema: UserCreateSchema | ||
) -> None: | ||
user_service = UserService(UserQueriesDummy()) | ||
|
||
result = await user_service.get_user_by_id(1) | ||
assert result == UserDBSchema( | ||
user_id=1, | ||
email="[email protected]", | ||
full_name="test", | ||
is_active=True, | ||
is_superuser=False, | ||
created_date="1/1/2020", | ||
) |