@@ -56,6 +56,79 @@ def test_team_api_view__for_inactive_team__returns_404(
56
56
assert response .status_code == 404
57
57
58
58
59
+ @pytest .mark .django_db
60
+ def test_team_disband__when_disbanding_team__succeeds (
61
+ api_client : APIClient ,
62
+ user : UserType ,
63
+ team : Team ,
64
+ ):
65
+ TeamMemberFactory (team = team , user = user , role = "owner" )
66
+ api_client .force_authenticate (user )
67
+
68
+ response = api_client .post (
69
+ f"/api/cyberstorm/team/{ team .name } /disband/" ,
70
+ json .dumps ({"verification" : team .name }),
71
+ content_type = "application/json" ,
72
+ )
73
+
74
+ assert response .status_code == 200
75
+ response_json = response .json ()
76
+ assert response_json ["name" ] == team .name
77
+
78
+
79
+ @pytest .mark .django_db
80
+ def test_team_disband__when_disbanding_team__fails_because_verification_is_invalid (
81
+ api_client : APIClient ,
82
+ user : UserType ,
83
+ team : Team ,
84
+ ):
85
+ TeamMemberFactory (team = team , user = user , role = "owner" )
86
+ api_client .force_authenticate (user )
87
+ response = api_client .post (
88
+ f"/api/cyberstorm/team/{ team .name } /disband/" ,
89
+ json .dumps ({"verification" : "Bad Verification" }),
90
+ content_type = "application/json" ,
91
+ )
92
+
93
+ assert response .status_code == 400
94
+ response_json = response .json ()
95
+ assert "Invalid verification" in response_json ["verification" ]
96
+
97
+
98
+ @pytest .mark .django_db
99
+ def test_team_disband__when_disbanding_team__fails_because_team_doesnt_exist (
100
+ api_client : APIClient ,
101
+ user : UserType ,
102
+ ):
103
+ api_client .force_authenticate (user )
104
+ response = api_client .post (
105
+ f"/api/cyberstorm/team/GhostTeam/disband/" ,
106
+ json .dumps ({"verification" : "GhostTeam" }),
107
+ content_type = "application/json" ,
108
+ )
109
+
110
+ assert response .status_code == 404
111
+ response_json = response .json ()
112
+ assert response_json ["detail" ] == "Not found."
113
+
114
+
115
+ @pytest .mark .django_db
116
+ def test_team_disband__when_disbanding_team__fails_because_user_is_not_authenticated (
117
+ api_client : APIClient ,
118
+ team : Team ,
119
+ ):
120
+ response = api_client .post (
121
+ f"/api/cyberstorm/team/{ team .name } /disband/" ,
122
+ json .dumps ({"verification" : "Bad Verification" }),
123
+ content_type = "application/json" ,
124
+ )
125
+
126
+ assert response .status_code == 401
127
+ response_json = response .json ()
128
+ assert response_json ["detail" ] == "Authentication credentials were not provided."
129
+ assert Team .objects .filter (name = team .name ).count () == 1
130
+
131
+
59
132
@pytest .mark .django_db
60
133
def test_team_membership_permission__for_unauthenticated_user__returns_401 (
61
134
api_client : APIClient ,
0 commit comments