Skip to content
This repository has been archived by the owner on Sep 1, 2021. It is now read-only.

Commit

Permalink
Renamed meta engine methods (#22)
Browse files Browse the repository at this point in the history
Renamed methods to match signatures from PHP client
  • Loading branch information
JasonStoltz authored Feb 13, 2020
1 parent 4f7b279 commit e650c9b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -395,27 +395,27 @@ Creating a search key that will only search over the body field.
### Create a Meta Engine

```python
>>> client.create_engine('my-meta-engine', options={
'type': 'meta',
'source_engines': [
'source-engine-1',
'source-engine-2'
]
})
>>> client.create_meta_engine(
engine_name=engine_name,
source_engines=[
'source-engine-1',
'source-engine-2'
]
)
{'source_engines': ['source-engine-1', 'source-engine-2'], 'type': 'meta', 'name': 'my-meta-engine'}
```

### Add a Source Engine to a Meta Engine

```python
>>> client.add_source_engines('my-meta-engine', ['source-engine-3'])
>>> client.add_meta_engine_sources('my-meta-engine', ['source-engine-3'])
{'source_engines': ['source-engine-1', 'source-engine-2', 'source-engine-3'], 'type': 'meta', 'name': 'my-meta-engine'}
```

### Remove a Source Engine from a Meta Engine

```python
>>> client.remove_source_engines('my-meta-engine', ['source-engine-3'])
>>> client.delete_meta_engine_sources('my-meta-engine', ['source-engine-3'])
{'source_engines': ['source-engine-1', 'source-engine-2'], 'type': 'meta', 'name': 'my-meta-engine'}
```

Expand Down
12 changes: 10 additions & 2 deletions elastic_app_search/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,19 @@ def click(self, engine_name, options):
endpoint = "engines/{}/click".format(engine_name)
return self.session.request_ignore_response('post', endpoint, json=options)

def add_source_engines(self, engine_name, source_engines):
def create_meta_engine(self, engine_name, source_engines):
data = {
'name': engine_name,
'source_engines': source_engines,
'type': 'meta'
}
return self.session.request('post', 'engines', json=data)

def add_meta_engine_sources(self, engine_name, source_engines):
endpoint = "engines/{}/source_engines".format(engine_name)
return self.session.request('post', endpoint, json=source_engines)

def remove_source_engines(self, engine_name, source_engines):
def delete_meta_engine_sources(self, engine_name, source_engines):
endpoint = "engines/{}/source_engines".format(engine_name)
return self.session.request('delete', endpoint, json=source_engines)

Expand Down
20 changes: 16 additions & 4 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,19 @@ def test_click(self):
self.client.click(self.engine_name, {
'query': 'cat', 'document_id': 'INscMGmhmX4'})

def test_add_source_engines(self):
def test_create_meta_engine(self):
source_engines = ['source-engine-1', 'source-engine-2']
expected_return = {'source_engines': source_engines,
'type': 'meta', 'name': self.engine_name}

with requests_mock.Mocker() as m:
url = "{}/{}".format(self.client.session.base_url, 'engines')
m.register_uri('POST', url, json=expected_return, status_code=200)
response = self.client.create_meta_engine(
self.engine_name, source_engines)
self.assertEqual(response, expected_return)

def test_add_meta_engine_sources(self):
target_source_engine_name = 'source-engine-3'
expected_return = {'source_engines': [
'source-engine-1', 'source-engine-2', target_source_engine_name], 'type': 'meta', 'name': self.engine_name}
Expand All @@ -521,11 +533,11 @@ def test_add_source_engines(self):
"engines/{}/source_engines".format(self.engine_name)
)
m.register_uri('POST', url, json=expected_return, status_code=200)
response = self.client.add_source_engines(
response = self.client.add_meta_engine_sources(
self.engine_name, [target_source_engine_name])
self.assertEqual(response, expected_return)

def test_remove_source_engines(self):
def test_delete_meta_engine_sources(self):
source_engine_name = 'source-engine-3'
expected_return = {'source_engines': [
'source-engine-1', 'source-engine-2'], 'type': 'meta', 'name': self.engine_name}
Expand All @@ -537,6 +549,6 @@ def test_remove_source_engines(self):
)
m.register_uri('DELETE', url, json=expected_return,
status_code=200)
response = self.client.remove_source_engines(
response = self.client.delete_meta_engine_sources(
self.engine_name, [source_engine_name])
self.assertEqual(response, expected_return)

0 comments on commit e650c9b

Please sign in to comment.