Example #1
0
    def test_get_asset_raises_AssetNotFoundError_exception(self, mk_read_file_binary):
        mk_read_file_binary.side_effect = IOError
        old_path = "/img/en/scielobre.gif"
        new_fname = "novo"
        dest_path = TEMP_TEST_PATH

        with self.assertRaises(packing.AssetNotFoundError):
            packing.get_asset(old_path, new_fname, dest_path)
Example #2
0
 def test_invalid_relative_URL_raises_error(self):
     """
     Testa correção do bug:
     https://github.com/scieloorg/document-store-migracao/issues/158
     """
     with self.assertRaises(packing.AssetNotFoundError) as exc:
         packing.get_asset("//www. [ <a href=", "novo", TEMP_TEST_PATH)
     self.assertIn(
         "Not found",
         str(exc.exception)
     )
Example #3
0
    def test_get_asset_pdf_path(self):
        with utils.environ(
            SOURCE_PDF_FILE=os.path.join(os.path.dirname(__file__), "samples"),
        ):
            old_path = "/pdf/sample.pdf"
            new_fname = "novo"
            dest_path = TEMP_TEST_PATH

            self.assertFalse(os.path.isfile(self.dest_filename_pdf))
            packing.get_asset(old_path, new_fname, dest_path)

            pdf_new_path = os.path.join(dest_path, new_fname + ".pdf")
            self.assertTrue(os.path.exists(pdf_new_path))
Example #4
0
    def test_get_asset_img_path(self):
        with utils.environ(
            SOURCE_IMG_FILE=os.path.join(os.path.dirname(__file__), "samples"),
        ):
            old_path = "/img/sample.jpg"
            new_fname = "novo"
            dest_path = TEMP_TEST_PATH

            self.assertFalse(os.path.isfile(self.dest_filename_img))
            packing.get_asset(old_path, new_fname, dest_path)

            img_new_path = os.path.join(dest_path, new_fname + ".jpg")
            self.assertTrue(os.path.exists(img_new_path))
Example #5
0
    def test_get_asset(self, read_file_binary):
        read_file_binary.return_value = b"conteudo"
        old_path = "/img/en/scielobre.gif"
        new_fname = "novo"
        dest_path = TEMP_TEST_PATH

        self.assertFalse(os.path.isfile(self.dest_filename_img))
        path = packing.get_asset(old_path, new_fname, dest_path)
        self.assertIsNone(path)
        with open(self.dest_filename_img) as fp:
            self.assertTrue(fp.read(), b"conteudo")
Example #6
0
    def test_get_asset_in_pdf_folder(self, read_file_binary):
        read_file_binary.return_value = b"conteudo pdf"
        old_path = "/pdf/en/asset.pdf"
        new_fname = "novo"
        dest_path = TEMP_TEST_PATH

        self.assertFalse(os.path.isfile(self.dest_filename_img))

        path = packing.get_asset(old_path, new_fname, dest_path)

        self.assertIsNone(path)

        with open(self.dest_filename_pdf) as fp:
            self.assertTrue(fp.read(), b"conteudo pdf")
Example #7
0
    def test_get_asset_raises_AssetNotFoundError_exception(
            self, mk_read_file_binary, mock_find_file):

        with utils.environ(
            SOURCE_PATH=SAMPLES_PATH,
            VALID_XML_PATH=SAMPLES_PATH,
            SPS_PKG_PATH=SAMPLES_PATH,
            INCOMPLETE_SPS_PKG_PATH=SAMPLES_PATH,
            SOURCE_PDF_FILE=os.path.join(os.path.dirname(__file__), "samples"),
            SOURCE_IMG_FILE=os.path.join(os.path.dirname(__file__), "samples")
        ):
            mk_read_file_binary.return_value = b""
            old_path = "/img/revistas/acron/volume/seta.gif"
            new_fname = "novo"
            dest_path = TEMP_TEST_PATH
            path = packing.get_asset(old_path, new_fname, dest_path)
            htdocs_path = os.path.join(os.path.dirname(__file__), "samples")
            mock_find_file.assert_called_with(f"{htdocs_path}/img/seta.gif")