fixed pymongo tests, update_data method should not delete document when {} was passed

This commit is contained in:
kievzenit 2025-08-11 18:33:14 +03:00
parent bf67e8d896
commit dbf6b535f8

View file

@ -54,8 +54,12 @@ async def test_update_existing_data_with_empty_dictionary(
):
assert await pymongo_storage._collection.find_one({}) is None
await pymongo_storage.set_data(key=storage_key, data={"key": "value"})
assert await pymongo_storage.update_data(key=storage_key, data={}) == {}
assert await pymongo_storage._collection.find_one({}) is None
assert await pymongo_storage.update_data(key=storage_key, data={}) == {"key": "value"}
assert await pymongo_storage._collection.find_one({}) == {
"_id": f"{PREFIX}:{CHAT_ID}:{USER_ID}",
"data": {"key": "value"},
}
await pymongo_storage._collection.delete_one({})
async def test_update_existing_data_with_non_empty_dictionary(
@ -170,9 +174,10 @@ class TestStateAndDataDoNotAffectEachOther:
"state": "test",
"data": {"key": "value"},
}
assert await pymongo_storage.update_data(key=storage_key, data={}) == {}
assert await pymongo_storage.update_data(key=storage_key, data={}) == {"key": "value"}
assert await pymongo_storage._collection.find_one({}, projection={"_id": 0}) == {
"state": "test",
"data": {"key": "value"},
}
async def test_state_do_not_affect_to_updating_existing_data_with_non_empty_dictionary(