def test_safe_delete_no_perms(self, tmpdir): cache_dir = tmpdir.join("unreadable-cache") cache_dir.makedirs() os.chmod(cache_dir, 000) cache = SafeFileCache(cache_dir) cache.delete("foo")
def test_cache_hashes_are_same(self, cache_tmpdir): cache = SafeFileCache(cache_tmpdir) key = "test key" fake_cache = Mock( FileCache, directory=cache.directory, encode=FileCache.encode ) assert cache._get_cache_path(key) == FileCache._fn(fake_cache, key)
def test_safe_set_no_perms(self, tmpdir): cache_dir = tmpdir.join("unreadable-cache") cache_dir.makedirs() os.chmod(cache_dir, 000) cache = SafeFileCache(cache_dir) cache.set("foo", b"bar")
def test_safe_get_no_perms(self, cache_tmpdir, monkeypatch): os.chmod(cache_tmpdir, 000) monkeypatch.setattr(os.path, "exists", lambda x: True) cache = SafeFileCache(cache_tmpdir) cache.get("foo")
def test_safe_get_no_perms(self, tmpdir, monkeypatch): cache_dir = tmpdir.join("unreadable-cache") cache_dir.makedirs() os.chmod(cache_dir, 000) monkeypatch.setattr(os.path, "exists", lambda x: True) cache = SafeFileCache(cache_dir) cache.get("foo")
def test_cache_roundtrip(self, cache_tmpdir): cache = SafeFileCache(cache_tmpdir) assert cache.get("test key") is None cache.set("test key", b"a test string") assert cache.get("test key") == b"a test string" cache.delete("test key") assert cache.get("test key") is None
def test_cache_roundtrip(self, tmpdir): cache_dir = tmpdir.join("test-cache") cache_dir.makedirs() cache = SafeFileCache(cache_dir) assert cache.get("test key") is None cache.set("test key", b"a test string") assert cache.get("test key") == b"a test string" cache.delete("test key") assert cache.get("test key") is None
def test_safe_delete_no_perms(self, cache_tmpdir): os.chmod(cache_tmpdir, 000) cache = SafeFileCache(cache_tmpdir) cache.delete("foo")
def test_safe_set_no_perms(self, cache_tmpdir): os.chmod(cache_tmpdir, 000) cache = SafeFileCache(cache_tmpdir) cache.set("foo", b"bar")