예제 #1
0
    def test_index_calls_index_or_create_method_with_correct_args(self):
        bulk = self.ss.bulk_operation()
        body = dict(key1='val1')

        bulk._index_or_create = Mock()

        bulk.index(index='test_bulk', doc_type='test_bulk_doc_type', body=body,
                   timeout=200)
        self.assertTrue(bulk._index_or_create)
        self.assertEquals(bulk._index_or_create.call_args[0][0], 'index')
        assertDictEquals(bulk._index_or_create.call_args[0][1], body)
        self.assertEquals(bulk._index_or_create.call_args[0][2], None)
        self.assertEquals(bulk._index_or_create.call_args[1]['timeout'], 200)
        self.assertEquals(bulk._index_or_create.call_args[1]['index'],
                          'test_bulk')
        self.assertEquals(bulk._index_or_create.call_args[1]['doc_type'],
                          'test_bulk_doc_type')
예제 #2
0
    def test_create_calls_index_or_create_method_with_correct_args(self):
        bulk = self.ss.bulk_operation()
        body = dict(key1='val1')

        bulk._index_or_create = Mock()

        bulk.create(doc_type='test_bulk_doc_type', body=body,
                    id=4, timeout=200, routing='abcd')
        self.assertTrue(bulk._index_or_create)
        self.assertEquals(bulk._index_or_create.call_args[0][0], 'create')
        assertDictEquals(bulk._index_or_create.call_args[0][1], body)
        self.assertEquals(bulk._index_or_create.call_args[0][2], 4)
        self.assertEquals(bulk._index_or_create.call_args[1]['timeout'], 200)
        self.assertEquals(bulk._index_or_create.call_args[1]['doc_type'],
                          'test_bulk_doc_type')
        self.assertEquals(bulk._index_or_create.call_args[1]['routing'],
                          'abcd')
예제 #3
0
    def test_update_must_push_correct_action(self):
        bulk = self.ss.bulk_operation()
        body = dict(key1='val1')

        # Without params
        bulk.update(id=123, body=body)
        action = bulk._actions[-1]
        self.assertEquals(action.type, 'update')
        assertDictEquals(action.body, body)
        assertDictEquals(action.params, dict(_id=123))

        # With params
        bulk.update(index='test_index', doc_type='test_doc_type', body=body,
                    id=123, consistency='sync', ttl=200)
        action = bulk._actions[-1]
        self.assertEquals(action.type, 'update')
        assertDictEquals(action.body, body)
        assertDictEquals(action.params, {
            '_index': 'test_index',
            '_type': 'test_doc_type',
            '_id': 123,
            'consistency': 'sync',
            'ttl': '200'
        })
예제 #4
0
    def test_delete_must_push_correct_action(self):
        bulk = self.ss.bulk_operation()
        body = dict(key1='val1')

        # Without params
        bulk.delete(id=123)
        action = bulk._actions[-1]
        self.assertEquals(action.type, 'delete')
        assertDictEquals(action.body, None)
        assertDictEquals(action.params, dict(_id=123))

        # With params
        bulk.delete(index='test_index', doc_type='test_doc_type',
                    id=123, consistency='sync', parent=1)
        action = bulk._actions[-1]
        self.assertEquals(action.type, 'delete')
        assertDictEquals(action.body, None)
        assertDictEquals(action.params, {
            '_index': 'test_index',
            '_type': 'test_doc_type',
            '_id': 123,
            'consistency': 'sync',
            'parent': '1',
        })

        # Make sure delete does not push body even if passed
        bulk.delete(id=123, body=body)
        action = bulk._actions[-1]
        self.assertEquals(action.type, 'delete')
        assertDictEquals(action.body, None)
        assertDictEquals(action.params, dict(_id=123))
예제 #5
0
    def test_index_or_create_must_push_correct_action(self):
        bulk = self.ss.bulk_operation()
        body = dict(key1='val1')

        # Without params
        bulk._index_or_create('index', body)
        action = bulk._actions[-1]
        self.assertEquals(action.type, 'index')
        assertDictEquals(action.body, body)
        assertDictEquals(action.params, {})

        # With params
        bulk._index_or_create('create', doc_type='test_doc_type', body=body,
                              id=1, consistency='sync', ttl=200)
        action = bulk._actions[-1]
        self.assertEquals(action.type, 'create')
        assertDictEquals(action.body, body)
        assertDictEquals(action.params, {
            '_type': 'test_doc_type',
            '_id': 1,
            'consistency': 'sync',
            'ttl': '200'
        })

        bulk._index_or_create('create', index='test_bulk',
                              doc_type='test_doc_type', body=body, 
                              routing='abcd', refresh=True)
        action = bulk._actions[-1]
        self.assertEquals(action.type, 'create')
        assertDictEquals(action.body, body)
        assertDictEquals(action.params, {
            '_index': 'test_bulk',
            '_type': 'test_doc_type',
            'routing': 'abcd',
            'refresh': 'true',
        })