MCPcopy Index your code
hub / github.com/SourceCode-AI/aura / test_github_cache

Function test_github_cache

tests/test_github.py:40–67  ·  view source on GitHub ↗
(mock_github, mock_cache)

Source from the content-addressed store, hash-verified

38
39@responses.activate
40def test_github_cache(mock_github, mock_cache):
41 mock_github(responses)
42 repo_url = "https://api.github.com/repos/psf/requests"
43 contributors_url = "https://api.github.com/repos/psf/requests/contributors"
44
45 real_session = requests.Session()
46 mock_session = mock.Mock(wraps=real_session, spec=True)
47 _ = github.GitHub.from_url("https://github.com/psf/requests")
48
49 url1_cached = cache.URLCache(url=repo_url)
50 assert url1_cached.is_valid is True
51 assert type(json.loads(url1_cached.fetch())) == dict
52
53 url2_cached = cache.URLCache(url=contributors_url)
54 assert url2_cached.is_valid
55 assert type(json.loads(url2_cached.fetch())) == list
56
57 responses.reset()
58 # Test that the data is cached and does not fire any requests
59 _ = github.GitHub.from_url("https://github.com/psf/requests")
60
61 output = cache.URLCache.proxy(url=repo_url, session=mock_session)
62 assert mock_session.called is False
63 assert type(json.loads(output)) == dict
64
65 output = cache.URLCache.proxy(url=contributors_url, session=mock_session)
66 assert mock_session.called is False
67 assert type(json.loads(output)) == list
68
69
70@responses.activate

Callers

nothing calls this directly

Calls 4

fetchMethod · 0.95
mock_githubFunction · 0.85
from_urlMethod · 0.80
proxyMethod · 0.45

Tested by

no test coverage detected