forked from activist-org/activist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_group.py
127 lines (107 loc) · 3.15 KB
/
test_group.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
# SPDX-License-Identifier: AGPL-3.0-or-later
"""
Testing for the Group model.
"""
# mypy: ignore-errors
from datetime import datetime
from uuid import UUID
import pytest
from django.core.exceptions import ValidationError
from faker import Faker
from authentication.factories import UserFactory
from communities.groups.models import Group
from communities.organizations.factories import OrganizationFactory
from content.factories import EntityLocationFactory
pytestmark = pytest.mark.django_db
def test_group_creation() -> None:
"""
Test complete group creation with all fields.
"""
user = UserFactory()
org = OrganizationFactory(created_by=user)
location = EntityLocationFactory()
fake = Faker()
group = Group.objects.create(
org=org,
created_by=user,
group_name=fake.company(),
name=fake.company(),
tagline=fake.catch_phrase(),
location=location,
category=fake.word(),
get_involved_url=fake.url(),
terms_checked=True,
)
assert isinstance(group.id, UUID)
assert group.org == org
assert group.created_by == user
assert isinstance(group.group_name, str)
assert isinstance(group.creation_date, datetime)
assert group.terms_checked is True
def test_url_validations() -> None:
"""
Test that get_involved_url field is a valid URL.
"""
user = UserFactory()
org = OrganizationFactory(created_by=user)
location = EntityLocationFactory()
fake = Faker()
# 1. Test invalid URL.
with pytest.raises(ValidationError):
group = Group(
org=org,
created_by=user,
group_name=fake.company(),
name=fake.company(),
location=location,
category=fake.word(),
get_involved_url="not a url",
terms_checked=True,
)
group.full_clean()
# 2. Test valid URL.
group = Group.objects.create(
org=org,
created_by=user,
group_name=fake.company(),
name=fake.company(),
location=location,
category=fake.word(),
get_involved_url=fake.url(),
terms_checked=True,
)
group.full_clean()
def test_multiple_groups_per_org() -> None:
"""
Test that multiple groups can be created per organization.
"""
user = UserFactory()
org = OrganizationFactory(created_by=user)
location = EntityLocationFactory()
fake = Faker()
group1 = Group.objects.create(
org=org,
created_by=user,
group_name=fake.company(),
name=fake.company(),
location=location,
category=fake.word(),
get_involved_url=fake.url(),
terms_checked=True,
)
group2 = Group.objects.create(
org=org,
created_by=user,
group_name=fake.company(),
name=fake.company(),
location=location,
category=fake.word(),
get_involved_url=fake.url(),
terms_checked=True,
)
assert Group.objects.count() == 2
assert group1.org == org
assert group2.org == org
org_groups = Group.objects.filter(org=org)
assert group1 in org_groups
assert group2 in org_groups