Skip to content

Commit

Permalink
tests for only fields in api
Browse files Browse the repository at this point in the history
  • Loading branch information
regiscamimura committed Aug 2, 2023
1 parent 26bc460 commit 7840552
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ def test_profile_detail(client, db, profile, user):
assert result["username"] == user.username


def test_profile_detail_trimmed(client, db, profile, user):
response = client.get(f"/profiles/trimmed/{profile.pk}/")
result = response.json()
assert response.status_code == 200, result
assert "username" not in result
assert result["user"]["id"] == user.id


def test_profile_detail_no_id(client, db, profile, user):
response = client.get(f"/profiles/no-id/{profile.pk}/")
result = response.json()
assert response.status_code == 200, result
assert "id" not in result["user"]


def test_profile_not_found(client, db, profile, user):
response = client.get(f"/profiles/{uuid4()}/")
result = response.json()
Expand Down
2 changes: 2 additions & 0 deletions tests/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
urlpatterns = [
path("profiles/", views.ProfileList.as_view()),
path("profiles/<uuid:id>/", views.ProfileDetail.as_view()),
path("profiles/trimmed/<uuid:id>/", views.ProfileDetailTrimmed.as_view()),
path("profiles/no-id/<uuid:id>/", views.ProfileDetailNoID.as_view()),
path("profiles/<uuid:id>/<str:action>/", views.ProfileDetail.as_view()),
path("staff/<uuid:id>/", views.StaffDetail.as_view()),
path("user/", views.UserSelf.as_view()),
Expand Down
12 changes: 12 additions & 0 deletions tests/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ def validate_phone(self, value):
return "+5555555555"


class ProfileDetailTrimmed(ActionAPI, DeleteAPI, UpdateAPI, DetailAPI):
model = Profile
serializer = ProfileSerializer(only=["user.id"])
permissions = [PublicEndpoint]


class ProfileDetailNoID(ActionAPI, DeleteAPI, UpdateAPI, DetailAPI):
model = Profile
serializer = ProfileSerializer(exclude=["user.id"])
permissions = [PublicEndpoint]


class StaffDetail(ProfileDetail):
permissions = [Authenticated, Staff]

Expand Down

0 comments on commit 7840552

Please sign in to comment.