def test_file_preview(self) -> None: path = (pathlib.Path(__file__).parent.parent.absolute() / "file_formats" / "tests" / "stairs.ctb") ctb_preview = CTBFile.read_preview(path) with patch("mariner.server.utils.CTBFile.read_preview", return_value=ctb_preview): response = self.client.get("/api/file_preview?filename=stairs.ctb") expect(response.content_type).to_equal("image/png") expect(hashlib.md5(response.get_data()).hexdigest()).to_equal( "ca98c806d42898ba70626e556f714928")
def test_preview_rendering(self) -> None: path = pathlib.Path(__file__).parent.absolute() / "stairs.ctb" bytes = io.BytesIO() preview_image: png.Image = CTBFile.read_preview(path) preview_image.write(bytes) expect(preview_image.info["width"]).to_equal(400) expect(preview_image.info["height"]).to_equal(300) expect(preview_image.info["bitdepth"]).to_equal(5) expect(preview_image.info["alpha"]).is_false() expect(hashlib.md5(bytes.getvalue()).hexdigest()).to_equal( "ca98c806d42898ba70626e556f714928")
def test_preview_rendering(self) -> None: path = pathlib.Path(__file__).parent.absolute() / "pyramid.cbddlp" bytes = io.BytesIO() preview_image: png.Image = CTBFile.read_preview(path) preview_image.write(bytes) expect(preview_image.info["width"]).to_equal(400) expect(preview_image.info["height"]).to_equal(300) expect(preview_image.info["bitdepth"]).to_equal(5) expect(preview_image.info["alpha"]).is_false() expect(hashlib.md5(bytes.getvalue()).hexdigest()).to_equal( "1e80ffc6bd1e975f9c943dfbcb990be5")
def read_cached_preview(filename: str) -> bytes: assert os.path.isabs(filename) bytes = io.BytesIO() preview_image: png.Image = CTBFile.read_preview(FILES_DIRECTORY / filename) preview_image.write(bytes) return bytes.getvalue()