def test__pack_incomplete_package_same_dir(self, mk_request_get): asset_replacements = [ ("/img/revistas/a01.gif", "f01"), ("/img/revistas/a02.gif", "f02"), ] m = Mock() m.content = b"conteudo" pkg_path = self.good_pkg_path bad_pkg_path = self.good_pkg_path renamed_path = pkg_path + "_INCOMPLETE" pkg_name = "pacote_sps" mk_request_get.side_effect = [HTTPGetError("Error"), m] result_path = packing.packing_assets(asset_replacements, pkg_path, bad_pkg_path, pkg_name) self.assertEqual(result_path, renamed_path) self.assertFalse(os.path.isdir(pkg_path)) self.assertEqual(["f02.gif", pkg_name + ".err"], os.listdir(renamed_path)) with open(os.path.join(renamed_path, pkg_name + ".err")) as fp: self.assertEqual(fp.read(), "/img/revistas/a01.gif f01 Error")
def test__pack_incomplete_package_same_dir(self, mk_read_file_binary): asset_replacements = [ ("/img/revistas/a01.gif", "f01"), ("/img/revistas/a02.gif", "f02"), ] m = Mock() m.return_value = b"conteudo" pkg_path = self.good_pkg_path bad_pkg_path = self.good_pkg_path renamed_path = pkg_path + "_INCOMPLETE" pkg_name = "pacote_sps" mk_read_file_binary.side_effect = [IOError("Error"), m.return_value] result_path = packing.packing_assets( asset_replacements, pkg_path, bad_pkg_path, pkg_name, "pid" ) self.assertEqual(result_path, renamed_path) self.assertFalse(os.path.isdir(pkg_path)) self.assertEqual(["f02.gif", pkg_name + ".err"], os.listdir(renamed_path)) with open(os.path.join(renamed_path, pkg_name + ".err")) as fp: self.assertIn("/img/revistas/a01.gif f01 Not found", fp.read())
def test__pack_complete_package(self, mk_read_file_binary): asset_replacements = [ ("/img/revistas/a01.gif", "f01"), ("/img/revistas/a02.gif", "f02"), ] mk_read_file_binary_result1 = Mock() mk_read_file_binary_result1.return_value = b"conteudo" mk_read_file_binary_result2 = Mock() mk_read_file_binary_result2.return_value = b"conteudo" pkg_path = self.good_pkg_path bad_pkg_path = self.bad_pkg_path pkg_name = "pacote_sps" mk_read_file_binary.side_effect = [mk_read_file_binary_result1.return_value, mk_read_file_binary_result2.return_value] result_path = packing.packing_assets( asset_replacements, pkg_path, bad_pkg_path, pkg_name, "pid" ) self.assertEqual(result_path, pkg_path) self.assertFalse(os.path.isdir(bad_pkg_path)) self.assertEqual({"f01.gif", "f02.gif"}, set(os.listdir(pkg_path)))
def test__pack_complete_package(self, mk_request_get): asset_replacements = [ ("/img/revistas/a01.gif", "f01"), ("/img/revistas/a02.gif", "f02"), ] mk_request_get_result1 = Mock() mk_request_get_result1.content = b"conteudo" mk_request_get_result2 = Mock() mk_request_get_result2.content = b"conteudo" pkg_path = self.good_pkg_path bad_pkg_path = self.bad_pkg_path pkg_name = "pacote_sps" mk_request_get.side_effect = [mk_request_get_result1, mk_request_get_result2] result_path = packing.packing_assets( asset_replacements, pkg_path, bad_pkg_path, pkg_name ) self.assertEqual(result_path, pkg_path) self.assertFalse(os.path.isdir(bad_pkg_path)) self.assertEqual({"f01.gif", "f02.gif"}, set(os.listdir(pkg_path)))