File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -192,6 +192,9 @@ def __eq__(self, other):
192
192
def __getattr__ (self , name ):
193
193
return getattr (self .__collection , name )
194
194
195
+ def __hash__ (self ):
196
+ return hash (self .__collection )
197
+
195
198
def find (self , * args , ** kwargs ) -> AsyncCursor :
196
199
return AsyncCursor (self .__collection .find (* args , ** kwargs ))
197
200
@@ -269,6 +272,9 @@ def __getattr__(self, name):
269
272
270
273
return self .get_collection (name )
271
274
275
+ def __hash__ (self ):
276
+ return hash (self .__database )
277
+
272
278
273
279
@masquerade_class ('motor.motor_asyncio.AsyncIOMotorClient' )
274
280
@with_async_methods (
@@ -317,6 +323,9 @@ def __getattr__(self, name):
317
323
318
324
return self .get_database (name )
319
325
326
+ def __hash__ (self ):
327
+ return hash (self .__client )
328
+
320
329
321
330
@contextmanager
322
331
def enabled_gridfs_integration ():
Original file line number Diff line number Diff line change
1
+ import pytest
2
+
3
+ from mongomock_motor import AsyncMongoMockClient
4
+
5
+
6
+ @pytest .mark .anyio
7
+ async def test_hashing_is_possible ():
8
+ hash (AsyncMongoMockClient ())
9
+ hash (AsyncMongoMockClient ()['database' ])
10
+ hash (AsyncMongoMockClient ()['database' ]['collection' ])
11
+
12
+
13
+ @pytest .mark .anyio
14
+ async def test_hashing_is_stable ():
15
+ assert hash (AsyncMongoMockClient ()) == hash (AsyncMongoMockClient ())
16
+ assert hash (AsyncMongoMockClient ('localhost' )) == hash (
17
+ AsyncMongoMockClient ('not.localhost' )
18
+ )
19
+ assert hash (AsyncMongoMockClient ()['database1' ]) == hash (
20
+ AsyncMongoMockClient ()['database1' ]
21
+ )
22
+ assert hash (AsyncMongoMockClient ()['database1' ]) != hash (
23
+ AsyncMongoMockClient ()['database2' ]
24
+ )
You can’t perform that action at this time.
0 commit comments