feat(api): add media news sorting
All checks were successful
All checks were successful
This commit is contained in:
@@ -105,6 +105,8 @@ SOURCE_RECORD_ORDERING_FIELDS = (
|
|||||||
"extension__organization__okpo",
|
"extension__organization__okpo",
|
||||||
"status",
|
"status",
|
||||||
"payload__attestation_status",
|
"payload__attestation_status",
|
||||||
|
"payload__sentiment",
|
||||||
|
"payload__news_source",
|
||||||
)
|
)
|
||||||
SOURCE_RECORD_ORDERING_VALUES = [
|
SOURCE_RECORD_ORDERING_VALUES = [
|
||||||
value
|
value
|
||||||
@@ -227,8 +229,9 @@ SOURCE_RECORD_LIST_PARAMS = [
|
|||||||
"extension__organization__full_name, created_at, updated_at, title, "
|
"extension__organization__full_name, created_at, updated_at, title, "
|
||||||
"uid, extension__organization__inn, extension__organization__ogrn, "
|
"uid, extension__organization__inn, extension__organization__ogrn, "
|
||||||
"extension__organization__okpo, status, "
|
"extension__organization__okpo, status, "
|
||||||
"payload__attestation_status. Для обратной сортировки используйте "
|
"payload__attestation_status, payload__sentiment, "
|
||||||
"префикс -. Значения record_date с null сортируются последними."
|
"payload__news_source. Для обратной сортировки используйте префикс -. "
|
||||||
|
"Значения record_date с null сортируются последними."
|
||||||
),
|
),
|
||||||
enum=SOURCE_RECORD_ORDERING_VALUES,
|
enum=SOURCE_RECORD_ORDERING_VALUES,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -207,6 +207,21 @@ class OrganizationsApiV2Test(APITestCase):
|
|||||||
)
|
)
|
||||||
self.assertIn("/api/v2/organizations/{uid}/sources/", paths)
|
self.assertIn("/api/v2/organizations/{uid}/sources/", paths)
|
||||||
self.assertIn("/api/v2/organization-sources/{uid}/records/", paths)
|
self.assertIn("/api/v2/organization-sources/{uid}/records/", paths)
|
||||||
|
source_record_list_operation = paths[
|
||||||
|
"/api/v2/organization-source-records/"
|
||||||
|
]["get"]
|
||||||
|
source_record_parameters = {
|
||||||
|
parameter["name"]: parameter
|
||||||
|
for parameter in source_record_list_operation["parameters"]
|
||||||
|
}
|
||||||
|
source_record_ordering_values = source_record_parameters["ordering"]["enum"]
|
||||||
|
for ordering_value in (
|
||||||
|
"payload__sentiment",
|
||||||
|
"-payload__sentiment",
|
||||||
|
"payload__news_source",
|
||||||
|
"-payload__news_source",
|
||||||
|
):
|
||||||
|
self.assertIn(ordering_value, source_record_ordering_values)
|
||||||
|
|
||||||
def test_retrieve_returns_item_by_uid(self):
|
def test_retrieve_returns_item_by_uid(self):
|
||||||
organization = create_frontend_organization(
|
organization = create_frontend_organization(
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ from django.urls import reverse
|
|||||||
from organizations.models import (
|
from organizations.models import (
|
||||||
ArbitrationExtension,
|
ArbitrationExtension,
|
||||||
ElectronicDocumentExchangeExtension,
|
ElectronicDocumentExchangeExtension,
|
||||||
|
MediaMentionExtension,
|
||||||
Organization,
|
Organization,
|
||||||
OrganizationSourceRecord,
|
OrganizationSourceRecord,
|
||||||
PlannedInspectionExtension,
|
PlannedInspectionExtension,
|
||||||
@@ -388,6 +389,54 @@ class OrganizationSourceExtensionsApiV2Test(APITestCase):
|
|||||||
expected,
|
expected,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_flat_media_records_support_frontend_sorting_fields(self):
|
||||||
|
organization = create_frontend_organization(
|
||||||
|
name="Media sorting organization",
|
||||||
|
inn="7707083817",
|
||||||
|
ogrn="1027700132017",
|
||||||
|
)
|
||||||
|
extension = MediaMentionExtension.objects.create(
|
||||||
|
organization=organization,
|
||||||
|
title="Media mentions",
|
||||||
|
)
|
||||||
|
for external_id, news_source, sentiment in (
|
||||||
|
("NEWS-ZULU", "Zulu Media", "negative"),
|
||||||
|
("NEWS-ALPHA", "Alpha Media", "positive"),
|
||||||
|
):
|
||||||
|
OrganizationSourceRecord.objects.create(
|
||||||
|
extension=extension,
|
||||||
|
record_type="media_mention",
|
||||||
|
source="media_news",
|
||||||
|
external_id=external_id,
|
||||||
|
status=sentiment,
|
||||||
|
payload={
|
||||||
|
"news_source": news_source,
|
||||||
|
"sentiment": sentiment,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
endpoint = reverse("api_v2:organizations:organization-source-records-list")
|
||||||
|
params = {
|
||||||
|
"source_group": "media_mentions",
|
||||||
|
"source": "media_news",
|
||||||
|
"record_type": "media_mention",
|
||||||
|
}
|
||||||
|
|
||||||
|
for ordering, expected in (
|
||||||
|
("payload__news_source", ["NEWS-ALPHA", "NEWS-ZULU"]),
|
||||||
|
("-payload__news_source", ["NEWS-ZULU", "NEWS-ALPHA"]),
|
||||||
|
("payload__sentiment", ["NEWS-ZULU", "NEWS-ALPHA"]),
|
||||||
|
("-payload__sentiment", ["NEWS-ALPHA", "NEWS-ZULU"]),
|
||||||
|
):
|
||||||
|
with self.subTest(ordering=ordering):
|
||||||
|
response = self.client.get(endpoint, {**params, "ordering": ordering})
|
||||||
|
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
self.assertEqual(
|
||||||
|
[item["external_id"] for item in response.data["data"]],
|
||||||
|
expected,
|
||||||
|
)
|
||||||
|
|
||||||
def test_flat_source_records_rejects_invalid_date_range_and_ordering(self):
|
def test_flat_source_records_rejects_invalid_date_range_and_ordering(self):
|
||||||
response = self.client.get(
|
response = self.client.get(
|
||||||
reverse("api_v2:organizations:organization-source-records-list"),
|
reverse("api_v2:organizations:organization-source-records-list"),
|
||||||
|
|||||||
Reference in New Issue
Block a user