-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/modal-share-page
- Loading branch information
Showing
33 changed files
with
540 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"eslint.validate": ["javascript", "typescript", "vue"], | ||
"eslint.useFlatConfig": true, | ||
"typescript.tsdk": "./frontend/node_modules/typescript/lib" | ||
"typescript.tsdk": "./frontend/node_modules/typescript/lib", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
""" | ||
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 content.factories import EntityLocationFactory | ||
from entities.factories import OrganizationFactory | ||
from entities.models import Group | ||
|
||
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_id=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_id == 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_id=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_id=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_id=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_id=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_id == org | ||
assert group2.org_id == org | ||
|
||
org_groups = Group.objects.filter(org_id=org) | ||
assert group1 in org_groups | ||
assert group2 in org_groups |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
""" | ||
Test cases for the GroupEvents entity. | ||
""" | ||
|
||
import pytest | ||
|
||
from entities.factories import GroupEventFactory, GroupFactory | ||
|
||
pytestmark = pytest.mark.django_db | ||
|
||
|
||
def test_group_event_str() -> None: | ||
"""Test string representation of GroupEvent model.""" | ||
group_event = GroupEventFactory.build() | ||
assert str(group_event) == f"{group_event.id}" | ||
|
||
|
||
def test_multiple_events_per_group() -> None: | ||
"""Test multiple events for a single group.""" | ||
group = GroupFactory() | ||
events = [GroupEventFactory(group_id=group) for _ in range(3)] | ||
|
||
assert len(events) == 3 | ||
for event in events: | ||
assert event.group_id == group |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
""" | ||
Test cases for the GroupMember model. | ||
""" | ||
|
||
import pytest | ||
|
||
from authentication.factories import UserFactory | ||
from entities.factories import GroupFactory, GroupMemberFactory | ||
|
||
pytestmark = pytest.mark.django_db | ||
|
||
|
||
def test_group_member_str() -> None: | ||
"""Test string representation of GroupMember model.""" | ||
group_member = GroupMemberFactory.build() | ||
assert str(group_member) == f"{group_member.id}" | ||
|
||
|
||
def test_group_member_roles() -> None: | ||
"""Test the different roles a group member can have.""" | ||
user = UserFactory() | ||
group = GroupFactory() | ||
|
||
# 1. Test owner role. | ||
owner = GroupMemberFactory( | ||
group_id=group, user_id=user, is_owner=True, is_admin=False, is_comms=False | ||
) | ||
assert owner.is_owner is True | ||
assert owner.is_admin is False | ||
assert owner.is_comms is False | ||
|
||
# 2. Test admin role. | ||
admin = GroupMemberFactory( | ||
group_id=group, user_id=user, is_owner=False, is_admin=True, is_comms=False | ||
) | ||
assert admin.is_owner is False | ||
assert admin.is_admin is True | ||
assert admin.is_comms is False | ||
|
||
# 3. Test comms role. | ||
comms = GroupMemberFactory( | ||
group_id=group, user_id=user, is_owner=False, is_admin=False, is_comms=True | ||
) | ||
assert comms.is_owner is False | ||
assert comms.is_admin is False | ||
assert comms.is_comms is True | ||
|
||
|
||
def test_multiple_members_per_group() -> None: | ||
"""Test multiple members in a single group.""" | ||
group = GroupFactory() | ||
members = [GroupMemberFactory(group_id=group) for _ in range(3)] | ||
|
||
assert len(members) == 3 | ||
|
||
for member in members: | ||
assert member.group_id == group |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
""" | ||
Test cases for GroupResource model. | ||
""" | ||
|
||
import pytest | ||
|
||
from entities.factories import GroupFactory, GroupResourceFactory | ||
from entities.models import GroupResource | ||
|
||
pytestmark = pytest.mark.django_db | ||
|
||
|
||
def test_group_resource_str() -> None: | ||
"""Test string representation of GroupResource model.""" | ||
group_resource = GroupResourceFactory.build() | ||
assert str(group_resource) == f"{group_resource.id}" | ||
|
||
|
||
def test_group_resource_creation() -> None: | ||
"""Test creating a GroupResource instance.""" | ||
group = GroupFactory() | ||
resource = GroupResourceFactory(group_id=group) | ||
|
||
assert isinstance(resource, GroupResource) | ||
assert resource.group_id == group | ||
|
||
|
||
def test_multiple_resources_per_group() -> None: | ||
"""Test multiple resources for a single group.""" | ||
group = GroupFactory() | ||
resources = [GroupResourceFactory(group_id=group) for _ in range(3)] | ||
|
||
assert len(resources) == 3 | ||
for resource in resources: | ||
assert resource.group_id == group | ||
|
||
|
||
def test_group_resource_deletion() -> None: | ||
"""Test cascade deletion when group is deleted.""" | ||
group = GroupFactory() | ||
resource = GroupResourceFactory(group_id=group) | ||
|
||
# Store resource ID for later verification. | ||
resource_id = resource.id | ||
|
||
# Delete the group. | ||
group.delete() | ||
|
||
# Verify resource is also deleted. | ||
assert not GroupResource.objects.filter(id=resource_id).exists() |
Oops, something went wrong.