Skip to content

Commit 4e6f635

Browse files
committed
6.x compatibility in tests
1 parent aca83e8 commit 4e6f635

File tree

1 file changed

+33
-34
lines changed

1 file changed

+33
-34
lines changed

test_elasticsearch/test_server/test_helpers.py

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ def test_different_op_types(self):
6464
self.assertTrue(ok)
6565

6666
self.assertFalse(self.client.exists(index='i', doc_type='t', id=45))
67-
self.assertEquals({'answer': 42}, self.client.get(index='i', id=42)['_source'])
68-
self.assertEquals({'f': 'v'}, self.client.get(index='i', id=47)['_source'])
67+
self.assertEquals({'answer': 42}, self.client.get(index='i', doc_type='t', id=42)['_source'])
68+
self.assertEquals({'f': 'v'}, self.client.get(index='i', doc_type='t', id=47)['_source'])
6969

7070
def test_transport_error_can_becaught(self):
7171
failing_client = FailingBulkClient(self.client)
@@ -255,49 +255,50 @@ def setUp(self):
255255
super(TestReindex, self).setUp()
256256
bulk = []
257257
for x in range(100):
258-
bulk.append({"index": {"_index": "test_index", "_type": "answers" if x % 2 == 0 else "questions", "_id": x}})
259-
bulk.append({"answer": x, "correct": x == 42})
258+
bulk.append({"index": {"_index": "test_index", "_type": "post", "_id": x}})
259+
bulk.append({"answer": x, "correct": x == 42, "type": "answers" if x % 2 == 0 else "questions"})
260260
self.client.bulk(bulk, refresh=True)
261261

262262
def test_reindex_passes_kwargs_to_scan_and_bulk(self):
263-
helpers.reindex(self.client, "test_index", "prod_index", scan_kwargs={'doc_type': 'answers'}, bulk_kwargs={'refresh': True})
263+
helpers.reindex(self.client, "test_index", "prod_index", scan_kwargs={'q': 'type:answers'}, bulk_kwargs={'refresh': True})
264264

265265
self.assertTrue(self.client.indices.exists("prod_index"))
266-
self.assertFalse(self.client.indices.exists_type(index='prod_index', doc_type='questions'))
267-
self.assertEquals(50, self.client.count(index='prod_index', doc_type='answers')['count'])
266+
self.assertEquals(50, self.client.count(index='prod_index', q='type:answers')['count'])
268267

269-
self.assertEquals({"answer": 42, "correct": True}, self.client.get(index="prod_index", doc_type="answers", id=42)['_source'])
268+
self.assertEquals({"answer": 42, "correct": True, "type": "answers"}, self.client.get(index="prod_index", doc_type="post", id=42)['_source'])
270269

271270
def test_reindex_accepts_a_query(self):
272-
helpers.reindex(self.client, "test_index", "prod_index", query={"query": {"bool": {"filter": {"term": {"_type": "answers"}}}}})
271+
helpers.reindex(self.client, "test_index", "prod_index", query={"query": {"bool": {"filter": {"term": {"type": "answers"}}}}})
273272
self.client.indices.refresh()
274273

275274
self.assertTrue(self.client.indices.exists("prod_index"))
276-
self.assertFalse(self.client.indices.exists_type(index='prod_index', doc_type='questions'))
277-
self.assertEquals(50, self.client.count(index='prod_index', doc_type='answers')['count'])
275+
self.assertEquals(50, self.client.count(index='prod_index', q='type:answers')['count'])
278276

279-
self.assertEquals({"answer": 42, "correct": True}, self.client.get(index="prod_index", doc_type="answers", id=42)['_source'])
277+
self.assertEquals({"answer": 42, "correct": True, "type": "answers"}, self.client.get(index="prod_index", doc_type="post", id=42)['_source'])
280278

281279
def test_all_documents_get_moved(self):
282280
helpers.reindex(self.client, "test_index", "prod_index")
283281
self.client.indices.refresh()
284282

285283
self.assertTrue(self.client.indices.exists("prod_index"))
286-
self.assertEquals(50, self.client.count(index='prod_index', doc_type='questions')['count'])
287-
self.assertEquals(50, self.client.count(index='prod_index', doc_type='answers')['count'])
284+
self.assertEquals(50, self.client.count(index='prod_index', q='type:questions')['count'])
285+
self.assertEquals(50, self.client.count(index='prod_index', q='type:answers')['count'])
288286

289-
self.assertEquals({"answer": 42, "correct": True}, self.client.get(index="prod_index", doc_type="answers", id=42)['_source'])
287+
self.assertEquals({"answer": 42, "correct": True, "type": "answers"}, self.client.get(index="prod_index", doc_type="post", id=42)['_source'])
290288

291289
class TestParentChildReindex(ElasticsearchTestCase):
292290
def setUp(self):
293291
super(TestParentChildReindex, self).setUp()
294292
body={
295293
'settings': {"number_of_shards": 1, "number_of_replicas": 0},
296294
'mappings': {
297-
'question': {
298-
},
299-
'answer': {
300-
'_parent': {'type': 'question'},
295+
'post': {
296+
'properties': {
297+
'question_answer': {
298+
'type': 'join',
299+
'relations': {'question': 'answer'}
300+
}
301+
}
301302
}
302303
}
303304
}
@@ -306,16 +307,16 @@ def setUp(self):
306307

307308
self.client.index(
308309
index='test-index',
309-
doc_type='question',
310+
doc_type='post',
310311
id=42,
311-
body={},
312+
body={'question_answer': 'question'},
312313
)
313314
self.client.index(
314315
index='test-index',
315-
doc_type='answer',
316+
doc_type='post',
316317
id=47,
317-
body={'some': 'data'},
318-
parent=42
318+
routing=42,
319+
body={'some': 'data', 'question_answer': {'name': 'answer', 'parent': 42}},
319320
)
320321
self.client.indices.refresh(index='test-index')
321322

@@ -324,35 +325,33 @@ def test_children_are_reindexed_correctly(self):
324325

325326
q = self.client.get(
326327
index='real-index',
327-
doc_type='question',
328+
doc_type='post',
328329
id=42
329330
)
330331
self.assertEquals(
331332
{
332333
'_id': '42',
333334
'_index': 'real-index',
334-
'_source': {},
335-
'_type': 'question',
335+
'_source': {'question_answer': 'question'},
336+
'_type': 'post',
336337
'_version': 1,
337338
'found': True
338339
}, q
339340
)
340341
q = self.client.get(
341342
index='test-index',
342-
doc_type='answer',
343+
doc_type='post',
343344
id=47,
344-
parent=42
345+
routing=42
345346
)
346-
if '_routing' in q:
347-
self.assertEquals(q.pop('_routing'), '42')
348347
self.assertEquals(
349348
{
349+
'_routing': '42',
350350
'_id': '47',
351351
'_index': 'test-index',
352-
'_source': {'some': 'data'},
353-
'_type': 'answer',
352+
'_source': {'some': 'data', 'question_answer': {'name': 'answer', 'parent': 42}},
353+
'_type': 'post',
354354
'_version': 1,
355-
'_parent': '42',
356355
'found': True
357356
}, q
358357
)

0 commit comments

Comments
 (0)