👔(backend) add read fields to teams api
Some fields are missing for the frontend. Add read fields to teams api: - created_at - updated_at
This commit is contained in:
@@ -129,8 +129,23 @@ class TeamSerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.Team
|
model = models.Team
|
||||||
fields = ["id", "name", "accesses", "abilities", "slug"]
|
fields = [
|
||||||
read_only_fields = ["id", "accesses", "abilities", "slug"]
|
"id",
|
||||||
|
"name",
|
||||||
|
"accesses",
|
||||||
|
"abilities",
|
||||||
|
"slug",
|
||||||
|
"created_at",
|
||||||
|
"updated_at",
|
||||||
|
]
|
||||||
|
read_only_fields = [
|
||||||
|
"id",
|
||||||
|
"accesses",
|
||||||
|
"abilities",
|
||||||
|
"slug",
|
||||||
|
"created_at",
|
||||||
|
"updated_at",
|
||||||
|
]
|
||||||
|
|
||||||
def get_abilities(self, team) -> dict:
|
def get_abilities(self, team) -> dict:
|
||||||
"""Return abilities of the logged-in user on the instance."""
|
"""Return abilities of the logged-in user on the instance."""
|
||||||
|
|||||||
@@ -26,8 +26,10 @@ def test_api_teams_list_anonymous():
|
|||||||
|
|
||||||
|
|
||||||
def test_api_teams_list_authenticated():
|
def test_api_teams_list_authenticated():
|
||||||
"""Authenticated users should be able to list teams
|
"""
|
||||||
they arean owner/administrator/member of."""
|
Authenticated users should be able to list teams
|
||||||
|
they are an owner/administrator/member of.
|
||||||
|
"""
|
||||||
identity = factories.IdentityFactory()
|
identity = factories.IdentityFactory()
|
||||||
user = identity.user
|
user = identity.user
|
||||||
|
|
||||||
|
|||||||
@@ -82,4 +82,6 @@ def test_api_teams_retrieve_authenticated_related():
|
|||||||
"name": team.name,
|
"name": team.name,
|
||||||
"slug": team.slug,
|
"slug": team.slug,
|
||||||
"abilities": team.get_abilities(user),
|
"abilities": team.get_abilities(user),
|
||||||
|
"created_at": team.created_at.isoformat().replace("+00:00", "Z"),
|
||||||
|
"updated_at": team.updated_at.isoformat().replace("+00:00", "Z"),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,8 +121,10 @@ def test_api_teams_update_authenticated_administrators():
|
|||||||
team.refresh_from_db()
|
team.refresh_from_db()
|
||||||
final_values = serializers.TeamSerializer(instance=team).data
|
final_values = serializers.TeamSerializer(instance=team).data
|
||||||
for key, value in final_values.items():
|
for key, value in final_values.items():
|
||||||
if key in ["id", "accesses"]: # pylint: disable=R1733
|
if key in ["id", "accesses", "created_at"]:
|
||||||
assert value == initial_values[key]
|
assert value == initial_values[key]
|
||||||
|
elif key == "updated_at":
|
||||||
|
assert value > initial_values[key]
|
||||||
else:
|
else:
|
||||||
# name, slug and abilities successfully modified
|
# name, slug and abilities successfully modified
|
||||||
assert value == new_values[key]
|
assert value == new_values[key]
|
||||||
@@ -153,8 +155,10 @@ def test_api_teams_update_authenticated_owners():
|
|||||||
team.refresh_from_db()
|
team.refresh_from_db()
|
||||||
team_values = serializers.TeamSerializer(instance=team).data
|
team_values = serializers.TeamSerializer(instance=team).data
|
||||||
for key, value in team_values.items():
|
for key, value in team_values.items():
|
||||||
if key in ["id", "accesses"]:
|
if key in ["id", "accesses", "created_at"]:
|
||||||
assert value == old_team_values[key]
|
assert value == old_team_values[key]
|
||||||
|
elif key == "updated_at":
|
||||||
|
assert value > old_team_values[key]
|
||||||
else:
|
else:
|
||||||
# name, slug and abilities successfully modified
|
# name, slug and abilities successfully modified
|
||||||
assert value == new_team_values[key]
|
assert value == new_team_values[key]
|
||||||
|
|||||||
Reference in New Issue
Block a user