Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test the __str__ method of different models in backend/content/models.py and backend/events/models.py🧪 #1170

Merged
merged 2 commits into from
Mar 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 101 additions & 1 deletion backend/content/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,20 @@

# mypy: ignore-errors
import pytest
from uuid import uuid4
from django.utils import timezone

from content.factories import ResourceFactory, TaskFactory, TopicFactory

from content.models import (
Discussion,
Faq,
Image,
Location,
SocialLink,
Tag,
DiscussionEntry
)
from authentication.factories import UserFactory
pytestmark = pytest.mark.django_db


Expand All @@ -19,3 +30,92 @@ def test_str_methods() -> None:
assert str(resource) == resource.name
assert str(task) == task.name
assert str(topics) == topics.name

def test_discussion_str_method():
"""Test the __str__ method of the Discussion model."""
user = UserFactory()
discussion = Discussion(
id=uuid4(),
created_by=user,
title="Test Discussion",
creation_date=timezone.now()
)
assert str(discussion) == f"{discussion.id}"

def test_faq_str_method():
"""Test the __str__ method of the Faq model."""
faq = Faq(
id=uuid4(),
iso="en",
primary=True,
question="Test Question?",
answer="Test Answer",
order=1,
last_updated=timezone.now()
)
assert str(faq) == faq.question

def test_image_str_method():
"""Test the __str__ method of the Image model."""
image_id = uuid4()
image = Image(
id=image_id,
creation_date=timezone.now()
)
assert str(image) == f"{image_id}"

def test_location_str_method():
"""Test the __str__ method of the Location model."""
location_id = uuid4()
location = Location(
id=location_id,
lat="40.7128",
lon="-74.0060",
display_name="New York City"
)
assert str(location) == f"{location_id}"

def test_social_link_str_method():
"""Test the __str__ method of the SocialLink model."""
social_link = SocialLink(
id=uuid4(),
link="https://example.com",
label="Example",
order=1,
creation_date=timezone.now(),
last_updated=timezone.now()
)
assert str(social_link) == social_link.label

def test_tag_str_method():
"""Test the __str__ method of the Tag model."""
tag_id = uuid4()
tag = Tag(
id=tag_id,
text="Test Tag",
description="Test Description",
creation_date=timezone.now()
)
assert str(tag) == f"{tag_id}"

def test_discussion_entry_str_method():
"""Test the __str__ method of the DiscussionEntry model."""
user = UserFactory()
discussion = Discussion(
id=uuid4(),
created_by=user,
title="Test Discussion",
creation_date=timezone.now()
)
discussion.save()

entry_id = uuid4()
entry = DiscussionEntry(
id=entry_id,
discussion=discussion,
created_by=user,
text="Test Entry",
creation_date=timezone.now(),
last_updated=timezone.now()
)
assert str(entry) == f"{entry_id}"
12 changes: 12 additions & 0 deletions backend/events/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
FormatFactory,
RoleFactory,
)
from events.models import EventText

pytestmark = pytest.mark.django_db

Expand All @@ -29,3 +30,14 @@ def test_str_methods() -> None:
assert str(event_attendee_status) == event_attendee_status.status_name
assert str(_format) == _format.name
assert str(role) == role.name

def test_event_text_str_method() -> None:
event = EventFactory.create()
event_text = EventText.objects.create(
event=event,
iso="en",
primary=True,
description="Test description",
get_involved="Get involved text"
)
assert str(event_text) == f"{event_text.event} - {event_text.iso}"
Loading