From b9ae53f16ebae8a0e9f819200d8a3fa8577394a6 Mon Sep 17 00:00:00 2001 From: Oksamies Date: Mon, 11 Dec 2023 16:43:13 +0200 Subject: [PATCH] Add tests for DisbandTeamAPIView --- .../api/cyberstorm/tests/test_team.py | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/django/thunderstore/api/cyberstorm/tests/test_team.py b/django/thunderstore/api/cyberstorm/tests/test_team.py index 0c84b4670..340f69dbd 100644 --- a/django/thunderstore/api/cyberstorm/tests/test_team.py +++ b/django/thunderstore/api/cyberstorm/tests/test_team.py @@ -1,3 +1,5 @@ +import json + import pytest from django.contrib.auth import get_user_model from rest_framework.test import APIClient @@ -223,3 +225,59 @@ def test_team_service_accounts_api_view__for_member__sorts_results( assert result[0]["name"] == alice.first_name assert result[1]["name"] == bob.first_name assert result[2]["name"] == charlie.first_name + + +@pytest.mark.django_db +def test_team_disband__success( + api_client: APIClient, + user: UserType, + team: Team, +): + TeamMemberFactory(team=team, user=user, role="owner") + api_client.force_authenticate(user) + + response = api_client.post( + f"/api/cyberstorm/team/{team.name}/disband/", + json.dumps({"verification": team.name}), + content_type="application/json", + ) + + assert response.status_code == 200 + response_json = response.json() + assert response_json["name"] == team.name + + +@pytest.mark.django_db +def test_team_disband__invalid_verification( + api_client: APIClient, + user: UserType, + team: Team, +): + TeamMemberFactory(team=team, user=user, role="owner") + api_client.force_authenticate(user) + response = api_client.post( + f"/api/cyberstorm/team/{team.name}/disband/", + json.dumps({"verification": "Bad Verification"}), + content_type="application/json", + ) + + assert response.status_code == 400 + response_json = response.json() + assert "Invalid verification" in response_json["verification"] + + +@pytest.mark.django_db +def test_team_disband__team_doesnt_exist( + api_client: APIClient, + user: UserType, +): + api_client.force_authenticate(user) + response = api_client.post( + f"/api/cyberstorm/team/GhostTeam/disband/", + json.dumps({"verification": "GhostTeam"}), + content_type="application/json", + ) + + assert response.status_code == 404 + response_json = response.json() + assert response_json["detail"] == "Not found."