| 44 | ("testpkg_file", "pkg_content", "mirror_testpkg_file", cache.MirrorFile.proxy) |
| 45 | )) |
| 46 | def test_proxy_mirror_json(cache_mock, tmp_path, filename, content, cache_id, call): |
| 47 | f = tmp_path / filename |
| 48 | cache_path = tmp_path / "cache" |
| 49 | cache_path.mkdir() |
| 50 | |
| 51 | cache_file = cache_path/cache_id |
| 52 | cache_mock.return_value = cache_path |
| 53 | |
| 54 | assert f.exists() is False |
| 55 | out = call(src=f) |
| 56 | assert out == f |
| 57 | assert cache_file.exists() is False |
| 58 | assert len(list(cache_path.iterdir())) == 0 |
| 59 | |
| 60 | f.write_text(content) |
| 61 | assert f.exists() is True |
| 62 | out = call(src=f) |
| 63 | assert out != f |
| 64 | assert out == cache_file |
| 65 | assert len(list(x for x in cache_path.iterdir() if not x.name.endswith(".metadata.json"))) == 1 |
| 66 | assert out.read_text() == content |
| 67 | |
| 68 | # Make sure the cache does not attempt to do any kind of file access if the cache entry exists |
| 69 | m = mock.MagicMock(spec_set=("name",), side_effect=ValueError("Call prohibited")) |
| 70 | m.name = filename |
| 71 | out = call(src=m) |
| 72 | assert out == cache_file |
| 73 | |
| 74 | # Original path should be returned if cache is disabled |
| 75 | cache_mock.return_value = None |
| 76 | out = call(src=f) |
| 77 | assert out == f |
| 78 | |
| 79 | |
| 80 | @pytest.mark.e2e |