-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix ES proxy to handle additional attribute (#35)
* Fix ES proxy to handle additional attribute * tmp remove test * Fix
- Loading branch information
Showing
9 changed files
with
139 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from abc import ABCMeta, abstractmethod | ||
from typing import Set | ||
|
||
|
||
class Base(metaclass=ABCMeta): | ||
""" | ||
A base class for ES model | ||
""" | ||
|
||
@abstractmethod | ||
def get_attrs(cls) -> Set: | ||
# return a set of attributes for the class | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
from setuptools import setup, find_packages | ||
|
||
__version__ = '1.1.2rc1' | ||
__version__ = '1.1.2' | ||
|
||
|
||
setup( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from typing import Any | ||
import unittest | ||
from unittest.mock import patch, MagicMock | ||
|
||
|
@@ -33,6 +34,36 @@ def __init__(self, *, | |
self.last_updated_epoch = last_updated_epoch | ||
|
||
|
||
class MockKVSearchResult: | ||
def __init__(self, *, | ||
first_name: str, | ||
last_name: str, | ||
name: str, | ||
team_name: str, | ||
email: str, | ||
manager_email: str, | ||
github_username: str, | ||
is_active: bool, | ||
employee_type: str, | ||
new_attr: str) -> None: | ||
self.name = name | ||
self.first_name = first_name | ||
self.last_name = last_name | ||
self.team_name = team_name | ||
self.email = email | ||
self.manager_email = manager_email | ||
self.github_username = github_username | ||
self.is_active = is_active | ||
self.employee_type = employee_type | ||
self.new_attr = new_attr | ||
|
||
|
||
class Response: | ||
def __init__(self, | ||
result: Any): | ||
self._d_ = result | ||
|
||
|
||
class TestElasticsearchProxy(unittest.TestCase): | ||
|
||
def setUp(self) -> None: | ||
|
@@ -73,15 +104,16 @@ def setUp(self) -> None: | |
tags=['match'], | ||
last_updated_epoch=1527283287) | ||
|
||
self.mock_result4 = User(name='First Last', | ||
first_name='First', | ||
last_name='Last', | ||
team_name='Test team', | ||
email='[email protected]', | ||
github_username='ghub', | ||
manager_email='[email protected]', | ||
is_active=True, | ||
employee_type='FTE') | ||
self.mock_result4 = MockKVSearchResult(name='First Last', | ||
first_name='First', | ||
last_name='Last', | ||
team_name='Test team', | ||
email='[email protected]', | ||
github_username='ghub', | ||
manager_email='[email protected]', | ||
is_active=True, | ||
employee_type='FTE', | ||
new_attr='aaa') | ||
|
||
def test_setup_client(self) -> None: | ||
self.es_proxy = ElasticsearchProxy( | ||
|
@@ -135,7 +167,7 @@ def test_search_with_one_table_result(self, | |
|
||
mock_results = MagicMock() | ||
mock_results.hits.total = 1 | ||
mock_results.__iter__.return_value = [self.mock_result1] | ||
mock_results.__iter__.return_value = [Response(result=vars(self.mock_result1))] | ||
mock_search.return_value = mock_results | ||
|
||
expected = SearchResult(total_results=1, | ||
|
@@ -165,7 +197,8 @@ def test_search_with_multiple_result(self, | |
|
||
mock_results = MagicMock() | ||
mock_results.hits.total = 2 | ||
mock_results.__iter__.return_value = [self.mock_result1, self.mock_result2] | ||
mock_results.__iter__.return_value = [Response(result=vars(self.mock_result1)), | ||
Response(result=vars(self.mock_result2))] | ||
mock_search.return_value = mock_results | ||
|
||
expected = SearchResult(total_results=2, | ||
|
@@ -264,38 +297,13 @@ def test_search_regex_match_field(self, | |
vars(expected.results[0]), | ||
"Search result doesn't match with expected result!") | ||
|
||
@patch('search_service.proxy.elasticsearch.ElasticsearchProxy._search_helper') | ||
def test_search_user_match(self, mock_search: MagicMock) -> None: | ||
|
||
mock_search.return_value = SearchResult(total_results=1, | ||
results=[self.mock_result4]) | ||
|
||
expected = SearchResult(total_results=1, | ||
results=[User(name='First Last', | ||
first_name='First', | ||
last_name='Last', | ||
team_name='Test team', | ||
email='[email protected]', | ||
github_username='ghub', | ||
manager_email='[email protected]', | ||
is_active=True, | ||
employee_type='FTE')]) | ||
|
||
resp = self.es_proxy.fetch_user_search_results(query_term='First', | ||
index='user_search_index') | ||
self.assertEquals(resp.total_results, expected.total_results) | ||
|
||
self.assertDictEqual(vars(resp.results[0]), | ||
vars(expected.results[0]), | ||
"Search result doesn't match with expected result!") | ||
|
||
@patch('elasticsearch_dsl.Search.execute') | ||
def test_search_with_one_user_result(self, | ||
mock_search: MagicMock) -> None: | ||
|
||
mock_results = MagicMock() | ||
mock_results.hits.total = 1 | ||
mock_results.__iter__.return_value = [self.mock_result4] | ||
mock_results.__iter__.return_value = [Response(result=vars(self.mock_result4))] | ||
mock_search.return_value = mock_results | ||
|
||
expected = SearchResult(total_results=1, | ||
|