Skip to content

Commit

Permalink
Add tests for TeamCreateAPIView
Browse files Browse the repository at this point in the history
  • Loading branch information
Oksamies committed Dec 13, 2023
1 parent e8ddb16 commit dc888b8
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions django/thunderstore/api/cyberstorm/tests/test_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,45 @@ def test_team_add_member__when_adding_a_member__fails_because_user_is_already_in
"Team Member with this User and Team already exists."
in response2.json()["__all__"]
)


@pytest.mark.django_db
def test_team_create__when_creating_a_team__succeeds(
api_client: APIClient,
user: UserType,
):
api_client.force_authenticate(user)

response = api_client.post(
"/api/cyberstorm/teams/create/",
json.dumps({"name": "CoolestTeamNameEver"}),
content_type="application/json",
)

assert response.status_code == 200
response_json = response.json()
assert response_json["name"] == "CoolestTeamNameEver"
assert len(
Team.objects.get(name="CoolestTeamNameEver").members.filter(
user__username=user.username
)
)


@pytest.mark.django_db
def test_team_create__when_creating_a_team__fails_because_team_with_provided_name_exists(
api_client: APIClient,
user: UserType,
team: Team,
):
api_client.force_authenticate(user)

response = api_client.post(
"/api/cyberstorm/teams/create/",
json.dumps({"name": team.name}),
content_type="application/json",
)

assert response.status_code == 400
response_json = response.json()
assert "A team with the provided name already exists" in response_json["name"]

0 comments on commit dc888b8

Please sign in to comment.