See #890: review tweaks

environments/review-docs-rate-jr6phc/deployments/2479
Eliot Berriot 2019-09-06 10:10:32 +02:00
rodzic 92a1914ef8
commit 0600819b38
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: DD6965E2476E5C27
2 zmienionych plików z 45 dodań i 10 usunięć

Wyświetl plik

@ -695,7 +695,6 @@ class ManageReportSerializer(serializers.ModelSerializer):
"target_state",
"target_owner",
"summary",
# "notes",
]
def get_notes(self, o):

Wyświetl plik

@ -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"]