mirror of https://github.com/gmbrax/Pilgrim.git
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.
This commit is contained in:
parent
3c7925cb1c
commit
77e191f480
|
|
@ -68,3 +68,26 @@ def test_create_entry_fails_when_diary_id_is_invalid(db_session):
|
|||
)
|
||||
|
||||
assert result is None
|
||||
|
||||
def test_create_entry_successfully_without_photo(populated_db_session):
|
||||
session = populated_db_session
|
||||
service = EntryService(session)
|
||||
diary_id = 1 # Sabemos que o ID é 1 por causa da nossa fixture
|
||||
title = "Primeiro Dia na Praia"
|
||||
text = "O dia foi ensolarado e o mar estava ótimo."
|
||||
date = datetime(2025, 7, 20)
|
||||
photos = []
|
||||
created_entry = service.create(
|
||||
travel_diary_id=diary_id,
|
||||
title=title,
|
||||
text=text,
|
||||
date=date,
|
||||
photos=photos
|
||||
)
|
||||
assert created_entry is not None
|
||||
assert created_entry.id is not None # Garante que foi salvo no BD e tem um ID
|
||||
assert created_entry.title == title
|
||||
assert created_entry.text == text
|
||||
assert len(created_entry.photos) == 0
|
||||
entry_in_db = session.query(Entry).filter_by(id=created_entry.id).one()
|
||||
assert entry_in_db.title == "Primeiro Dia na Praia"
|
||||
Loading…
Reference in New Issue