From 9657bca54ebae9a9b051df6a8f7095776c9d96bd Mon Sep 17 00:00:00 2001 From: vitin-m Date: Thu, 23 Feb 2023 09:28:15 -0300 Subject: [PATCH 1/2] testes de dominio #5 --- pyproject.toml | 6 +++- src/entrypoints/api/{.gitkeep => __init__.py} | 0 src/entrypoints/api/tests/test_api.py | 1 - src/framework/tests/{.gitkeep => __init__.py} | 0 src/framework/tests/value_object_test.py | 30 +++++++++++++++++++ 5 files changed, 35 insertions(+), 2 deletions(-) rename src/entrypoints/api/{.gitkeep => __init__.py} (100%) rename src/framework/tests/{.gitkeep => __init__.py} (100%) create mode 100644 src/framework/tests/value_object_test.py diff --git a/pyproject.toml b/pyproject.toml index 962a4d8..2668011 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,5 +2,9 @@ markers = [ "unit: Unit test marker.", - "integration: Integration test marker." + "integration: Integration test marker.", + "domain: Domain layer tests.", + "application: Application layer tests.", + "infrastructure: Infrastructure layer tests.", + "entrypoint: Solution test. Tests solution as a whole." ] diff --git a/src/entrypoints/api/.gitkeep b/src/entrypoints/api/__init__.py similarity index 100% rename from src/entrypoints/api/.gitkeep rename to src/entrypoints/api/__init__.py diff --git a/src/entrypoints/api/tests/test_api.py b/src/entrypoints/api/tests/test_api.py index dd50f2e..2116741 100644 --- a/src/entrypoints/api/tests/test_api.py +++ b/src/entrypoints/api/tests/test_api.py @@ -1,6 +1,5 @@ import pytest import requests -from entrypoints.api.endpoints import cpus url = "http://127.0.0.1:5000/api/v1" diff --git a/src/framework/tests/.gitkeep b/src/framework/tests/__init__.py similarity index 100% rename from src/framework/tests/.gitkeep rename to src/framework/tests/__init__.py diff --git a/src/framework/tests/value_object_test.py b/src/framework/tests/value_object_test.py new file mode 100644 index 0000000..277d279 --- /dev/null +++ b/src/framework/tests/value_object_test.py @@ -0,0 +1,30 @@ +import pytest + +from ..domain.value_object import Money, URL +from ..domain.rule import BusinessRuleValidationException + + +@pytest.mark.unit +@pytest.mark.domain +def test_money(): + m1 = Money(100) + m2 = Money(100) + m3 = Money(100, "USD") + m4 = Money(150, "USD") + + assert m1 == m2 + assert not (m2 == m3) + assert m3 < m4 + + +@pytest.mark.unit +@pytest.mark.domain +def test_URL(): + u_w_path = URL.get_URL("https://github.com/ES2-UFPI/WiseBuilder") + u_wo_path = URL.get_URL("https://github.com") + + assert u_w_path.domain == "github.com" + assert u_wo_path.domain == "github.com" + + with pytest.raises(BusinessRuleValidationException) as excinfo: + URL.get_URL("github.com/ES2-UFPI/WiseBuilder") From f552b41087dd164ba58a67b40b416a4f1269394f Mon Sep 17 00:00:00 2001 From: vitin-m Date: Tue, 28 Feb 2023 09:15:25 -0300 Subject: [PATCH 2/2] =?UTF-8?q?modifica=C3=A7=C3=B5es=20necess=C3=A1rias?= =?UTF-8?q?=20p/=20teste=20de=20integra=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/SearchEngine/application/unit_of_work.py | 12 ++++++++++++ src/entrypoints/api/endpoints/connection_util.py | 4 ++-- src/entrypoints/api/endpoints/ram.py | 3 --- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/SearchEngine/application/unit_of_work.py b/src/SearchEngine/application/unit_of_work.py index 175a853..448c047 100644 --- a/src/SearchEngine/application/unit_of_work.py +++ b/src/SearchEngine/application/unit_of_work.py @@ -7,6 +7,18 @@ class MockUnitOfWork(AbstractUnitOfWork): + def __init__(self, session): + self.repository = MockRepository({}) + self.commited = False + + def commit(self): + self.commited = True + + def rollback(self): + pass + + +class SQLAlchemyUnitOfWork(AbstractUnitOfWork): def __init__(self, session): self.repository = SQLAlchemyRepository(session) self.commited = False diff --git a/src/entrypoints/api/endpoints/connection_util.py b/src/entrypoints/api/endpoints/connection_util.py index 5d6888b..b6e2c20 100644 --- a/src/entrypoints/api/endpoints/connection_util.py +++ b/src/entrypoints/api/endpoints/connection_util.py @@ -3,13 +3,13 @@ create_session, ) from framework.infrastructure.db_management.db_creation import create_db -from SearchEngine.application.unit_of_work import MockUnitOfWork +from SearchEngine.application.unit_of_work import SQLAlchemyUnitOfWork from framework.application.handler import MessageBus from SearchEngine.application.handlers import COMMAND_HANDLER_MAPPER def _message_bus(engine): - uow = MockUnitOfWork(create_session(engine)) + uow = SQLAlchemyUnitOfWork(create_session(engine)) COMMAND_HANDLER_MAPPER_CALLABLE = {} for c, h in COMMAND_HANDLER_MAPPER.items(): COMMAND_HANDLER_MAPPER_CALLABLE[c] = h(uow) diff --git a/src/entrypoints/api/endpoints/ram.py b/src/entrypoints/api/endpoints/ram.py index 1f01b4d..705347c 100644 --- a/src/entrypoints/api/endpoints/ram.py +++ b/src/entrypoints/api/endpoints/ram.py @@ -4,9 +4,6 @@ from flask_restx import Namespace, Resource, fields from .connection_util import message_bus -from framework.application.handler import MessageBus -from SearchEngine.application.handlers import COMMAND_HANDLER_MAPPER -from SearchEngine.application.unit_of_work import MockUnitOfWork from SearchEngine.domain.repositories import ( EntityUIDNotFoundException, EntityUIDCollisionException,