def test_transform_xml_file_tags(self): # populate an ElementTree xml_string = read_fixture("code_file_list.xml") root = ElementTree.fromstring(xml_string) # specify from file, to file transformations file_transformations = [] test_data = [ { "from_xml": "Figure 5source code 1.c", "to_xml": "Figure 5source code 1.c.zip", }, { "from_xml": "Figure 5source code 2.c", "to_xml": "Figure 5source code 2.c.zip", }, ] for data in test_data: from_file = ArticleZipFile(data.get("from_xml"), None, None) to_file = ArticleZipFile(data.get("to_xml"), None, None) file_transformations.append((from_file, to_file)) # invoke the function root_output = transform.transform_xml_file_tags( root, file_transformations) # find the tag in the XML root returned which will have been altered upload_file_nm_tags = root_output.findall( "./front/article-meta/files/file/upload_file_nm") # assert the XML text is different self.assertEqual(upload_file_nm_tags[1].text, test_data[0].get("to_xml")) self.assertEqual(upload_file_nm_tags[2].text, test_data[1].get("to_xml"))
def test_file_list(self): zip_file = "tests/test_data/30-01-2019-RA-eLife-45644.zip" asset_file_name_map = zip_lib.unzip_zip(zip_file, self.temp_dir) xml_asset = parse.article_xml_asset(asset_file_name_map) root = parse.parse_article_xml(xml_asset[1]) expected = read_fixture("file_list_45644.py") files = parse.file_list(root) self.assertEqual(files, expected)
def test_glencoe_xml(self, fake_gmtime): fake_gmtime.return_value = time.strptime("2022-04-19", "%Y-%m-%d") zip_file = "tests/test_data/08-11-2020-FA-eLife-64719.zip" xml_file_name = "08-11-2020-FA-eLife-64719/08-11-2020-FA-eLife-64719.xml" xml_file_path = os.path.join(self.temp_dir, xml_file_name) with zipfile.ZipFile(zip_file, "r") as input_zipfile: input_zipfile.extract(xml_file_name, self.temp_dir) xml_string = video_xml.glencoe_xml(xml_file_path, VIDEO_DATA) expected = read_fixture("video_xml_64719.xml", "rb") self.assertEqual(xml_string, expected)
def test_code_file_list(self): xml_string = read_fixture("code_file_list.xml") expected = read_fixture("code_file_list.py") root = ElementTree.fromstring(xml_string) code_files = transform.code_file_list(root) self.assertEqual(code_files, expected)
def test_unzip_zip(self): zip_file = "tests/test_data/30-01-2019-RA-eLife-45644.zip" asset_file_name_map = zip_lib.unzip_zip(zip_file, self.temp_dir) expected = read_fixture("asset_file_name_map_45644.py") self.assertEqual(asset_file_name_map, expected)
def test_generate_xml(self, fake_gmtime): fake_gmtime.return_value = time.strptime("2022-04-19", "%Y-%m-%d") article = build_article("10.7554/eLife.64719", 64719) xml_string = video_xml.generate_xml(article, JOURNAL_DATA, VIDEO_DATA) expected = read_fixture("video_xml_64719.xml", "rb") self.assertEqual(xml_string, expected)