@@ -56,6 +56,69 @@ def test_team_detail_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_edit__when_editing_donation_link__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
+ new_donation_link = "https://example.com"
69
+
70
+ response = api_client .post (
71
+ f"/api/cyberstorm/team/{ team .name } /edit/" ,
72
+ json .dumps ({"donation_link" : new_donation_link }),
73
+ content_type = "application/json" ,
74
+ )
75
+
76
+ assert response .status_code == 200
77
+ response_json = response .json ()
78
+ assert response_json ["donation_link" ] == new_donation_link
79
+ assert Team .objects .get (pk = team .pk ).donation_link == new_donation_link
80
+
81
+
82
+ @pytest .mark .django_db
83
+ def test_team_edit__when_editing_donation_link__fails_because_user_is_not_authenticated (
84
+ api_client : APIClient ,
85
+ team : Team ,
86
+ ):
87
+ new_donation_link = "https://example.com"
88
+
89
+ response = api_client .post (
90
+ f"/api/cyberstorm/team/{ team .name } /edit/" ,
91
+ json .dumps ({"donation_link" : new_donation_link }),
92
+ content_type = "application/json" ,
93
+ )
94
+
95
+ assert response .status_code == 401
96
+ response_json = response .json ()
97
+ assert response_json ["detail" ] == "Authentication credentials were not provided."
98
+
99
+
100
+ @pytest .mark .django_db
101
+ def test_team_edit__when_editing_donation_link__fails_because_serializer_validators_check_fails (
102
+ api_client : APIClient ,
103
+ user : UserType ,
104
+ team : Team ,
105
+ ):
106
+ TeamMemberFactory (team = team , user = user , role = "owner" )
107
+ api_client .force_authenticate (user )
108
+
109
+ new_bad_donation_link = "example.com"
110
+
111
+ response = api_client .post (
112
+ f"/api/cyberstorm/team/{ team .name } /edit/" ,
113
+ json .dumps ({"donation_link" : new_bad_donation_link }),
114
+ content_type = "application/json" ,
115
+ )
116
+
117
+ assert response .status_code == 400
118
+ response_json = response .json ()
119
+ assert "Enter a valid URL." in response_json ["donation_link" ]
120
+
121
+
59
122
@pytest .mark .django_db
60
123
def test_team_membership_permission__for_unauthenticated_user__returns_401 (
61
124
api_client : APIClient ,
0 commit comments