Skip to content

Commit

Permalink
Fixes python2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Bob Corsaro committed Feb 4, 2016
1 parent d63c781 commit 15aa2b6
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions tests/test_elasticsearch.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import unittest2 as unittest
import json
from tubing.ext import elasticsearch
from tubing import sinks, sources, pipe

EXPECTED = b"""{"update": {"_type": "test", "_id": "id0"}}
{"doc": {"name": "id0"}, "doc_as_upsert": true}
{"update": {"_type": "test-child", "_id": "id1", "parent": "id0"}}
{"doc": {"name": "id1"}, "doc_as_upsert": false}
"""
EXPECTED = [{"update": {"_id": "id0", "_type": "test"}},
{"doc": {"name": "id0"}, "doc_as_upsert": True},
{"update": {"_id": "id1", "_type": "test-child", "parent": "id0"}},
{"doc": {"name": "id1"}, "doc_as_upsert": False}]

class ElasticSearchTestCase(unittest.TestCase):
def test_es(self):
Expand All @@ -18,14 +18,19 @@ def test_es(self):
sink.done()

buffer0.seek(0)
self.assertEqual(EXPECTED, buffer0.getvalue())
f = []
for line in buffer0.getvalue().split(b'\n'):
if line:
f.append(json.loads(line.decode('utf-8')))

self.assertEqual(EXPECTED, f)

def test_batching(self):
buffer0 = sinks.BytesIOSink()
sink = elasticsearch.BulkBatcherSink(buffer0, batch_size=50)

def make_du(i):
esid = 'id{}'.format(i)
esid = 'id%d'%i
return elasticsearch.DocUpdate(
esid=esid,
doc=dict(name=esid),
Expand Down

0 comments on commit 15aa2b6

Please sign in to comment.