Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alessio committed Feb 1, 2024
1 parent d053a84 commit 4e4e21a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/querytyper/mongo/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,13 @@ def __contains__(
other: T,
) -> QueryCondition:
"""Overload in operator."""
return regex_query(self.name, re.compile(other))
if not issubclass(cast(type, self.field_type), str):
raise TypeError(
f"Cannot check if field {self.name} contains {other} because {self.name} is not a subclass of str but {self.field_type}"
)
if not isinstance(other, str):
raise ValueError("Comparison value must be a valid string.")
return self == {"$regex": other}


def exists(
Expand Down
2 changes: 1 addition & 1 deletion tests/mongo/test_pymongo_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ def test_integration_with_pymongo() -> None:
assert found_dummy.int_field == 1
query = MongoQuery("test" in QueryModel.str_field)
assert isinstance(query, dict)
# assert query
assert query
found_docs = list(collection.find(query))
assert len(found_docs) == doc_num

0 comments on commit 4e4e21a

Please sign in to comment.