Skip to content

Commit 9707316

Browse files
committed
Add tests to EditTeamAPIView
1 parent a6a528a commit 9707316

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

django/thunderstore/api/cyberstorm/tests/test_team.py

+61
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import json
2+
13
import pytest
24
from django.contrib.auth import get_user_model
35
from rest_framework.test import APIClient
@@ -223,3 +225,62 @@ def test_team_service_accounts_api_view__for_member__sorts_results(
223225
assert result[0]["name"] == alice.first_name
224226
assert result[1]["name"] == bob.first_name
225227
assert result[2]["name"] == charlie.first_name
228+
229+
230+
@pytest.mark.django_db
231+
def test_team_edit__when_editing_donation_link__succeeds(
232+
api_client: APIClient,
233+
user: UserType,
234+
team: Team,
235+
):
236+
TeamMemberFactory(team=team, user=user, role="owner")
237+
api_client.force_authenticate(user)
238+
239+
new_donation_link = "https://example.com"
240+
241+
response = api_client.post(
242+
f"/api/cyberstorm/team/{team.name}/edit/",
243+
json.dumps({"donation_link": new_donation_link}),
244+
content_type="application/json",
245+
)
246+
247+
assert response.status_code == 200
248+
response_json = response.json()
249+
assert response_json["donation_link"] == new_donation_link
250+
assert Team.objects.get(pk=team.pk).donation_link == new_donation_link
251+
252+
253+
@pytest.mark.django_db
254+
def test_team_edit__when_editing_donation_link__fails_because_user_is_not_authenticated(
255+
api_client: APIClient,
256+
team: Team,
257+
):
258+
new_donation_link = "https://example.com"
259+
260+
response = api_client.post(
261+
f"/api/cyberstorm/team/{team.name}/edit/",
262+
json.dumps({"donation_link": new_donation_link}),
263+
content_type="application/json",
264+
)
265+
266+
assert response.status_code == 400
267+
response_json = response.json()
268+
assert "Must be authenticated" in response_json["__all__"]
269+
270+
271+
@pytest.mark.django_db
272+
def test_team_edit__when_editing_donation_link__fails_because_serializer_validators_check_fails(
273+
api_client: APIClient,
274+
team: Team,
275+
):
276+
new_bad_donation_link = "example.com"
277+
278+
response = api_client.post(
279+
f"/api/cyberstorm/team/{team.name}/edit/",
280+
json.dumps({"donation_link": new_bad_donation_link}),
281+
content_type="application/json",
282+
)
283+
284+
assert response.status_code == 400
285+
response_json = response.json()
286+
assert "Enter a valid URL." in response_json["donation_link"]

0 commit comments

Comments
 (0)