See #890: added moderation note model, serializers and views

This commit is contained in:
Eliot Berriot 2019-08-29 11:45:41 +02:00
commit ab3bc96783
No known key found for this signature in database
GPG key ID: DD6965E2476E5C27
13 changed files with 193 additions and 9 deletions

View file

@ -550,3 +550,20 @@ def test_manage_report_serializer(factories, to_api_date):
s = serializers.ManageReportSerializer(report)
assert s.data == expected
def test_manage_note_serializer(factories, to_api_date):
actor = factories["federation.Actor"]()
note = factories["moderation.Note"](target=actor)
expected = {
"id": note.id,
"uuid": str(note.uuid),
"summary": note.summary,
"creation_date": to_api_date(note.creation_date),
"author": serializers.ManageBaseActorSerializer(note.author).data,
"target": {"type": "account", "full_username": actor.full_username},
}
s = serializers.ManageNoteSerializer(note)
assert s.data == expected

View file

@ -391,6 +391,50 @@ def test_upload_delete(factories, superuser_api_client):
assert response.status_code == 204
def test_note_create(factories, superuser_api_client):
actor = superuser_api_client.user.create_actor()
target = factories["federation.Actor"]()
data = {
"summary": "Hello",
"target": {"type": "account", "full_username": target.full_username},
}
url = reverse("api:v1:manage:moderation:notes-list")
response = superuser_api_client.post(url, data, format="json")
assert response.status_code == 201
note = actor.moderation_notes.latest("id")
assert note.target == target
assert response.data == serializers.ManageNoteSerializer(note).data
def test_note_list(factories, superuser_api_client, settings):
note = factories["moderation.Note"]()
url = reverse("api:v1:manage:moderation:notes-list")
response = superuser_api_client.get(url)
assert response.status_code == 200
assert response.data["count"] == 1
assert response.data["results"][0] == serializers.ManageNoteSerializer(note).data
def test_note_delete(factories, superuser_api_client):
note = factories["moderation.Note"]()
url = reverse("api:v1:manage:moderation:notes-detail", kwargs={"uuid": note.uuid})
response = superuser_api_client.delete(url)
assert response.status_code == 204
def test_note_detail(factories, superuser_api_client):
note = factories["moderation.Note"]()
url = reverse("api:v1:manage:moderation:notes-detail", kwargs={"uuid": note.uuid})
response = superuser_api_client.get(url)
assert response.status_code == 200
assert response.data == serializers.ManageNoteSerializer(note).data
def test_tag_detail(factories, superuser_api_client):
tag = factories["tags.Tag"]()
url = reverse("api:v1:manage:tags-detail", kwargs={"name": tag.name})