Skip to content

Commit

Permalink
Add model tests; rename app in admin
Browse files Browse the repository at this point in the history
  • Loading branch information
XanderVertegaal committed Feb 5, 2024
1 parent c864bf6 commit 689b829
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
15 changes: 12 additions & 3 deletions backend/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pytest
from case_study.models import CaseStudy
from letter.models import Letter
from event.models import EpistolaryEvent, LetterAction, LetterActionCategory
from person.models import Person, PersonDateOfBirth, PersonName
from event.models import EpistolaryEvent, LetterAction, LetterActionCategory, WorldEvent
from person.models import Person


@pytest.fixture()
Expand Down Expand Up @@ -40,7 +40,16 @@ def case_study(db):
@pytest.fixture()
def epistolary_event(db, letter, case_study):
epistolary_event = EpistolaryEvent.objects.create(
name="Test Epistolary event", note="Test note", case_studies=[case_study]
name="Test Epistolary event", note="Test note"
)
epistolary_event.case_studies.add(case_study)

return epistolary_event


@pytest.fixture()
def world_event(db):
world_event = WorldEvent.objects.create(
name="Test World Event", note="Test World Event note", year_exact=612
)
return world_event
2 changes: 1 addition & 1 deletion backend/event/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
class EventConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'event'
verbose_name = 'epistolary episodes and actions'
verbose_name = 'events and actions'
44 changes: 43 additions & 1 deletion backend/event/tests/test_event_models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,46 @@
from event.models import LetterEventDate


def test_letter_action_name(letter, letter_action):
action_str = str(letter_action)

assert str(action_str) == f'writing of {str(letter)}'
assert str(action_str) == f"writing of {str(letter)}"


def test_letter_event_date_with_exact_date(letter_action):
letter_event_date = LetterEventDate.objects.create(
letter_action=letter_action,
year_exact=500,
)
assert (
str(letter_event_date)
== f"writing of {str(letter_action.letters.first())} (500)"
)


def test_letter_event_date_with_date_range(letter_action):
letter_event_date = LetterEventDate.objects.create(
letter_action=letter_action,
year_lower=500,
year_upper=600,
)
assert (
str(letter_event_date)
== f"writing of {str(letter_action.letters.first())} (c. 500–600)"
)


def test_world_event(world_event):
world_event.year_exact = 500
world_event.save()
assert str(world_event) == "Test World Event (500)"


def test_world_event_trigger(world_event, epistolary_event):
world_event.epistolary_events.add(epistolary_event)
world_event.save()

trigger = world_event.epistolary_events.through.objects.first()

assert str(trigger) == "Test World Event (612) triggered Test Epistolary event"

0 comments on commit 689b829

Please sign in to comment.