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

Commit b5331a6

Browse files
committed
Addeded language support to create engine
1 parent 9811afa commit b5331a6

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ The client can be configured to use a managed deploy by adjusting the `base_endp
168168
### Create an Engine
169169

170170
```python
171-
>>> client.create_engine('favorite-videos')
172-
{'name': 'favorite-videos'}
171+
>>> client.create_engine('favorite-videos', 'en')
172+
{'name': 'favorite-videos', 'type': 'default', 'language': 'en'}
173173
```
174174

175175
### Destroy an Engine

swiftype_app_search/client.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,16 @@ def get_engine(self, engine_name):
127127
"""
128128
return self.swiftype_session.request('get', "engines/{}".format(engine_name))
129129

130-
def create_engine(self, engine_name):
130+
def create_engine(self, engine_name, language=None):
131131
"""
132132
Creates an engine with the specified name.
133133
:param engine_name: Name of the new engine.
134-
:return: A dictionary corresponding to the name of the engine.
134+
:param language: Language of the new engine.
135+
:return: A dictionary corresponding to the new engine.
135136
"""
136137
data = { 'name': engine_name }
138+
if language is not None:
139+
data['language'] = language
137140
return self.swiftype_session.request('post', 'engines', json=data)
138141

139142
def destroy_engine(self, engine_name):

tests/test_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,12 @@ def test_get_engine(self):
185185

186186
def test_create_engine(self):
187187
engine_name = 'myawesomeengine'
188-
expected_return = {'name': engine_name}
188+
expected_return = {'name': engine_name, 'language': 'en'}
189189

190190
with requests_mock.Mocker() as m:
191191
url = "{}/{}".format(self.client.swiftype_session.base_url, 'engines')
192192
m.register_uri('POST', url, json=expected_return, status_code=200)
193-
response = self.client.create_engine(engine_name)
193+
response = self.client.create_engine(engine_name, 'en')
194194
self.assertEqual(response, expected_return)
195195

196196
def test_destroy_engine(self):

0 commit comments

Comments
 (0)