-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add <model>_service.create tests
- Loading branch information
Showing
15 changed files
with
223 additions
and
5 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
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
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
Empty file.
Empty file.
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from unittest.mock import Mock | ||
|
||
import pytest | ||
from pytest import fixture | ||
|
||
from costy.application.category.create_category import ( | ||
CreateCategory, | ||
NewCategoryDTO, | ||
) | ||
from costy.application.common.category_gateway import CategorySaver | ||
from costy.application.common.uow import UoW | ||
from costy.domain.models.category import Category, CategoryType | ||
|
||
|
||
@fixture | ||
def category_info() -> NewCategoryDTO: | ||
return NewCategoryDTO("test") | ||
|
||
|
||
@fixture | ||
def interactor(id_provider, category_id, user_id, category_info) -> CreateCategory: | ||
category_service = Mock() | ||
category_service.create.return_value = Category( | ||
id=None, | ||
name=category_info.name, | ||
kind=CategoryType.PERSONAL.value, | ||
user_id=user_id, | ||
) | ||
|
||
async def save_category_mock(category: Category) -> None: | ||
category.id = category_id | ||
|
||
category_gateway = Mock(spec=CategorySaver) | ||
category_gateway.save_category = save_category_mock | ||
uow = Mock(spec=UoW) | ||
return CreateCategory(category_service, category_gateway, id_provider, uow) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_create_operation(interactor: CreateCategory, category_info: NewCategoryDTO, category_id) -> None: | ||
assert await interactor(category_info) == category_id |
Empty file.
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from unittest.mock import Mock | ||
|
||
import pytest | ||
from pytest import fixture | ||
|
||
from costy.application.common.operation_gateway import OperationSaver | ||
from costy.application.common.uow import UoW | ||
from costy.application.operation.create_operation import ( | ||
CreateOperation, | ||
NewOperationDTO, | ||
) | ||
from costy.domain.models.category import CategoryId | ||
from costy.domain.models.operation import Operation | ||
|
||
|
||
@fixture | ||
def operation_info() -> NewOperationDTO: | ||
return NewOperationDTO( | ||
100, | ||
"description", | ||
10000, | ||
CategoryId(999) | ||
) | ||
|
||
|
||
@fixture | ||
def interactor(id_provider, operation_id, user_id, operation_info) -> CreateOperation: | ||
operation_service = Mock() | ||
operation_service.create.return_value = Operation( | ||
id=None, | ||
amount=operation_info.amount, | ||
description=operation_info.description, | ||
time=operation_info.time, | ||
user_id=user_id, | ||
category_id=operation_info.category_id, | ||
) | ||
|
||
async def save_operation_mock(operation: Operation) -> None: | ||
operation.id = operation_id | ||
|
||
operation_gateway = Mock(spec=OperationSaver) | ||
operation_gateway.save_operation = save_operation_mock | ||
uow = Mock(spec=UoW) | ||
return CreateOperation(operation_service, operation_gateway, id_provider, uow) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_create_operation(interactor: CreateOperation, operation_info: NewOperationDTO, operation_id) -> None: | ||
assert await interactor(operation_info) == operation_id |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from unittest.mock import Mock | ||
|
||
import pytest | ||
from pytest import fixture | ||
|
||
from costy.application.authenticate import Authenticate, LoginInputDTO | ||
from costy.application.common.uow import UoW | ||
from costy.application.common.user_gateway import UserReader | ||
from costy.domain.models.user import User, UserId | ||
|
||
|
||
@fixture | ||
def login_info() -> LoginInputDTO: | ||
return LoginInputDTO(email="test@email.com", password="password") | ||
|
||
|
||
@fixture | ||
def interactor(user_id, login_info): | ||
user_gateway = Mock(spec=UserReader) | ||
user_gateway.get_user_by_email.return_value = User( | ||
id=user_id, email=login_info.email, | ||
hashed_password=login_info.password, | ||
) | ||
uow = Mock(spec=UoW) | ||
return Authenticate(user_gateway, uow) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_authenticate(interactor: Authenticate, user_id: UserId, login_info: LoginInputDTO): | ||
assert await interactor(login_info) == user_id |
Empty file.
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from unittest.mock import Mock | ||
|
||
import pytest | ||
from pytest import fixture | ||
|
||
from costy.application.common.uow import UoW | ||
from costy.application.common.user_gateway import UserSaver | ||
from costy.application.user.create_user import CreateUser, NewUserDTO | ||
from costy.domain.models.user import User, UserId | ||
from costy.domain.services.user import UserService | ||
|
||
|
||
@fixture | ||
def user_info() -> NewUserDTO: | ||
return NewUserDTO(email="test@email.com", password="password") | ||
|
||
|
||
@fixture | ||
def interactor(user_id, user_info): | ||
user_service = Mock(spec=UserService) | ||
user_service.create.return_value = User( | ||
id=None, | ||
email=user_info.email, | ||
hashed_password=user_info.password | ||
) | ||
|
||
async def mock_save_user(user: User): | ||
user.id = user_id | ||
|
||
user_gateway = Mock(spec=UserSaver) | ||
user_gateway.save_user = mock_save_user | ||
uow = Mock(spec=UoW) | ||
return CreateUser(user_service, user_gateway, uow) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_create_user(interactor: CreateUser, user_info: NewUserDTO, user_id: UserId): | ||
assert await interactor(user_info) == user_id |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from unittest.mock import Mock | ||
|
||
from pytest import fixture | ||
|
||
from costy.application.common.id_provider import IdProvider | ||
from costy.domain.models.category import CategoryId | ||
from costy.domain.models.operation import OperationId | ||
from costy.domain.models.user import UserId | ||
|
||
|
||
@fixture | ||
def user_id() -> UserId: | ||
return UserId(999) | ||
|
||
|
||
@fixture | ||
def operation_id() -> OperationId: | ||
return OperationId(999) | ||
|
||
|
||
@fixture | ||
def category_id() -> CategoryId: | ||
return CategoryId(999) | ||
|
||
|
||
@fixture | ||
def id_provider(user_id: UserId) -> IdProvider: | ||
provider = Mock(spec=IdProvider) | ||
provider.get_current_user_id.return_value = user_id | ||
return provider |
Empty file.
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import pytest | ||
|
||
from costy.domain.models.category import Category, CategoryId, CategoryType | ||
from costy.domain.models.operation import Operation | ||
from costy.domain.models.user import User, UserId | ||
from costy.domain.services.category import CategoryService | ||
from costy.domain.services.operation import OperationService | ||
from costy.domain.services.user import UserService | ||
|
||
|
||
@pytest.mark.parametrize("domain_service, data, expected_model", [ | ||
( | ||
UserService(), | ||
("email@test.com", "password"), | ||
User(None, "email@test.com", "password") | ||
), | ||
( | ||
OperationService(), | ||
(100, "desc", 10000, UserId(9999), CategoryId(9999)), | ||
Operation(None, 100, "desc", 10000, UserId(9999), CategoryId(9999)) | ||
), | ||
( | ||
CategoryService(), | ||
("test", CategoryType.GENERAL, UserId(9999)), | ||
Category(None, "test", CategoryType.GENERAL.value, UserId(9999)) | ||
), | ||
]) | ||
def test_create_domain_service(domain_service, data, expected_model): | ||
assert domain_service.create(*data) == expected_model |
This file was deleted.
Oops, something went wrong.