BeanieODM / beanie

Asynchronous Python ODM for MongoDB
http://beanie-odm.dev/
Apache License 2.0
1.9k stars 201 forks source link

test #900

Closed CAPITAINMARVEL closed 3 months ago

CAPITAINMARVEL commented 3 months ago

test

CAPITAINMARVEL commented 3 months ago

I think its good in term of type hint without changing behavior i dont know maybe its worth a test

CAPITAINMARVEL commented 3 months ago

@roman-right

CAPITAINMARVEL commented 3 months ago

=================================== FAILURES =================================== ___ test_set ___

session = AsyncIOMotorClientSession(<pymongo.client_session.ClientSession object at 0xffffa0484a30>)

async def test_set(session):
    q = Sample.find_many(Sample.integer == 1).set(
        {Sample.integer: 100}, session=session
    )
  assert isinstance(q, UpdateQuery)

E assert False E + where False = isinstance(<coroutine object UpdateMethods.set at 0xffffa0236570>, UpdateQuery)

tests/odm/query/test_update_methods.py:11: AssertionError __ test_current_date ___

session = AsyncIOMotorClientSession(<pymongo.client_session.ClientSession object at 0xffffa8140d90>)

async def test_current_date(session):
    q = Sample.find_many(Sample.integer == 1).current_date(
        {Sample.timestamp: "timestamp"}, session=session
    )
  assert isinstance(q, UpdateQuery)

E assert False E + where False = isinstance(<coroutine object UpdateMethods.current_date at 0xffffa024f530>, UpdateQuery)

tests/odm/query/test_update_methods.py:37: AssertionError ___ test_inc ___

session = AsyncIOMotorClientSession(<pymongo.client_session.ClientSession object at 0xffffa0486440>)

async def test_inc(session):
    q = Sample.find_many(Sample.integer == 1).inc(
        {Sample.integer: 100}, session=session
    )
  assert isinstance(q, UpdateQuery)

E assert False E + where False = isinstance(<coroutine object UpdateMethods.inc at 0xffffa0236ab0>, UpdateQuery)

tests/odm/query/test_update_methods.py:63: AssertionError ____ test_findone ____

documents = <function documents..generate_documents at 0xffffa0714310>

async def test_find_one(documents):
    await documents(5)
    doc = await DocumentTestModel.find_one(DocumentTestModel.test_int == 1)
    await DocumentTestModel.find_one(DocumentTestModel.test_int == 1).set(
        {DocumentTestModel.test_str: "NEW_VALUE"}
    )
    new_doc = await DocumentTestModel.find_one(DocumentTestModel.test_int == 1)
    assert doc == new_doc

    new_doc = await DocumentTestModel.find_one(
        DocumentTestModel.test_int == 1, ignore_cache=True
    )
  assert doc != new_doc

E AssertionError: assert DocumentTestModel(id=ObjectId('6604767613003d38d90d9567'), revision_id=None, test_int=1, test_doc=SubDocument(test_str...42), test_str='kipasa', test_list=[SubDocument(test_str='foo', test_int=42), SubDocument(test_str='bar', test_int=42)]) != DocumentTestModel(id=ObjectId('6604767613003d38d90d9567'), revision_id=None, test_int=1, test_doc=SubDocument(test_str...42), test_str='kipasa', test_list=[SubDocument(test_str='foo', test_int=42), SubDocument(test_str='bar', test_int=42)])

tests/odm/test_cache.py:18: AssertionError ____ test_find_many ____

documents = <function documents..generate_documents at 0xffffa0717640>

async def test_find_many(documents):
    await documents(5)
    docs = await DocumentTestModel.find(
        DocumentTestModel.test_int > 1
    ).to_list()

    await DocumentTestModel.find(DocumentTestModel.test_int > 1).set(
        {DocumentTestModel.test_str: "NEW_VALUE"}
    )

    new_docs = await DocumentTestModel.find(
        DocumentTestModel.test_int > 1
    ).to_list()
    assert docs == new_docs

    new_docs = await DocumentTestModel.find(
        DocumentTestModel.test_int > 1, ignore_cache=True
    ).to_list()
  assert docs != new_docs

E AssertionError: assert [DocumentTestModel(id=ObjectId('6604767713003d38d90d956e'), revision_id=None, test_int=2, test_doc=SubDocument(test_st...2), test_str='kipasa', test_list=[SubDocument(test_str='foo', test_int=42), SubDocument(test_str='bar', test_int=42)])] != [DocumentTestModel(id=ObjectId('6604767713003d38d90d956e'), revision_id=None, test_int=2, test_doc=SubDocument(test_st...2), test_str='kipasa', test_list=[SubDocument(test_str='foo', test_int=42), SubDocument(test_str='bar', test_int=42)])]

tests/odm/test_cache.py:44: AssertionError ___ test_aggregation ___

documents = <function documents..generate_documents at 0xffffa0716200>

async def test_aggregation(documents):
    await documents(5)
    docs = await DocumentTestModel.aggregate(
        [{"$group": {"_id": "$test_str", "total": {"$sum": "$test_int"}}}]
    ).to_list()

    await DocumentTestModel.find(DocumentTestModel.test_int > 1).set(
        {DocumentTestModel.test_str: "NEW_VALUE"}
    )

    new_docs = await DocumentTestModel.aggregate(
        [{"$group": {"_id": "$test_str", "total": {"$sum": "$test_int"}}}]
    ).to_list()
    assert docs == new_docs

    new_docs = await DocumentTestModel.aggregate(
        [{"$group": {"_id": "$test_str", "total": {"$sum": "$test_int"}}}],
        ignore_cache=True,
    ).to_list()
  assert docs != new_docs

E AssertionError: assert [{'_id': 'kipasa', 'total': 10}] != [{'_id': 'kipasa', 'total': 10}]

tests/odm/test_cache.py:73: AssertionError ____ testcapacity ____

documents = <function documents..generate_documents at 0xffffa05b96c0>

async def test_capacity(documents):
    await documents(10)
    docs = []
    for i in range(10):
        docs.append(
            await DocumentTestModel.find_one(DocumentTestModel.test_int == i)
        )

    await DocumentTestModel.find_one(DocumentTestModel.test_int == 1).set(
        {DocumentTestModel.test_str: "NEW_VALUE"}
    )
    await DocumentTestModel.find_one(DocumentTestModel.test_int == 9).set(
        {DocumentTestModel.test_str: "NEW_VALUE"}
    )

    new_doc = await DocumentTestModel.find_one(DocumentTestModel.test_int == 1)
  assert docs[1] != new_doc

E AssertionError: assert DocumentTestModel(id=ObjectId('6604767913003d38d90d9579'), revision_id=None, test_int=1, test_doc=SubDocument(test_str...42), test_str='kipasa', test_list=[SubDocument(test_str='foo', test_int=42), SubDocument(test_str='bar', test_int=42)]) != DocumentTestModel(id=ObjectId('6604767913003d38d90d9579'), revision_id=None, test_int=1, test_doc=SubDocument(test_str...42), test_str='kipasa', test_list=[SubDocument(test_str='foo', test_int=42), SubDocument(test_str='bar', test_int=42)])

tests/odm/test_cache.py:99: AssertionError

I got all those error