♻️(backend) add more info to doc
Update the serializer to include more info about the doc: - created date - updated date
This commit is contained in:
@@ -139,8 +139,17 @@ class DocumentSerializer(BaseResourceSerializer):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.Document
|
model = models.Document
|
||||||
fields = ["id", "content", "title", "accesses", "abilities", "is_public"]
|
fields = [
|
||||||
read_only_fields = ["id", "accesses", "abilities"]
|
"id",
|
||||||
|
"content",
|
||||||
|
"title",
|
||||||
|
"accesses",
|
||||||
|
"abilities",
|
||||||
|
"is_public",
|
||||||
|
"created_at",
|
||||||
|
"updated_at",
|
||||||
|
]
|
||||||
|
read_only_fields = ["id", "accesses", "abilities", "created_at", "updated_at"]
|
||||||
|
|
||||||
|
|
||||||
class TemplateSerializer(BaseResourceSerializer):
|
class TemplateSerializer(BaseResourceSerializer):
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ def test_api_documents_retrieve_anonymous_public():
|
|||||||
"title": document.title,
|
"title": document.title,
|
||||||
"is_public": True,
|
"is_public": True,
|
||||||
"content": document.content,
|
"content": document.content,
|
||||||
|
"created_at": document.created_at.isoformat().replace("+00:00", "Z"),
|
||||||
|
"updated_at": document.updated_at.isoformat().replace("+00:00", "Z"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -78,6 +80,8 @@ def test_api_documents_retrieve_authenticated_unrelated_public():
|
|||||||
"title": document.title,
|
"title": document.title,
|
||||||
"is_public": True,
|
"is_public": True,
|
||||||
"content": document.content,
|
"content": document.content,
|
||||||
|
"created_at": document.created_at.isoformat().replace("+00:00", "Z"),
|
||||||
|
"updated_at": document.updated_at.isoformat().replace("+00:00", "Z"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -146,6 +150,8 @@ def test_api_documents_retrieve_authenticated_related_direct():
|
|||||||
"content": document.content,
|
"content": document.content,
|
||||||
"abilities": document.get_abilities(user),
|
"abilities": document.get_abilities(user),
|
||||||
"is_public": document.is_public,
|
"is_public": document.is_public,
|
||||||
|
"created_at": document.created_at.isoformat().replace("+00:00", "Z"),
|
||||||
|
"updated_at": document.updated_at.isoformat().replace("+00:00", "Z"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -277,6 +283,8 @@ def test_api_documents_retrieve_authenticated_related_team_members(
|
|||||||
"content": document.content,
|
"content": document.content,
|
||||||
"abilities": document.get_abilities(user),
|
"abilities": document.get_abilities(user),
|
||||||
"is_public": False,
|
"is_public": False,
|
||||||
|
"created_at": document.created_at.isoformat().replace("+00:00", "Z"),
|
||||||
|
"updated_at": document.updated_at.isoformat().replace("+00:00", "Z"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -394,6 +402,8 @@ def test_api_documents_retrieve_authenticated_related_team_administrators(
|
|||||||
"content": document.content,
|
"content": document.content,
|
||||||
"abilities": document.get_abilities(user),
|
"abilities": document.get_abilities(user),
|
||||||
"is_public": False,
|
"is_public": False,
|
||||||
|
"created_at": document.created_at.isoformat().replace("+00:00", "Z"),
|
||||||
|
"updated_at": document.updated_at.isoformat().replace("+00:00", "Z"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -515,4 +525,6 @@ def test_api_documents_retrieve_authenticated_related_team_owners(
|
|||||||
"content": document.content,
|
"content": document.content,
|
||||||
"abilities": document.get_abilities(user),
|
"abilities": document.get_abilities(user),
|
||||||
"is_public": False,
|
"is_public": False,
|
||||||
|
"created_at": document.created_at.isoformat().replace("+00:00", "Z"),
|
||||||
|
"updated_at": document.updated_at.isoformat().replace("+00:00", "Z"),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,8 +141,10 @@ def test_api_documents_update_authenticated_editor_administrator_or_owner(
|
|||||||
document = models.Document.objects.get(pk=document.pk)
|
document = models.Document.objects.get(pk=document.pk)
|
||||||
document_values = serializers.DocumentSerializer(instance=document).data
|
document_values = serializers.DocumentSerializer(instance=document).data
|
||||||
for key, value in document_values.items():
|
for key, value in document_values.items():
|
||||||
if key in ["id", "accesses"]:
|
if key in ["id", "accesses", "created_at"]:
|
||||||
assert value == old_document_values[key]
|
assert value == old_document_values[key]
|
||||||
|
elif key == "updated_at":
|
||||||
|
assert value > old_document_values[key]
|
||||||
else:
|
else:
|
||||||
assert value == new_document_values[key]
|
assert value == new_document_values[key]
|
||||||
|
|
||||||
@@ -178,8 +180,10 @@ def test_api_documents_update_authenticated_owners(via, mock_user_get_teams):
|
|||||||
document = models.Document.objects.get(pk=document.pk)
|
document = models.Document.objects.get(pk=document.pk)
|
||||||
document_values = serializers.DocumentSerializer(instance=document).data
|
document_values = serializers.DocumentSerializer(instance=document).data
|
||||||
for key, value in document_values.items():
|
for key, value in document_values.items():
|
||||||
if key in ["id", "accesses"]:
|
if key in ["id", "accesses", "created_at"]:
|
||||||
assert value == old_document_values[key]
|
assert value == old_document_values[key]
|
||||||
|
elif key == "updated_at":
|
||||||
|
assert value > old_document_values[key]
|
||||||
else:
|
else:
|
||||||
assert value == new_document_values[key]
|
assert value == new_document_values[key]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user