4
4
from swiftype_app_search import Client
5
5
from swiftype_app_search .exceptions import InvalidDocument
6
6
7
+
7
8
class TestClient (TestCase ):
8
9
9
10
def setUp (self ):
@@ -15,13 +16,6 @@ def setUp(self):
15
16
"engines/{}/documents" .format (self .engine_name )
16
17
)
17
18
18
- def test_index_document_validation (self ):
19
- invalid_document = {'does' : 'not have the id field' }
20
- with self .assertRaises (InvalidDocument ) as context :
21
- self .client .index_documents (self .engine_name , [invalid_document ])
22
- self .assertEqual (str (context .exception ), 'Missing required fields: id' )
23
- self .assertEqual (context .exception .document , invalid_document )
24
-
25
19
def test_index_document_processing_error (self ):
26
20
invalid_document = {'id' : 'something' , 'bad' : {'no' : 'nested' }}
27
21
error = 'some processing error'
@@ -33,27 +27,28 @@ def test_index_document_processing_error(self):
33
27
self .client .index_document (self .engine_name , invalid_document )
34
28
self .assertEqual (str (context .exception ), error )
35
29
36
- def test_index_documents_validation (self ):
37
- invalid_documents = [
38
- {
39
- 'does' : 'not have the id field'
40
- }
41
- ]
42
- with self .assertRaises (InvalidDocument ) as context :
43
- self .client .index_documents (self .engine_name , invalid_documents )
44
- self .assertEqual (str (context .exception ), 'Missing required fields: id' )
45
- self .assertEqual (context .exception .document , invalid_documents [0 ])
30
+ def test_index_document_no_error_key_in_response (self ):
31
+ document_without_id = {'body' : 'some value' }
32
+ stubbed_return = [{'id' : 'auto generated' , 'errors' : []}]
33
+
34
+ with requests_mock .Mocker () as m :
35
+ m .register_uri ('POST' , self .document_index_url , json = stubbed_return , status_code = 200 )
36
+ response = self .client .index_document (self .engine_name , document_without_id )
37
+ self .assertEqual (response , {'id' : 'auto generated' })
46
38
47
39
def test_index_documents (self ):
48
40
id = 'INscMGmhmX4'
49
41
valid_document = {'id' : id }
42
+ other_document = { 'body' : 'some value' }
43
+
50
44
expected_return = [
51
- {'id' : id , 'errors' : []}
45
+ {'id' : id , 'errors' : []},
46
+ {'id' : 'some autogenerated id' , 'errors' : []}
52
47
]
53
48
54
49
with requests_mock .Mocker () as m :
55
50
m .register_uri ('POST' , self .document_index_url , json = expected_return , status_code = 200 )
56
- response = self .client .index_documents (self .engine_name , [valid_document ])
51
+ response = self .client .index_documents (self .engine_name , [valid_document , other_document ])
57
52
self .assertEqual (response , expected_return )
58
53
59
54
def test_get_documents (self ):
0 commit comments