@@ -56,6 +56,70 @@ 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_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
+ assert Team .objects .get (pk = team .pk ).donation_link == None
99
+
100
+
101
+ @pytest .mark .django_db
102
+ def test_team_edit__when_editing_donation_link__fails_because_serializer_validators_check_fails (
103
+ api_client : APIClient ,
104
+ user : UserType ,
105
+ team : Team ,
106
+ ):
107
+ TeamMemberFactory (team = team , user = user , role = "owner" )
108
+ api_client .force_authenticate (user )
109
+
110
+ new_bad_donation_link = "example.com"
111
+
112
+ response = api_client .post (
113
+ f"/api/cyberstorm/team/{ team .name } /edit/" ,
114
+ json .dumps ({"donation_link" : new_bad_donation_link }),
115
+ content_type = "application/json" ,
116
+ )
117
+
118
+ assert response .status_code == 400
119
+ response_json = response .json ()
120
+ assert "Enter a valid URL." in response_json ["donation_link" ]
121
+
122
+
59
123
@pytest .mark .django_db
60
124
def test_team_membership_permission__for_unauthenticated_user__returns_401 (
61
125
api_client : APIClient ,
0 commit comments