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

Function test_delete__expired

tests/unit/test_base_cache.py:85–114  ·  view source on GitHub ↗
(mock_normalize_url, mock_session)

Source from the content-addressed store, hash-verified

83@skip_pypy # time-machine doesn't work on PyPy
84@patch_normalize_url
85def test_delete__expired(mock_normalize_url, mock_session):
86 unexpired_url = f'{MOCKED_URL}?x=1'
87 mock_session.mock_adapter.register_uri(
88 'GET', unexpired_url, status_code=200, text='mock response'
89 )
90 mock_session.settings.expire_after = 1
91
92 with time_travel(START_DT):
93 mock_session.get(MOCKED_URL)
94 mock_session.get(MOCKED_URL_JSON)
95
96 mock_session.settings.expire_after = 2
97 with time_travel(START_DT + timedelta(seconds=1.1)):
98 mock_session.get(unexpired_url)
99
100 # At this point we should have 1 unexpired response and 2 expired responses
101 assert len(mock_session.cache.responses) == 3
102
103 # Use the generic BaseCache implementation, not the SQLite-specific one
104 with time_travel(START_DT + timedelta(seconds=2)):
105 BaseCache.delete(mock_session.cache, expired=True)
106 assert len(mock_session.cache.responses) == 1
107
108 cached_response = list(mock_session.cache.responses.values())[0]
109 assert cached_response.url == unexpired_url
110
111 # Now the last response should be expired as well
112 with time_travel(START_DT + timedelta(seconds=4)):
113 BaseCache.delete(mock_session.cache, expired=True)
114 assert len(mock_session.cache.responses) == 0
115
116
117@skip_pypy

Callers

nothing calls this directly

Calls 3

getMethod · 0.80
deleteMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…