def test_returns_files_from_cache(self):
     with tempdir() as cache_dir:
         store = FileStore(cache_dir)
         tar_xz, files = self.make_tar_xz(cache_dir)
         sha256, size = self.get_file_info(tar_xz)
         checksums = {"sha256": sha256}
         with open(tar_xz, "rb") as f:
             content_source = ChecksummingContentSource(f, checksums, size)
             download_resources.extract_archive_tar(
                 store,
                 os.path.basename(tar_xz),
                 sha256,
                 checksums,
                 size,
                 content_source,
             )
             mocked_tar = self.patch(download_resources.tarfile, "open")
             cached_files = download_resources.extract_archive_tar(
                 store,
                 os.path.basename(tar_xz),
                 sha256,
                 checksums,
                 size,
                 content_source,
             )
             self.assertThat(mocked_tar, MockNotCalled())
             for f, info in files.items():
                 cached_file = os.path.join(cache_dir,
                                            "%s-%s" % (f, sha256))
                 expected_cached_file = (cached_file, f)
                 self.assertIn(expected_cached_file, cached_files)
 def test_extracts_files(self):
     with tempdir() as cache_dir:
         store = FileStore(cache_dir)
         tar_xz, files = self.make_tar_xz(cache_dir)
         sha256, size = self.get_file_info(tar_xz)
         checksums = {'sha256': sha256}
         with open(tar_xz, 'rb') as f:
             content_source = ChecksummingContentSource(f, checksums, size)
             cached_files = download_resources.extract_archive_tar(
                 store, os.path.basename(tar_xz), sha256, checksums, size,
                 content_source)
             for f, info in files.items():
                 cached_file = os.path.join(cache_dir,
                                            '%s-%s' % (f, sha256))
                 expected_cached_file = (cached_file, f)
                 self.assertIn(expected_cached_file, cached_files)
                 self.assertTrue(os.path.exists(cached_file))
                 self.assertEqual(info, self.get_file_info(cached_file))