Esempio n. 1
0
 def test_save_cache(self, cli_fs_runner):
     with open(".cache_ggshield", "w") as file:
         json.dump({}, file)
     cache = Cache()
     cache.update_cache(last_found_secrets=["XXX"])
     cache.save()
     with open(".cache_ggshield", "r") as file:
         file_content = json.load(file)
         assert file_content == {"last_found_secrets": ["XXX"]}
Esempio n. 2
0
    def test_save_cache_first_time(self, isolated_fs, with_entry):
        """
        GIVEN no existing cache
        WHEN save is called but there are (new entries/no entries in memory)
        THEN it should (create/not create) the file
        """
        cache = Cache()
        if with_entry:
            cache.update_cache(last_found_secrets=["XXX"])
        cache.save()

        assert os.path.isfile(".cache_ggshield") is with_entry
Esempio n. 3
0
 def test_read_only_fs(self):
     """
     GIVEN a read-only file-system
     WHEN save is called
     THEN it shouldn't raise an exception
     """
     cache = Cache()
     cache.update_cache(last_found_secrets=["XXX"])
     # don't use mock.patch decorator on the test, since Cache.__init__ also calls open
     with patch("builtins.open") as open_mock:
         # The read-only FS is simulated with patched builtin open raising an error
         open_mock.side_effect = OSError("Read-only file system")
         cache.save()
         # Make sure our patched open was called
         open_mock.assert_called_once()