summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJordan Cook <jordan.cook@pioneer.com>2022-06-11 20:33:46 -0500
committerJordan Cook <jordan.cook@pioneer.com>2022-06-11 20:46:44 -0500
commita78af0338d9b3a59c33c15e50cd54422ae7489b8 (patch)
tree895809c63f54b556ec9d509270a3f21e54519927 /tests
parent03d83c137d55dc2d168e7716a5b753e8a2cf64ea (diff)
downloadrequests-cache-a78af0338d9b3a59c33c15e50cd54422ae7489b8.tar.gz
Clean up SQLiteCache convenience methods a bit
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/test_sqlite.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/tests/integration/test_sqlite.py b/tests/integration/test_sqlite.py
index 54b0ceb..580948b 100644
--- a/tests/integration/test_sqlite.py
+++ b/tests/integration/test_sqlite.py
@@ -211,7 +211,7 @@ class TestSQLiteDict(BaseStorageTest):
cache[f'key_{i}'] = response
# Items should only include unexpired (even numbered) items, and still be in sorted order
- items = list(cache.sorted(key='expires', exclude_expired=True))
+ items = list(cache.sorted(key='expires', expired=False))
assert len(items) == 50
prev_item = None
@@ -272,6 +272,13 @@ class TestSQLiteCache(BaseCacheTest):
session = self.init_session()
assert session.cache.db_path == session.cache.responses.db_path
+ @patch.object(SQLiteDict, 'sorted')
+ def test_filter__expired_only(self, mock_sorted):
+ """Filtering by expired only should use a more efficient SQL query"""
+ session = self.init_session()
+ session.cache.filter(valid=False, expired=True)
+ mock_sorted.assert_called_once_with(expired=True)
+
def test_sorted(self):
"""Test wrapper method for SQLiteDict.sorted(), with all arguments combined"""
session = self.init_session(clear=False)
@@ -287,9 +294,7 @@ class TestSQLiteCache(BaseCacheTest):
session.cache.responses[f'key_{i}'] = response
# Sorted items should be in ascending order by expiration time
- items = list(
- session.cache.sorted(key='expires', exclude_expired=True, reversed=True, limit=100)
- )
+ items = list(session.cache.sorted(key='expires', expired=False, reversed=True, limit=100))
assert len(items) == 100
prev_item = None