mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-08 22:42:05 +00:00
langchain-mongodb: add unit tests for MongoDBChatMessageHistory (#18599)
## Description Adding in Unit Test variation for `MongoDBChatMessageHistory` package Follow-up to #18590 - [x] **Add tests and docs**: Unit test is what's being added - [x] **Lint and test**: Run `make format`, `make lint` and `make test` from the root of the package(s) you've modified. See contribution guidelines for more: https://python.langchain.com/docs/contributing/
This commit is contained in:
@@ -169,18 +169,21 @@ class MockCollection(Collection):
|
||||
[k["_id"] for k in mongodb_inserts], acknowledged=True
|
||||
)
|
||||
|
||||
def insert_one(self, to_insert: Any, *args, **kwargs) -> Any: # type: ignore
|
||||
return self.insert_many([to_insert])
|
||||
|
||||
def find_one(self, find_query: Dict[str, Any]) -> Optional[Dict[str, Any]]: # type: ignore
|
||||
find = self.find(find_query) or [None] # type: ignore
|
||||
return find[0]
|
||||
|
||||
def find(self, find_query: Dict[str, Any]) -> Optional[List[Dict[str, Any]]]: # type: ignore
|
||||
def _is_match(item: Dict[str, Any]) -> bool:
|
||||
for key, match_val in find_query.items():
|
||||
if item.get(key) != match_val:
|
||||
return False
|
||||
return True
|
||||
|
||||
# Return the first element to match
|
||||
for document in self._data:
|
||||
if _is_match(document):
|
||||
return document
|
||||
return None
|
||||
return [document for document in self._data if _is_match(document)]
|
||||
|
||||
def update_one( # type: ignore
|
||||
self,
|
||||
|
Reference in New Issue
Block a user