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

Commit 5abb9ad

Browse files
authored
0.1.4 Fix BadRequest error on client.list_engines
1 parent 8253e98 commit 5abb9ad

File tree

5 files changed

+58
-13
lines changed

5 files changed

+58
-13
lines changed

README.rst

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ You can also download the project source and run::
2121

2222
$ python setup.py install
2323

24+
Running Tests
25+
============
26+
27+
$ python setup.py test
28+
2429
Dependencies
2530
============
2631
Swiftype App Search supports Python 2.7 and Python 3.3+. It depends on requests and PyJWT.
@@ -44,7 +49,7 @@ Index document
4449
.. code-block:: python
4550
4651
>>> engine_name = 'favorite-videos'
47-
>>> documents = {
52+
>>> document = {
4853
'id': 'INscMGmhmX4',
4954
'url': 'https://www.youtube.com/watch?v=INscMGmhmX4',
5055
'title': 'The Original Grumpy Cat',
@@ -101,8 +106,18 @@ List Engines
101106

102107
.. code-block:: python
103108
104-
>>> client.list_engines()
105-
[{'name': 'favorite-videos'}, {'name': 'another-engine'}]
109+
>>> client.list_engines(current=1, size=20)
110+
{
111+
'meta': {
112+
'page': {
113+
'current': 1,
114+
'total_pages': 1,
115+
'total_results': 2,
116+
'size': 20
117+
}
118+
},
119+
'results': [{'name': 'favorite-videos'}, {'name': 'another-engine'}]
120+
}
106121
107122
Get an Engine
108123
-------------

setup.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,10 @@
4040
'requests',
4141
'PyJWT'
4242
],
43-
extras_require={
44-
'test': [
45-
'mock',
46-
'requests_mock',
47-
'future'
48-
],
49-
},
43+
tests_require=[
44+
'mock',
45+
'requests_mock',
46+
'future'
47+
],
5048
test_suite='tests'
5149
)

swiftype_app_search/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__title__ = 'swiftype_app_search'
22
__description__ = 'An API client for Swiftype App Search'
33
__url__ = 'https://github.com/swiftype/swiftype-app-search-python'
4-
__version__ = '0.1.3'
4+
__version__ = '0.1.4'
55
__author__ = 'Swiftype'
66
__author_email__ = 'eng@swiftype.com'

swiftype_app_search/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def list_engines(self, current=1, size=20):
8888
name of the engine.
8989
"""
9090
data = { 'page': { 'current': current, 'size': size } }
91-
return self.swiftype_session.request('get', 'engines', data=data)
91+
return self.swiftype_session.request('get', 'engines', json=data)
9292

9393
def get_engine(self, engine_name):
9494
"""

tests/test_client.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from swiftype_app_search import Client
55
from swiftype_app_search.exceptions import InvalidDocument
66

7-
87
class TestClient(TestCase):
98

109
def setUp(self):
@@ -78,6 +77,39 @@ def test_destroy_documents(self):
7877
response = self.client.destroy_documents(self.engine_name, [id])
7978
self.assertEqual(response, expected_return)
8079

80+
def test_list_engines(self):
81+
expected_return = [
82+
{ 'name': 'myawesomeengine' }
83+
]
84+
85+
with requests_mock.Mocker() as m:
86+
url = "{}/{}".format(self.client.swiftype_session.base_url, 'engines')
87+
m.register_uri('GET',
88+
url,
89+
additional_matcher=lambda x: x.text == '{"page": {"current": 1, "size": 20}}',
90+
json=expected_return,
91+
status_code=200
92+
)
93+
response = self.client.list_engines()
94+
self.assertEqual(response, expected_return)
95+
96+
def test_list_engines_with_paging(self):
97+
expected_return = [
98+
{'name': 'myawesomeengine'}
99+
]
100+
101+
with requests_mock.Mocker() as m:
102+
url = "{}/{}".format(self.client.swiftype_session.base_url, 'engines')
103+
m.register_uri(
104+
'GET',
105+
url,
106+
additional_matcher=lambda x: x.text == '{"page": {"current": 10, "size": 2}}',
107+
json=expected_return,
108+
status_code=200
109+
)
110+
response = self.client.list_engines(current=10, size=2)
111+
self.assertEqual(response, expected_return)
112+
81113
def test_get_engine(self):
82114
engine_name = 'myawesomeengine'
83115
expected_return = [

0 commit comments

Comments
 (0)