Skip to content

Commit

Permalink
Add Atlas dependency and fix Atlas initialisation (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
whazor authored and Hans Adriaans committed Jun 30, 2022
1 parent 21f45d8 commit 0ad3e46
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
3 changes: 2 additions & 1 deletion search/search_service/proxy/atlas.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ def __init__(self, *,
index: str = None,
user: str = '',
password: str = '',
client: Atlas = None,
page_size: int = 10) -> None:
self.atlas = Atlas(host, username=user, password=password)
self.atlas = client or Atlas(host, username=user, password=password)
self.index = index
self.page_size = page_size

Expand Down
5 changes: 3 additions & 2 deletions search/setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages

__version__ = '1.0.3'
__version__ = '1.0.4'


setup(
Expand All @@ -16,7 +16,8 @@
'Flask-RESTFul==0.3.6',
'elasticsearch==6.2.0',
'elasticsearch-dsl==6.1.0',
'statsd==3.2.1'
'statsd==3.2.1',
'atlasclient==0.1.6'
],
python_requires=">=3.6"
)
32 changes: 30 additions & 2 deletions search/tests/unit/proxy/test_atlas.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import string
import unittest

from mock import MagicMock
from mock import MagicMock, patch
from typing import List, Callable, Tuple

from search_service import create_app
from search_service import create_app, config
from search_service.models.search_result import SearchResult
from search_service.models.table import Table
from search_service.proxy import get_proxy_client


class TestAtlasProxy(unittest.TestCase):
Expand Down Expand Up @@ -174,6 +175,33 @@ def guid_filter(guid: List):

return guid_filter

def test_setup_client(self) -> None:
with self.app_context:
from search_service.proxy.atlas import AtlasProxy
client = AtlasProxy(
host="http://localhost:21000",
user="admin",
password="admin",
page_size=1337
)
self.assertEqual(client.atlas.base_url, "http://localhost:21000")
self.assertEqual(client.atlas.client.request_params['headers']['Authorization'], 'Basic YWRtaW46YWRtaW4=')
self.assertEqual(client.page_size, 1337)

@patch('search_service.proxy._proxy_client', None)
def test_setup_config(self) -> None:
# Gather all the configuration to create a Proxy Client
self.app.config[config.PROXY_ENDPOINT] = "http://localhost:21000"
self.app.config[config.PROXY_USER] = "admin"
self.app.config[config.PROXY_PASSWORD] = "admin"
self.app.config[config.PROXY_CLIENT] = config.PROXY_CLIENTS['ATLAS']
self.app.config[config.SEARCH_PAGE_SIZE_KEY] = 1337

client = get_proxy_client()
self.assertEqual(client.atlas.base_url, "http://localhost:21000")
self.assertEqual(client.atlas.client.request_params['headers']['Authorization'], 'Basic YWRtaW46YWRtaW4=')
self.assertEqual(client.page_size, 1337)

def test_search_normal(self):
expected = SearchResult(total_results=1,
results=[Table(name=self._qualified('table', 'Table1'),
Expand Down
1 change: 1 addition & 0 deletions search/tests/unit/proxy/test_elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def test_setup_client(self) -> None:
self.assertEqual(client.transport.hosts[0]['port'], 9200)
self.assertEqual(self.es_proxy.index, "random123")

@patch('search_service.proxy._proxy_client', None)
def test_setup_config(self) -> None:
es: ElasticsearchProxy = get_proxy_client()
a = es.elasticsearch
Expand Down

0 comments on commit 0ad3e46

Please sign in to comment.