Skip to content

Commit

Permalink
fix: add id field to Dashboard (#174)
Browse files Browse the repository at this point in the history
Signed-off-by: tianru zhou <[email protected]>
  • Loading branch information
tianruzhou-db authored Jan 29, 2021
1 parent 76a8a8b commit 53634fa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 3 additions & 1 deletion search_service/models/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ class Dashboard(Base,
"""
This represents the part of a dashboard stored in the search proxy
"""
id: str = attr.ib()

def get_id(self) -> str:
# uses the table key as the document id in ES
return self.name
return self.id

@classmethod
def get_attrs(cls) -> Set:
return {
'id',
'uri',
'cluster',
'group_name',
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/api/dashboard/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@


def mock_proxy_results() -> Dashboard:
return Dashboard(uri='dashboard_uri',
return Dashboard(id='mode_dashboard',
uri='dashboard_uri',
cluster='gold',
group_name='mode_dashboard_group',
group_url='mode_dashboard_group_url',
Expand All @@ -18,6 +19,7 @@ def mock_proxy_results() -> Dashboard:

def mock_json_response() -> dict:
return {
"id": 'mode_dashboard',
"chart_names": [],
"uri": 'dashboard_uri',
"cluster": 'gold',
Expand Down
9 changes: 6 additions & 3 deletions tests/unit/proxy/test_elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ def setUp(self) -> None:
role_name='swe',
new_attr='aaa')

self.mock_dashboard_result = Dashboard(uri='dashboard_uri',
self.mock_dashboard_result = Dashboard(id='mode_dashboard',
uri='dashboard_uri',
cluster='gold',
group_name='mode_dashboard_group',
group_url='mode_dashboard_group_url',
Expand Down Expand Up @@ -711,7 +712,8 @@ def test_get_instance_badge(self) -> None:
def test_fetch_dashboard_search_results(self,
mock_search: MagicMock) -> None:

self.mock_dashboard_result = Dashboard(uri='dashboard_uri',
self.mock_dashboard_result = Dashboard(id='mode_dashboard',
uri='dashboard_uri',
cluster='gold',
group_name='mode_dashboard_group',
group_url='mode_dashboard_group_url',
Expand All @@ -725,7 +727,8 @@ def test_fetch_dashboard_search_results(self,
results=[self.mock_dashboard_result])

expected = SearchResult(total_results=1,
results=[Dashboard(uri='dashboard_uri',
results=[Dashboard(id='mode_dashboard',
uri='dashboard_uri',
cluster='gold',
group_name='mode_dashboard_group',
group_url='mode_dashboard_group_url',
Expand Down

0 comments on commit 53634fa

Please sign in to comment.