(mock_github, mock_cache)
| 38 | |
| 39 | @responses.activate |
| 40 | def 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 |
nothing calls this directly
no test coverage detected