Skip to content

Commit

Permalink
add system tests for != null and != nan
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-sanche committed Dec 20, 2024
1 parent ce9ef67 commit 0e205d8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/system/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,10 @@ def test_query_unary(client, cleanup, database):
# Add to clean-up.
cleanup(document1.delete)

_, document2 = collection.add({field_name: 123})
# Add to clean-up.
cleanup(document2.delete)

# 0. Query for null.
query0 = collection.where(filter=FieldFilter(field_name, "==", None))
values0 = list(query0.stream())
Expand Down
21 changes: 21 additions & 0 deletions tests/system/test_system_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,10 @@ async def test_query_unary(client, cleanup, database):
# Add to clean-up.
cleanup(document1.delete)

_, document2 = await collection.add({field_name: 123})
# Add to clean-up.
cleanup(document2.delete)

# 0. Query for null.
query0 = collection.where(filter=FieldFilter(field_name, "==", None))
values0 = [i async for i in query0.stream()]
Expand All @@ -1462,6 +1466,23 @@ async def test_query_unary(client, cleanup, database):
assert len(data1) == 1
assert math.isnan(data1[field_name])

# 2. Query for not null
query2 = collection.where(filter=FieldFilter(field_name, "!=", None))
values2 = [i async for i in query2.stream()]
assert len(values2) == 2
# should fetch documents 1 (NaN) and 2 (int)
assert any(snapshot.reference._path == document1._path for snapshot in values2)
assert any(snapshot.reference._path == document2._path for snapshot in values2)

# 3. Query for not NAN.
query3 = collection.where(filter=FieldFilter(field_name, "!=", nan_val))
values3 = [i async for i in query3.stream()]
assert len(values3) == 1
snapshot3 = values3[0]
assert snapshot3.reference._path == document2._path
# only document2 is not NaN
assert snapshot3.to_dict() == {field_name: 123}


@pytest.mark.parametrize("database", [None, FIRESTORE_OTHER_DB], indirect=True)
async def test_collection_group_queries(client, cleanup, database):
Expand Down

0 comments on commit 0e205d8

Please sign in to comment.