Skip to content

Commit c8423c6

Browse files
authored
fix: Sort reports alphabetically (#293)
* Sort reports alphabetically Signed-off-by: sinkuladis <sink.vlad@gmail.com> * Static typing fix Signed-off-by: sinkuladis <sink.vlad@gmail.com>
1 parent cf6710d commit c8423c6

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

metadata_service/proxy/atlas_proxy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ def _get_reports(self, guids: List[str]) -> List[ResourceReport]:
428428
parsed_reports = app.config['RESOURCE_REPORT_CLIENT'](reports) \
429429
if app.config['RESOURCE_REPORT_CLIENT'] else reports
430430

431-
return parsed_reports
431+
return sorted(parsed_reports)
432432

433433
def _get_owners(self, data_owners: list, fallback_owner: str = None) -> List[User]:
434434
owners_detail = list()

tests/unit/proxy/test_atlas_proxy.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from amundsen_common.models.popular_table import PopularTable
1010
from amundsen_common.models.table import (Badge, Column,
1111
ProgrammaticDescription, Reader,
12-
Stat, Table, User)
12+
ResourceReport, Stat, Table, User)
1313
from apache_atlas.model.instance import AtlasRelatedObjectId
1414
from apache_atlas.model.relationship import AtlasRelationship
1515
from apache_atlas.utils import type_coerce
@@ -101,7 +101,17 @@ def _create_mocked_report_entities_collection(self) -> None:
101101
mocked_report_entity.attributes = entity['attributes']
102102
mocked_report_entities_collection.entities.append(mocked_report_entity)
103103

104-
self.report_entity_collection = [mocked_report_entities_collection]
104+
self.report_entity_collection = mocked_report_entities_collection
105+
106+
def test_get_sorted_reports(self) -> None:
107+
self._create_mocked_report_entities_collection()
108+
self.report_entity_collection.entities.sort(key=lambda x: x.attributes['name'], reverse=True)
109+
self.proxy.client.entity.get_entities_by_guids = MagicMock(return_value=self.report_entity_collection)
110+
reports_guid = cast(dict, self.entity1)['attributes']['reports']
111+
sorted_reports = self.proxy._get_reports(reports_guid)
112+
expected = [ResourceReport(name="test_report", url="http://test"),
113+
ResourceReport(name="test_report3", url="http://test3")]
114+
self.assertEqual(sorted_reports, expected)
105115

106116
def _get_table(self, custom_stats_format: bool = False) -> None:
107117
if custom_stats_format:

0 commit comments

Comments
 (0)