def _test_update(self, filename, contents, expected_new_contents, expected_updates): with tempfile.TemporaryDirectory() as tmpdir: manifest = os.path.join(tmpdir, filename) with open(manifest, "w") as f: f.write(contents) appdata = os.path.join( tmpdir, os.path.splitext(filename)[0] + ".appdata.xml", ) with open(appdata, "w") as f: f.write("""<application></application>""") checker = ManifestChecker(manifest) checker._checkers = [UpdateEverythingChecker()] checker.check() updates = checker.update_manifests() with open(manifest, "r") as f: new_contents = f.read() self.assertEqual(new_contents, expected_new_contents) self.assertEqual(updates, expected_updates) with open(appdata, "r") as f: appdata_doc = minidom.parse(f) releases = appdata_doc.getElementsByTagName("release") self.assertNotEqual(releases, []) self.assertEqual(releases, releases[:1]) self.assertEqual(releases[0].getAttribute("version"), "1.2.3.4") self.assertEqual(releases[0].getAttribute("date"), "2019-08-28")
def _test_remove(self, filename, contents, expected_new_contents, expected_updates): with tempfile.TemporaryDirectory() as tmpdir: manifest = os.path.join(tmpdir, filename) with open(manifest, "w") as f: f.write(contents) checker = ManifestChecker(manifest) checker._checkers = [RemoveEverythingChecker()] checker.check() updates = checker.update_manifests() with open(manifest, "r") as f: new_contents = f.read() self.assertEqual(new_contents, expected_new_contents) self.assertEqual(updates, expected_updates)
def test_check_filtered(self): # Use only the URLChecker which is fast so we don't have to wait a lot # for this test; so save the real checkers for later dummy_checker = ManifestChecker(TEST_MANIFEST) dummy_checker._checkers = [DummyChecker()] ext_data = dummy_checker.check() ext_data_from_getter = dummy_checker.get_external_data() self.assertEqual(len(ext_data), len(ext_data_from_getter)) self.assertEqual(set(ext_data), set(ext_data_from_getter)) self.assertEqual(len(ext_data), NUM_ALL_EXT_DATA) ext_data = dummy_checker.check(ExternalData.Type.EXTRA_DATA) self.assertEqual(len(ext_data), NUM_EXTRA_DATA_IN_MANIFEST) ext_data = dummy_checker.check(ExternalData.Type.FILE) self.assertEqual(len(ext_data), NUM_FILE_IN_MANIFEST) ext_data = dummy_checker.check(ExternalData.Type.ARCHIVE) self.assertEqual(len(ext_data), NUM_ARCHIVE_IN_MANIFEST)