feat(api): add media news sorting
All checks were successful
All checks were successful
This commit is contained in:
@@ -207,6 +207,21 @@ class OrganizationsApiV2Test(APITestCase):
|
||||
)
|
||||
self.assertIn("/api/v2/organizations/{uid}/sources/", 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):
|
||||
organization = create_frontend_organization(
|
||||
|
||||
@@ -7,6 +7,7 @@ from django.urls import reverse
|
||||
from organizations.models import (
|
||||
ArbitrationExtension,
|
||||
ElectronicDocumentExchangeExtension,
|
||||
MediaMentionExtension,
|
||||
Organization,
|
||||
OrganizationSourceRecord,
|
||||
PlannedInspectionExtension,
|
||||
@@ -388,6 +389,54 @@ class OrganizationSourceExtensionsApiV2Test(APITestCase):
|
||||
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):
|
||||
response = self.client.get(
|
||||
reverse("api_v2:organizations:organization-source-records-list"),
|
||||
|
||||
Reference in New Issue
Block a user