MCPcopy Create free account
hub / github.com/requests-cache/requests-cache / test_sorted

Method test_sorted

tests/integration/test_sqlite.py:431–453  ·  view source on GitHub ↗

Test wrapper method for SQLiteDict.sorted(), with all arguments combined

(self)

Source from the content-addressed store, hash-verified

429 mock_sorted.assert_called_with(expired=False)
430
431 def test_sorted(self):
432 """Test wrapper method for SQLiteDict.sorted(), with all arguments combined"""
433 session = self.init_session(clear=False)
434 now = utcnow()
435
436 # Insert items with decreasing expiration time
437 for i in range(500):
438 delta = 1000 - i
439 if i > 400:
440 delta -= 2000
441
442 response = CachedResponse(status_code=i, expires=now + timedelta(seconds=delta))
443 session.cache.responses[f'key_{i}'] = response
444
445 # Sorted items should be in ascending order by expiration time
446 items = list(session.cache.sorted(key='expires', expired=False, reversed=True, limit=100))
447 assert len(items) == 100
448
449 prev_item = None
450 for item in items:
451 assert prev_item is None or prev_item.expires < item.expires
452 assert item.cache_key
453 assert not item.is_expired

Callers

nothing calls this directly

Calls 4

utcnowFunction · 0.90
CachedResponseClass · 0.90
init_sessionMethod · 0.80
sortedMethod · 0.45

Tested by

no test coverage detected