Verified Commit 0600819b authored by Eliot Berriot's avatar Eliot Berriot
Browse files

See #890: review tweaks

parent 92a1914e
......@@ -695,7 +695,6 @@ class ManageReportSerializer(serializers.ModelSerializer):
"target_state",
"target_owner",
"summary",
# "notes",
]
def get_notes(self, o):
......
......@@ -45,7 +45,6 @@ def test_user_filter_serializer_save(factories):
("music.Album", "album", "id", serializers.AlbumStateSerializer),
("music.Track", "track", "id", serializers.TrackStateSerializer),
("music.Library", "library", "uuid", serializers.LibraryStateSerializer),
("playlists.Playlist", "playlist", "id", serializers.PlaylistStateSerializer),
(
"federation.Actor",
"account",
......@@ -54,7 +53,7 @@ def test_user_filter_serializer_save(factories):
),
],
)
def test_report_serializer_save(
def test_report_federated_entity_serializer_save(
factory_name, target_type, id_field, state_serializer, factories, mocker, settings
):
target = factories[factory_name]()
......@@ -80,13 +79,50 @@ def test_report_serializer_save(
expected_state["_target"] = json.loads(
json.dumps(target_data, cls=DjangoJSONEncoder)
)
if hasattr(target, "fid"):
expected_state["domain"] = urllib.parse.urlparse(target.fid).hostname
expected_state["is_local"] = (
expected_state["domain"] == settings.FEDERATION_HOSTNAME
)
else:
expected_state["is_local"] = True
expected_state["domain"] = urllib.parse.urlparse(target.fid).hostname
expected_state["is_local"] = (
expected_state["domain"] == settings.FEDERATION_HOSTNAME
)
assert report.target == target
assert report.type == payload["type"]
assert report.summary == payload["summary"]
assert report.target_state == expected_state
assert report.target_owner == target_owner
get_target_owner.assert_called_once_with(target)
@pytest.mark.parametrize(
"factory_name, target_type, id_field, state_serializer",
[("playlists.Playlist", "playlist", "id", serializers.PlaylistStateSerializer)],
)
def test_report_local_entity_serializer_save(
factory_name, target_type, id_field, state_serializer, factories, mocker, settings
):
target = factories[factory_name]()
target_owner = factories["federation.Actor"]()
submitter = factories["federation.Actor"]()
target_data = {"type": target_type, id_field: getattr(target, id_field)}
payload = {
"summary": "Report content",
"type": "illegal_content",
"target": target_data,
}
serializer = serializers.ReportSerializer(
data=payload, context={"submitter": submitter}
)
get_target_owner = mocker.patch.object(
serializers, "get_target_owner", return_value=target_owner
)
assert serializer.is_valid(raise_exception=True) is True
report = serializer.save()
expected_state = state_serializer(target).data
expected_state["_target"] = json.loads(
json.dumps(target_data, cls=DjangoJSONEncoder)
)
expected_state["is_local"] = True
assert report.target == target
assert report.type == payload["type"]
assert report.summary == payload["summary"]
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment