Esempio n. 1
0
async def test_async_single_query(es_data, async_engine):
    """ """
    builder = Q_(resource="ChargeItem", engine=async_engine)
    builder = builder.where(exists_("ChargeItem.enteredDate"))

    result = await builder().single()
    assert result is not None
    assert isinstance(result, EngineResultRow)
    # test empty result
    builder = Q_(resource="ChargeItem", engine=async_engine)
    builder = builder.where(not_(exists_("ChargeItem.enteredDate")))

    result = await builder().single()
    assert result is None

    # Test Multiple Result error
    conn, meta_info = es_data
    load_organizations_data(conn, 2)

    builder = Q_(resource="Organization", engine=async_engine)
    builder = builder.where(T_("Organization.active", "true"))

    with pytest.raises(MultipleResultsFound) as excinfo:
        await builder().single()
    assert excinfo.type == MultipleResultsFound
Esempio n. 2
0
async def test_single_query(es_requester):
    """ """
    async with es_requester as requester:
        container, request, txn, tm = await setup_txn_on_container(requester
                                                                   )  # noqa
        # init primary data
        await init_data(requester)
        await load_organizations_data(requester, 2)
        engine = query_utility(IElasticsearchEngineFactory).get()

        index_name = await engine.get_index_name(container)

        conn = engine.connection.raw_connection
        await conn.indices.refresh(index=index_name)

        builder = Q_(resource="ChargeItem", engine=engine)
        builder = builder.where(exists_("ChargeItem.enteredDate"))

        result = await builder(async_result=True).single()
        assert result is not None
        assert result[0]["resourceType"] == builder._from[0][0]
        # test empty result
        builder = Q_(resource="ChargeItem", engine=engine)
        builder = builder.where(not_(exists_("ChargeItem.enteredDate")))

        result = await builder(async_result=True).single()
        assert result is None

        # Test Multiple Result error
        builder = Q_(resource="Organization", engine=engine)
        builder = builder.where(T_("Organization.active", "true"))

        with pytest.raises(MultipleResultsFound) as excinfo:
            await builder(async_result=True).single()
        assert excinfo.type == MultipleResultsFound
Esempio n. 3
0
def test_exists_query(es_data, engine):
    """ enteredDate"""
    builder = Q_(resource="ChargeItem", engine=engine)
    builder = builder.where(exists_("ChargeItem.enteredDate"))

    result = builder().fetchall()
    assert result.header.total == 1
Esempio n. 4
0
async def test_exists_query(es_requester):
    """ enteredDate"""
    async with es_requester as requester:
        container, request, txn, tm = await setup_txn_on_container(requester
                                                                   )  # noqa
        # init primary data
        await init_data(requester)
        engine = query_utility(IElasticsearchEngineFactory).get()

        index_name = await engine.get_index_name(container)

        conn = engine.connection.raw_connection
        await conn.indices.refresh(index=index_name)

        builder = Q_(resource="ChargeItem", engine=engine)
        builder = builder.where(exists_("ChargeItem.enteredDate"))

        result = await builder(async_result=True).fetchall()
        assert result.header.total == 1