diff options
author | Jordan Cook <jordan.cook.git@proton.me> | 2022-10-28 12:46:19 -0500 |
---|---|---|
committer | Jordan Cook <jordan.cook.git@proton.me> | 2022-10-28 17:38:28 -0500 |
commit | 81929b18b11c72dbf7d95b7358b9cb1e0b395c2c (patch) | |
tree | 2fe4e51cffe2135285b35aaed8d3c1688a048c0a /tests | |
parent | 03a97079839a5683b202e3ea3f66e8ce54eedab4 (diff) | |
download | requests-cache-81929b18b11c72dbf7d95b7358b9cb1e0b395c2c.tar.gz |
Add SQLite method to count unexpired responses in SQL
Diffstat (limited to 'tests')
-rw-r--r-- | tests/integration/test_sqlite.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/tests/integration/test_sqlite.py b/tests/integration/test_sqlite.py index 7e31634..9aeaa3f 100644 --- a/tests/integration/test_sqlite.py +++ b/tests/integration/test_sqlite.py @@ -297,6 +297,16 @@ class TestSQLiteCache(BaseCacheTest): session = self.init_session() assert session.cache.db_path == session.cache.responses.db_path + def test_count(self): + """count() should work the same as len(), but with the option to exclude expired responses""" + session = self.init_session() + now = datetime.utcnow() + session.cache.responses['key_1'] = CachedResponse(expires=now + timedelta(1)) + session.cache.responses['key_2'] = CachedResponse(expires=now - timedelta(1)) + + assert session.cache.count() == 2 + assert session.cache.count(expired=False) == 1 + @patch.object(SQLiteDict, 'sorted') def test_filter__expired_only(self, mock_sorted): """Filtering by expired only should use a more efficient SQL query""" |