# Path: elasticmagic/actions.py
# class Create(Action):
#     __action_name__ = 'create'
# 
# Path: elasticmagic/actions.py
# class Delete(Action):
#     __action_name__ = 'delete'
# 
#     def get_source(self):
#         pass
# 
# Path: elasticmagic/actions.py
# class Index(Action):
#     __action_name__ = 'index'
# 
# Path: elasticmagic/actions.py
# class Update(Action):
#     __action_name__ = 'update'
# 
#     def __init__(self, doc=None, script=None, script_id=None,
#                  index=None, doc_type=None,
#                  consistency=None, refresh=None,
#                  routing=None, parent=None,
#                  timestamp=None, ttl=None,
#                  version=None, version_type=None,
#                  detect_noop=None, retry_on_conflict=None,
#                  upsert=None, doc_as_upsert=None,
#                  scripted_upsert=None, params=None,
#                  **kwargs):
#         super(Update, self).__init__(
#             doc or {},
#             index=index,
#             doc_type=doc_type,
#             consistency=consistency,
#             refresh=refresh,
#             routing=routing,
#             parent=parent,
#             timestamp=timestamp,
#             ttl=ttl,
#             version=version,
#             version_type=version_type,
#             retry_on_conflict=retry_on_conflict,
#             **kwargs
#         )
#         self.source_params = clean_params({
#             'detect_noop': detect_noop,
#             'upsert': upsert,
#             'doc_as_upsert': doc_as_upsert,
#             'scripted_upsert': scripted_upsert,
#             'params': params,
#             'script': script,
#             'script_id': script_id,
#         })
# 
# Path: tests_integ/asyncio/conftest.py
# def event_loop(request):
# async def es_client(event_loop, es_url):
# def es_cluster(es_client):
# async def es_index(es_cluster, es_client, index_name):
# async def cars(es_index, car_docs):
# async def all_cars(es_index, all_car_docs):


import pytest
from elasticmagic.actions import Create
from elasticmagic.actions import Delete
from elasticmagic.actions import Index
from elasticmagic.actions import Update
from .conftest import Car
    doc = await es_index.get(1, doc_cls=Car, routing=2)
    assert doc._id == '1'
    assert doc._routing == '2'
    assert doc._version == 1
    assert doc.name == 'Doc Hudson'

    await es_index.bulk(
        [
            Delete(Car(_id=1, _routing=2))
        ],
        refresh=True,
    )
    assert (await es_index.count()).count == 0


@pytest.mark.asyncio
async def test_bulk_update_params(es_index):
    res = await es_index.bulk(
        [
            Update(
                Car(_id=1, name='Doc Hudson'),
                doc_as_upsert=True,
                retry_on_conflict=2,
            )
        ],
        refresh=True
    )
    assert not res.errors
    assert res.items[0].status == 201


# Path: elasticmagic/actions.py
# class Create(Action):
#     __action_name__ = 'create'
# 
# Path: elasticmagic/actions.py
# class Delete(Action):
#     __action_name__ = 'delete'
# 
#     def get_source(self):
#         pass
# 
# Path: elasticmagic/actions.py
# class Index(Action):
#     __action_name__ = 'index'
# 
# Path: elasticmagic/actions.py
# class Update(Action):
#     __action_name__ = 'update'
# 
#     def __init__(self, doc=None, script=None, script_id=None,
#                  index=None, doc_type=None,
#                  consistency=None, refresh=None,
#                  routing=None, parent=None,
#                  timestamp=None, ttl=None,
#                  version=None, version_type=None,
#                  detect_noop=None, retry_on_conflict=None,
#                  upsert=None, doc_as_upsert=None,
#                  scripted_upsert=None, params=None,
#                  **kwargs):
#         super(Update, self).__init__(
#             doc or {},
#             index=index,
#             doc_type=doc_type,
#             consistency=consistency,
#             refresh=refresh,
#             routing=routing,
#             parent=parent,
#             timestamp=timestamp,
#             ttl=ttl,
#             version=version,
#             version_type=version_type,
#             retry_on_conflict=retry_on_conflict,
#             **kwargs
#         )
#         self.source_params = clean_params({
#             'detect_noop': detect_noop,
#             'upsert': upsert,
#             'doc_as_upsert': doc_as_upsert,
#             'scripted_upsert': scripted_upsert,
#             'params': params,
#             'script': script,
#             'script_id': script_id,
#         })
# 
# Path: tests_integ/asyncio/conftest.py
# def event_loop(request):
# async def es_client(event_loop, es_url):
# def es_cluster(es_client):
# async def es_index(es_cluster, es_client, index_name):
# async def cars(es_index, car_docs):
# async def all_cars(es_index, all_car_docs):


# Path: tests_integ/asyncio/test_bulk.py
import pytest
from elasticmagic.actions import Create
from elasticmagic.actions import Delete
from elasticmagic.actions import Index
from elasticmagic.actions import Update
from .conftest import Car

    doc = await es_index.get(1, doc_cls=Car, routing=2)
    assert doc._id == '1'
    assert doc._routing == '2'
    assert doc._version == 1
    assert doc.name == 'Doc Hudson'

    await es_index.bulk(
        [
            Delete(Car(_id=1, _routing=2))
        ],
        refresh=True,
    )
    assert (await es_index.count()).count == 0


@pytest.mark.asyncio
async def test_bulk_update_params(es_index):
    res = await es_index.bulk(
        [
            Update(
                Car(_id=1, name='Doc Hudson'),
                doc_as_upsert=True,
                retry_on_conflict=2,
            )
        ],
        refresh=True
    )
    assert not res.errors
    assert res.items[0].status == 201


    doc = await es_index.get(1, doc_cls=Car)