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

Missing test for deleting authenticated users #1168

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
25 changes: 25 additions & 0 deletions backend/authentication/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ def test_pwreset(client: Client) -> None:
)
assert response.status_code == 404


def test_create_user_and_superuser():
"""
Test create_user and create_superuser methods of the CustomAccountManager.
Expand Down Expand Up @@ -297,3 +298,27 @@ def test_create_user_and_superuser():
password="AdminPassword123$",
is_superuser=False,
)


def test_delete_user(client: Client) -> None:
"""
Test the deletion of existing user records from the database.
"""
test_username = "test_user_123"
test_pass = "Activist@123!?"
user = UserFactory(username=test_username, plaintext_password=test_pass)
user.is_confirmed = True
user.save()

response = client.post(
path="/v1/auth/sign_in/",
data={"username": user.username, "password": user.password},
)

if response.status_code == 200:
delete_response = client.delete(
path="/v1/auth/delete/",
data={"pk": user.id}
)

assert delete_response.status_code == 200
12 changes: 9 additions & 3 deletions backend/communities/groups/tests/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@


def test_group_creation() -> None:
"""Test complete group creation with all fields."""
"""
Test complete group creation with all fields.
"""
user = UserFactory()
org = OrganizationFactory(created_by=user)
location = EntityLocationFactory()
Expand All @@ -47,7 +49,9 @@ def test_group_creation() -> None:


def test_url_validations() -> None:
"""Test that get_involved_url field is a valid URL."""
"""
Test that get_involved_url field is a valid URL.
"""
user = UserFactory()
org = OrganizationFactory(created_by=user)
location = EntityLocationFactory()
Expand Down Expand Up @@ -84,7 +88,9 @@ def test_url_validations() -> None:


def test_multiple_groups_per_org() -> None:
"""Test that multiple groups can be created per organization."""
"""
Test that multiple groups can be created per organization.
"""
user = UserFactory()
org = OrganizationFactory(created_by=user)
location = EntityLocationFactory()
Expand Down
4 changes: 3 additions & 1 deletion backend/communities/groups/tests/test_group_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@


def test_multiple_events_per_group() -> None:
"""Test multiple events for a single group."""
"""
Test multiple events for a single group.
"""
group = GroupFactory.create()
events = EventFactory.create_batch(3)

Expand Down
4 changes: 3 additions & 1 deletion backend/communities/groups/tests/test_group_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@


def test_group_image_str() -> None:
"""Test string representation of GroupImage model."""
"""
Test string representation of GroupImage model.
"""
group = GroupFactory()
image = ImageFactory()
group_image = GroupImageFactory(group=group, image=image, sequence_index=1)
Expand Down
12 changes: 9 additions & 3 deletions backend/communities/groups/tests/test_group_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@


def test_group_member_str() -> None:
"""Test string representation of GroupMember model."""
"""
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."""
"""
Test the different roles a group member can have.
"""
user = UserFactory()
group = GroupFactory()

Expand Down Expand Up @@ -50,7 +54,9 @@ def test_group_member_roles() -> None:


def test_multiple_members_per_group() -> None:
"""Test multiple members in a single group."""
"""
Test multiple members in a single group.
"""
group = GroupFactory()
members = [GroupMemberFactory(group=group) for _ in range(3)]

Expand Down
8 changes: 6 additions & 2 deletions backend/communities/groups/tests/test_group_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@


def test_group_resource_creation() -> None:
"""Test creating a GroupResource instance."""
"""
Test creating a GroupResource instance.
"""
group = GroupFactory()
resource = ResourceFactory()

Expand All @@ -24,7 +26,9 @@ def test_group_resource_creation() -> None:


def test_multiple_resources_per_group() -> None:
"""Test multiple resources for a single group."""
"""
Test multiple resources for a single group.
"""
group = GroupFactory()
resources = ResourceFactory.create_batch(3)

Expand Down
12 changes: 9 additions & 3 deletions backend/communities/groups/tests/test_group_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@


def test_group_text_str() -> None:
"""Test string representation of GroupText model."""
"""
Test string representation of GroupText model.
"""
group_text = GroupTextFactory.build()
assert hasattr(group_text, "description")


def test_group_text_languages() -> None:
"""Test group text with different ISO languages."""
"""
Test group text with different ISO languages.
"""
group = GroupFactory()

# 1. Test primary language text.
Expand Down Expand Up @@ -48,7 +52,9 @@ def test_group_text_languages() -> None:


def test_group_text_str_representation() -> None:
"""Test string representation of GroupText model."""
"""
Test string representation of GroupText model.
"""
group = GroupFactory()
group_text = GroupTextFactory(group=group, iso="eng")

Expand Down
8 changes: 6 additions & 2 deletions backend/communities/groups/tests/test_group_topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@


def test_group_topic_creation() -> None:
"""Test creating a GroupTopic instance."""
"""
Test creating a GroupTopic instance.
"""
group = GroupFactory()
topic = TopicFactory()

Expand All @@ -24,7 +26,9 @@ def test_group_topic_creation() -> None:


def test_multiple_topics_per_group() -> None:
"""Test multiple topics for a single group."""
"""
Test multiple topics for a single group.
"""
group = GroupFactory()
topics = TopicFactory.create_batch(3)

Expand Down
4 changes: 3 additions & 1 deletion backend/communities/organizations/tests/test_org_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@


def test_multiple_events_per_org() -> None:
"""Test multiple events for a single organization."""
"""
Test multiple events for a single organization.
"""
org = OrganizationFactory.create()
events = EventFactory.create_batch(3)

Expand Down
12 changes: 9 additions & 3 deletions backend/communities/organizations/tests/test_org_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@


def test_org_member_str() -> None:
"""Test string representation of OrganizationMember model."""
"""
Test string representation of OrganizationMember model.
"""
org_member = OrganizationMemberFactory.build()
assert str(org_member) == f"{org_member.id}"


def test_org_member_roles() -> None:
"""Test the different roles an organization member can have."""
"""
Test the different roles an organization member can have.
"""
user = UserFactory()
org = OrganizationFactory()

Expand Down Expand Up @@ -53,7 +57,9 @@ def test_org_member_roles() -> None:


def test_multiple_members_per_org() -> None:
"""Test multiple members in a single organization."""
"""
Test multiple members in a single organization.
"""
org = OrganizationFactory()
members = [OrganizationMemberFactory(org=org) for _ in range(3)]

Expand Down
8 changes: 6 additions & 2 deletions backend/communities/organizations/tests/test_org_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@


def test_org_resource_creation() -> None:
"""Test creating a OrganizationResource instance."""
"""
Test creating a OrganizationResource instance.
"""
org = OrganizationFactory()
resource = ResourceFactory()

Expand All @@ -24,7 +26,9 @@ def test_org_resource_creation() -> None:


def test_multiple_resources_per_org() -> None:
"""Test multiple resources for a single organization."""
"""
Test multiple resources for a single organization.
"""
org = OrganizationFactory()
resources = ResourceFactory.create_batch(3)

Expand Down
8 changes: 6 additions & 2 deletions backend/communities/organizations/tests/test_org_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@


def test_org_text_str() -> None:
"""Test string representation of OrganizationText model."""
"""
Test string representation of OrganizationText model.
"""
org_text = OrganizationTextFactory.build()
assert hasattr(org_text, "description")


def test_org_text_languages() -> None:
"""Test organization text with different ISO languages."""
"""
Test organization text with different ISO languages.
"""
org = OrganizationFactory()

# 1. Test primary language text.
Expand Down
8 changes: 6 additions & 2 deletions backend/communities/organizations/tests/test_org_topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@


def test_org_topic_creation() -> None:
"""Test creating a OrganizationTopic instance."""
"""
Test creating a OrganizationTopic instance.
"""
org = OrganizationFactory()
topic = TopicFactory()

Expand All @@ -24,7 +26,9 @@ def test_org_topic_creation() -> None:


def test_multiple_topics_per_org() -> None:
"""Test multiple topics for a single organization."""
"""
Test multiple topics for a single organization.
"""
org = OrganizationFactory()
topics = TopicFactory.create_batch(3)

Expand Down
8 changes: 6 additions & 2 deletions backend/communities/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@


def test_str_methods() -> None:
"""Test the __str__ methods of the communities."""
"""
Test the __str__ methods of the communities.
"""
organization = OrganizationFactory.create()
# Note: Needs to be updated to reflect the recent changes.
# organization_application = OrganizationApplicationFactory.create()
Expand All @@ -39,7 +41,9 @@ def test_str_methods() -> None:
assert str(group_member) == str(group_member.id)

def test_status_and_status_type_str_methods() -> None:
"""Test the __str__ methods of the Status and StatusType models."""
"""
Test the __str__ methods of the Status and StatusType models.
"""

status_type = StatusType.objects.create(name="Active")

Expand Down
Loading