-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #852 from thunderstore-io/cb-team
Add CS team endpoint
- Loading branch information
Showing
7 changed files
with
84 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
from .community import CyberstormCommunitySerializer | ||
from .team import CyberstormTeamMemberSerializer, CyberstormTeamSerializer | ||
from .user import CyberstormUserSerializer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from rest_framework import serializers | ||
|
||
from .user import CyberstormUserSerializer | ||
|
||
|
||
class CyberstormTeamMemberSerializer(serializers.Serializer): | ||
user = CyberstormUserSerializer() | ||
role = serializers.CharField() | ||
|
||
|
||
class CyberstormTeamSerializer(serializers.Serializer): | ||
identifier = serializers.CharField(source="id") | ||
name = serializers.CharField() | ||
members = CyberstormTeamMemberSerializer(many=True) | ||
donation_link = serializers.CharField(required=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from rest_framework import serializers | ||
|
||
|
||
class CyberstormUserSerializer(serializers.Serializer): | ||
identifier = serializers.CharField(source="id") | ||
username = serializers.CharField() |
42 changes: 42 additions & 0 deletions
42
django/thunderstore/api/cyberstorm/tests/test_team_detail.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import pytest | ||
from rest_framework.test import APIClient | ||
|
||
from thunderstore.community.models import CommunitySite | ||
from thunderstore.repository.models.team import Team, TeamMember | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_api_cyberstorm_team_detail_success( | ||
client: APIClient, | ||
community_site: CommunitySite, | ||
team: Team, | ||
team_member: TeamMember, | ||
): | ||
response = client.get( | ||
f"/api/cyberstorm/team/{team.name}/", | ||
HTTP_HOST=community_site.site.domain, | ||
) | ||
result = response.json() | ||
assert response.status_code == 200 | ||
assert team.name == result["name"] | ||
assert team.donation_link == result["donation_link"] | ||
|
||
members = team.members.all() | ||
assert len(members) == 1 | ||
assert len(members) == len(result["members"]) | ||
|
||
member = members.first() | ||
assert result["members"][0]["role"] == member.role | ||
assert result["members"][0]["user"]["identifier"] == str(member.user.pk) | ||
assert result["members"][0]["user"]["username"] == member.user.username | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_api_cyberstorm_team_detail_failure( | ||
client: APIClient, community_site: CommunitySite | ||
): | ||
response = client.get( | ||
f"/api/cyberstorm/team/bad/", | ||
HTTP_HOST=community_site.site.domain, | ||
) | ||
assert response.status_code == 404 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,3 @@ | ||
from .community_detail import CommunityDetailAPIView | ||
from .community_list import CommunityListAPIView | ||
|
||
__all__ = [ | ||
"CommunityDetailAPIView", | ||
"CommunityListAPIView", | ||
] | ||
from .team_detail import TeamDetailAPIView |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from rest_framework.generics import RetrieveAPIView | ||
|
||
from thunderstore.api.cyberstorm.serializers import CyberstormTeamSerializer | ||
from thunderstore.repository.models.team import Team | ||
|
||
|
||
class TeamDetailAPIView(RetrieveAPIView): | ||
permission_classes = [] | ||
serializer_class = CyberstormTeamSerializer | ||
queryset = Team.objects.exclude(is_active=False).prefetch_related("members") | ||
lookup_field = "name" | ||
lookup_url_kwarg = "team_id" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters