forked from activist-org/activist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
128 lines (108 loc) · 3.02 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# SPDX-License-Identifier: AGPL-3.0-or-later
"""
Testing for the content app.
"""
# 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
def test_str_methods() -> None:
resource = ResourceFactory.build()
task = TaskFactory.build()
topics = TopicFactory.build()
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}"