Compare commits

...

11 Commits

Author SHA1 Message Date
Gustavo Henrique Santos Souza de Miranda cc95ce669f Merge remote-tracking branch 'origin/test/entryservice-unit-test' into test/entryservice-unit-test
# Conflicts:
#	tests/service/test_entry_service.py
2025-07-20 23:16:48 -03:00
Gustavo Henrique Santos Souza de Miranda d36ff829db Remove the shared fixtures that are available on conftest.py 2025-07-20 23:15:08 -03:00
Gustavo Henrique Santos Souza de Miranda 0173465943 Add all tests to test the delete of entries 2025-07-20 23:13:46 -03:00
Gustavo Henrique Santos Souza de Miranda 5b9a5bfe24 Add all tests to test the read of entries 2025-07-20 23:13:46 -03:00
Gustavo Henrique Santos Souza de Miranda 95a3a13ee2 Add all tests to test the update of entries 2025-07-20 23:13:46 -03:00
Gustavo Henrique Santos Souza de Miranda f9fb660d7c Add a test to test the creation of entries with null on nullable fields 2025-07-20 23:13:45 -03:00
Gustavo Henrique Santos Souza de Miranda f7a7289b5e test(entry_service): add test for creating an entry without photos
This commit adds a unit test to ensure that the EntryService's
`create` method correctly handles cases where an empty list of photos
is provided.

It verifies that the entry is created successfully and that the
`photos` relationship is an empty list, confirming the feature's
flexibility.
2025-07-20 23:13:45 -03:00
Gustavo Henrique Santos Souza de Miranda 0227879bb3 test(entry_service): add a failure case test for create method
This commit adds a unit test for an important "unhappy path" in the
EntryService's `create` method.

It specifically verifies that the method gracefully returns `None`
when provided with a `travel_diary_id` that does not exist in the
database, ensuring the initial guard clause works as expected.
2025-07-20 23:13:45 -03:00
Gustavo Henrique Santos Souza de Miranda e46f02cc39 test(entry_service): add unit test for creating a new entry
This commit introduces the first unit test for the EntryService,
covering the "happy path" for the `create` method.

It verifies that a new entry is correctly persisted to the database,
including its relationship with associated Photo objects. The test
leverages fixtures to create an isolated, in-memory database
populated with the necessary dependencies.
2025-07-20 23:13:45 -03:00
Gustavo Henrique Miranda e9162ab25c
Merge pull request #63 from gmbrax/refactor/shared-test-fixtures
Refactor to add conftest.py to share fixtures
2025-07-20 23:12:32 -03:00
Gustavo Henrique Santos Souza de Miranda 88a0b9cf80 Refactor to add conftest.py to share fixtures 2025-07-20 23:07:04 -03:00
2 changed files with 28 additions and 16 deletions

28
tests/conftest.py Normal file
View File

@ -0,0 +1,28 @@
import pytest
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from pilgrim.database import Base
from pilgrim.models.travel_diary import TravelDiary
# Todos os imports necessários para as fixtures devem estar aqui
# ...
@pytest.fixture(scope="function")
def db_session():
"""Esta fixture agora está disponível para TODOS os testes."""
engine = create_engine("sqlite:///:memory:")
Base.metadata.create_all(engine)
Session = sessionmaker(bind=engine)
session = Session()
yield session
session.close()
Base.metadata.drop_all(engine)
@pytest.fixture
def populated_db_session(db_session):
"""Esta também fica disponível para todos."""
travel_diary = TravelDiary(name="My Travel Diary", directory_name="viagem-teste")
db_session.add(travel_diary)
db_session.commit()
return db_session

View File

@ -14,23 +14,7 @@ from pilgrim.models.photo import Photo
from pilgrim.service.entry_service import EntryService
@pytest.fixture(scope="function")
def db_session():
engine = create_engine("sqlite:///:memory:")
Base.metadata.create_all(engine)
Session = sessionmaker(bind=engine)
session = Session()
yield session
session.close()
Base.metadata.drop_all(engine)
@pytest.fixture
def populated_db_session(db_session):
travel_diary = TravelDiary(name="My Travel Diary", directory_name="viagem-teste")
db_session.add(travel_diary)
db_session.commit()
return db_session
@pytest.fixture
def session_with_an_entry(populated_db_session):