Skip to content

Commit

Permalink
fix: Sort reports alphabetically (amundsen-io#293)
Browse files Browse the repository at this point in the history
* Sort reports alphabetically

Signed-off-by: sinkuladis <sink.vlad@gmail.com>

* Static typing fix

Signed-off-by: sinkuladis <sink.vlad@gmail.com>
  • Loading branch information
sinkuladis committed Apr 20, 2021
1 parent 2390be5 commit 26ea1cb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion metadata/metadata_service/proxy/atlas_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def _get_reports(self, guids: List[str]) -> List[ResourceReport]:
parsed_reports = app.config['RESOURCE_REPORT_CLIENT'](reports) \
if app.config['RESOURCE_REPORT_CLIENT'] else reports

return parsed_reports
return sorted(parsed_reports)

def _get_owners(self, data_owners: list, fallback_owner: str = None) -> List[User]:
owners_detail = list()
Expand Down
14 changes: 12 additions & 2 deletions metadata/tests/unit/proxy/test_atlas_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from amundsen_common.models.popular_table import PopularTable
from amundsen_common.models.table import (Badge, Column,
ProgrammaticDescription, Reader,
Stat, Table, User)
ResourceReport, Stat, Table, User)
from apache_atlas.model.instance import AtlasRelatedObjectId
from apache_atlas.model.relationship import AtlasRelationship
from apache_atlas.utils import type_coerce
Expand Down Expand Up @@ -101,7 +101,17 @@ def _create_mocked_report_entities_collection(self) -> None:
mocked_report_entity.attributes = entity['attributes']
mocked_report_entities_collection.entities.append(mocked_report_entity)

self.report_entity_collection = [mocked_report_entities_collection]
self.report_entity_collection = mocked_report_entities_collection

def test_get_sorted_reports(self) -> None:
self._create_mocked_report_entities_collection()
self.report_entity_collection.entities.sort(key=lambda x: x.attributes['name'], reverse=True)
self.proxy.client.entity.get_entities_by_guids = MagicMock(return_value=self.report_entity_collection)
reports_guid = cast(dict, self.entity1)['attributes']['reports']
sorted_reports = self.proxy._get_reports(reports_guid)
expected = [ResourceReport(name="test_report", url="http://test"),
ResourceReport(name="test_report3", url="http://test3")]
self.assertEqual(sorted_reports, expected)

def _get_table(self, custom_stats_format: bool = False) -> None:
if custom_stats_format:
Expand Down

0 comments on commit 26ea1cb

Please sign in to comment.