@@ -318,3 +318,63 @@ def test_team_member_add_api_view__when_adding_a_member__fails_because_user_is_n
318
318
.count ()
319
319
== 0
320
320
)
321
+
322
+
323
+ @pytest .mark .django_db
324
+ def test_team_create__when_creating_a_team__succeeds (
325
+ api_client : APIClient ,
326
+ user : UserType ,
327
+ ):
328
+ api_client .force_authenticate (user )
329
+
330
+ response = api_client .post (
331
+ "/api/cyberstorm/teams/create/" ,
332
+ json .dumps ({"name" : "CoolestTeamNameEver" }),
333
+ content_type = "application/json" ,
334
+ )
335
+
336
+ assert response .status_code == 200
337
+ response_json = response .json ()
338
+ assert response_json ["name" ] == "CoolestTeamNameEver"
339
+ assert (
340
+ Team .objects .get (name = "CoolestTeamNameEver" )
341
+ .members .filter (user__username = user .username )
342
+ .count ()
343
+ == 1
344
+ )
345
+
346
+
347
+ @pytest .mark .django_db
348
+ def test_team_create__when_creating_a_team__fails_because_user_is_not_authenticated (
349
+ api_client : APIClient ,
350
+ user : UserType ,
351
+ ):
352
+ response = api_client .post (
353
+ "/api/cyberstorm/teams/create/" ,
354
+ json .dumps ({"name" : "CoolestTeamNameEver" }),
355
+ content_type = "application/json" ,
356
+ )
357
+
358
+ assert response .status_code == 401
359
+ response_json = response .json ()
360
+ assert response_json ["detail" ] == "Authentication credentials were not provided."
361
+ assert Team .objects .filter (name = "CoolestTeamNameEver" ).count () == 0
362
+
363
+
364
+ @pytest .mark .django_db
365
+ def test_team_create__when_creating_a_team__fails_because_team_with_provided_name_exists (
366
+ api_client : APIClient ,
367
+ user : UserType ,
368
+ team : Team ,
369
+ ):
370
+ api_client .force_authenticate (user )
371
+
372
+ response = api_client .post (
373
+ "/api/cyberstorm/teams/create/" ,
374
+ json .dumps ({"name" : team .name }),
375
+ content_type = "application/json" ,
376
+ )
377
+
378
+ assert response .status_code == 400
379
+ response_json = response .json ()
380
+ assert "A team with the provided name already exists" in response_json ["name" ]
0 commit comments