Skip to content

Commit

Permalink
update rc version, add tests for helper method
Browse files Browse the repository at this point in the history
  • Loading branch information
csteez committed Mar 11, 2020
1 parent 27786b5 commit ea8714c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
3 changes: 3 additions & 0 deletions search_service/models/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
class Tag:
tag_name: str

def __init__(self, tag_name: str):
self.tag_name = tag_name


class TagSchema(AttrsSchema):
class Meta:
Expand Down
9 changes: 4 additions & 5 deletions search_service/proxy/elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def _get_search_result(self, page_index: int,
result = {}
for attr, val in es_payload.items():
if attr in model.get_attrs():
result[attr] = self._get_instance(attr, val)
result[attr] = self._get_instance(attr=attr, val=val)

results.append(model(**result))
except Exception:
Expand All @@ -115,11 +115,10 @@ def _get_search_result(self, page_index: int,
return SearchResult(total_results=response.hits.total,
results=results)

@staticmethod
def _get_instance(attr: str, val: str) -> Any:
def _get_instance(self, attr: str, val: Any) -> Any:
if attr in TAG_MAPPING:
# maps a given badge or tag to a tag class'
return [TAG_MAPPING[attr](property_val) for property_val in val] # type: ignore
# maps a given badge or tag to a tag class
return [TAG_MAPPING[attr](tag_name=property_val) for property_val in val] # type: ignore
else:
return val

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from setuptools import setup, find_packages

__version__ = '2.1.1rc6'
__version__ = '2.1.1rc7'

requirements_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'requirements.txt')
with open(requirements_path) as requirements_file:
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/proxy/test_elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,3 +670,17 @@ def test_delete_user_document(self, mock_uuid: MagicMock) -> None:

self.assertEquals(expected_alias, result)
mock_elasticsearch.bulk.assert_called_with(expected_data)

def test__get_instance_string(self) -> None:
result = self.es_proxy._get_instance('column', 'value')
self.assertEqual('value', result)

def test__get_instance_tag(self) -> None:
result = self.es_proxy._get_instance('tags', ['value'])
tags = [Tag(tag_name='value')]
self.assertEqual(tags, result)

def test__get_instance_badge(self) -> None:
result = self.es_proxy._get_instance('badges', ['badge1'])
badges = [Tag(tag_name='badge1')]
self.assertEqual(badges, result)

0 comments on commit ea8714c

Please sign in to comment.