Skip to content

Commit

Permalink
test: Add model str tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marksweb committed Nov 25, 2023
1 parent 5a9c1a0 commit 44a4b34
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 3 deletions.
21 changes: 19 additions & 2 deletions tests/core/test_deploy_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from coach.models import Coach
from core.deploy_event import copy_content_from_previous_event, copy_event, copy_menu_from_previous_event
from core.models import Event
from core.models import Event, EventPageContent, EventPageMenu
from sponsor.models import Sponsor


Expand Down Expand Up @@ -38,7 +38,7 @@ def test_copy_event(past_event):

new_event = copy_event(past_event, new_date)

# we need to refetch the event as we changed id of the object
# we need to re-fetch the event as we changed id of the object
# inside copy_event method
past_event = Event.objects.get(pk=previous_event_id)

Expand All @@ -50,3 +50,20 @@ def test_copy_event(past_event):
assert past_event.country == new_event.country
assert past_event.latlng == new_event.latlng
assert past_event.main_organizer == new_event.main_organizer


def test_eventpagecontent_str(past_event):
event_content = EventPageContent.objects.create(
name="coach",
content="<div><h2>Be a Mentor!</h2></div>",
background="event/backgrounds/photo0_cBUZ8zp.jpg",
is_public=True,
position=40,
event=past_event,
)
assert str(event_content) == f"{event_content.name} at {event_content.event}"


def test_eventpagemenu_str(past_event):
menu = EventPageMenu.objects.create(url="#values", position=1, event=past_event, title="About")
assert str(menu) == f"{menu.title}"
9 changes: 8 additions & 1 deletion tests/organize/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from core.models import Event
from organize.constants import DEPLOYED, ON_HOLD, REJECTED
from organize.models import EventApplication
from organize.models import Coorganizer, EventApplication


def test_comment_required_for_on_hold_application(base_application):
Expand Down Expand Up @@ -119,3 +119,10 @@ def test_previous_application_with_approximate_date(data_dict, previous_applicat
assert EventApplication.object.count() == 1
EventApplication.object.create(**data_dict)
assert EventApplication.object.count() == 2


def test_coorganizer_str(base_application):
org = Coorganizer.objects.create(
event_application=base_application, email="[email protected]", first_name="Anna", last_name="Smith"
)
assert str(org) == f"{org.first_name} {org.last_name} <{org.email}>"
11 changes: 11 additions & 0 deletions tests/patreon/test_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from patreonmanager.models import FundraisingStatus, Payment


def test_payment_str(payment):
payment = Payment.objects.get()
assert str(payment) == f"{payment.patron}, {payment.month}"


def test_fundraisingstatus_str():
status = FundraisingStatus.objects.create(number_of_patrons=1, amount_raised=1)
assert str(status) == f"{status.id} updated {status.date_updated}, raised {status.amount_raised}"
Empty file added tests/sponsor/__init__.py
Empty file.
14 changes: 14 additions & 0 deletions tests/sponsor/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import pytest

from sponsor.models import Donor, Sponsor


@pytest.fixture()
def donor():
donor = Donor.objects.create(name="Ola", amount=50, visible=True)
return donor


@pytest.fixture()
def sponsor():
return Sponsor.objects.create(name="Company name")
6 changes: 6 additions & 0 deletions tests/sponsor/test_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def test_donor(donor):
assert str(donor) == donor.name


def test_sponsor(sponsor):
assert str(sponsor) == sponsor.name

0 comments on commit 44a4b34

Please sign in to comment.