def test_missing_cached_entry(self) -> None: path = Path(self.tmp.name).joinpath("vulns01.json") self._write_cache(path, time.time()) with patch("ossaudit.const.CACHE", path): entry = cache.get("pkg:pypi/[email protected]") self.assertIsNone(entry)
def test_have_old_cached_entry(self) -> None: path = Path(self.tmp.name).joinpath("vulns01.json") self._write_cache(path, time.time() + const.CACHE_TIME + 1) with patch("ossaudit.const.CACHE", path): entry = cache.get("pkg:pypi/[email protected]") self.assertIsNone(entry)
def test_have_cached_entry(self) -> None: path = Path(self.tmp.name).joinpath("vulns01.json") self._write_cache(path, time.time()) with patch("ossaudit.const.CACHE", path): entry = cache.get("pkg:pypi/[email protected]") or {} self.assertEqual(entry["coordinates"], "pkg:pypi/[email protected]")
def test_ignore_invalid(self) -> None: path = Path(self.tmp.name).joinpath("vulns01.json") path.write_text("foo") entry = {"coordinates": "abcd"} with patch("ossaudit.const.CACHE", path): cache.save(entry) entry["time"] = ANY self.assertEqual(cache.get("abcd"), entry)
def test_no_cache(self) -> None: self.assertIsNone(cache.get("x"))
def test_invalid_cache(self) -> None: path = Path(self.tmp.name).joinpath("invalid.json") path.write_text("abcd") with patch("ossaudit.const.CACHE", path): self.assertIsNone(cache.get("foo"))