Skip to content

Commit

Permalink
Merge pull request #44 from ES2-UFPI/unit-tests-#5
Browse files Browse the repository at this point in the history
Unit tests #5
  • Loading branch information
wesleyvitor11000 authored Mar 2, 2023
2 parents f3d74e7 + f552b41 commit cb4a0fc
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 7 deletions.
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
]
12 changes: 12 additions & 0 deletions src/SearchEngine/application/unit_of_work.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/entrypoints/api/endpoints/connection_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions src/entrypoints/api/endpoints/ram.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/entrypoints/api/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pytest
import requests
from entrypoints.api.endpoints import cpus

url = "http://127.0.0.1:5000/api/v1"

Expand Down
File renamed without changes.
30 changes: 30 additions & 0 deletions src/framework/tests/value_object_test.py
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit cb4a0fc

Please sign in to comment.