diff options
author | Jordan Cook <jordan.cook@pioneer.com> | 2022-04-21 11:47:22 -0500 |
---|---|---|
committer | Jordan Cook <jordan.cook@pioneer.com> | 2022-04-21 13:50:50 -0500 |
commit | 826738d5254b8ca2a24ba0c1630914529efc2bfc (patch) | |
tree | a420080078deac6e378f7c6aa6d132e597ec4ac8 /tests | |
parent | 67dd63cfa7904b2e746728882d64414c94364490 (diff) | |
download | requests-cache-826738d5254b8ca2a24ba0c1630914529efc2bfc.tar.gz |
Fix parameter forwarding for redis-py 4.2 and pymongo 4.1 on python <=3.8
Diffstat (limited to 'tests')
-rw-r--r-- | tests/integration/test_mongodb.py | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/tests/integration/test_mongodb.py b/tests/integration/test_mongodb.py index 7db3f8c..262ddd6 100644 --- a/tests/integration/test_mongodb.py +++ b/tests/integration/test_mongodb.py @@ -5,9 +5,7 @@ from unittest.mock import patch import pytest from gridfs import GridFS from gridfs.errors import CorruptGridFile, FileExists -from pymongo import MongoClient -from requests_cache._utils import get_valid_kwargs from requests_cache.backends import ( GridFSCache, GridFSPickleDict, @@ -44,15 +42,20 @@ class TestMongoPickleDict(BaseStorageTest): storage_class = MongoDocumentDict picklable = True - @patch('requests_cache.backends.mongodb.MongoClient') - @patch( - 'requests_cache.backends.mongodb.get_valid_kwargs', - side_effect=lambda cls, kwargs: get_valid_kwargs(MongoClient, kwargs), - ) - def test_connection_kwargs(self, mock_get_valid_kwargs, mock_client): + def test_connection_kwargs(self): """A spot check to make sure optional connection kwargs gets passed to connection""" - MongoDict('test', host='http://0.0.0.0', port=1234, invalid_kwarg='???') - mock_client.assert_called_with(host='http://0.0.0.0', port=1234) + # MongoClient prevents direct access to private members like __init_kwargs; + # need to test indirectly using its repr + cache = MongoDict( + 'test', + host='mongodb://0.0.0.0', + port=2222, + tz_aware=True, + connect=False, + invalid_kwarg='???', + ) + assert "host=['0.0.0.0:2222']" in repr(cache.connection) + assert "tz_aware=True" in repr(cache.connection) class TestMongoCache(BaseCacheTest): @@ -115,16 +118,18 @@ class TestGridFSPickleDict(BaseStorageTest): picklable = True num_instances = 1 # Only test a single collecton instead of multiple - @patch('requests_cache.backends.gridfs.GridFS') - @patch('requests_cache.backends.gridfs.MongoClient') - @patch( - 'requests_cache.backends.gridfs.get_valid_kwargs', - side_effect=lambda cls, kwargs: get_valid_kwargs(MongoClient, kwargs), - ) - def test_connection_kwargs(self, mock_get_valid_kwargs, mock_client, mock_gridfs): + def test_connection_kwargs(self): """A spot check to make sure optional connection kwargs gets passed to connection""" - GridFSPickleDict('test', host='http://0.0.0.0', port=1234, invalid_kwarg='???') - mock_client.assert_called_with(host='http://0.0.0.0', port=1234) + cache = GridFSPickleDict( + 'test', + host='mongodb://0.0.0.0', + port=2222, + tz_aware=True, + connect=False, + invalid_kwarg='???', + ) + assert "host=['0.0.0.0:2222']" in repr(cache.connection) + assert "tz_aware=True" in repr(cache.connection) def test_corrupt_file(self): """A corrupted file should be handled and raise a KeyError instead""" |