From 89948603de0b36164de6afb51de78f8161f001d1 Mon Sep 17 00:00:00 2001 From: James Turner Date: Sun, 30 Jul 2017 10:38:04 -0700 Subject: [PATCH] Catalog support for minimum-fg-version Extend test coverage with a minimal aircraft to exercise more code paths for this. --- .gitignore | 1 + catalog/catalog.py | 36 ++++++++++++++----- catalog/testData/Aircraft/c150/c150-set.xml | 8 +++++ catalog/testData/Aircraft/f16/f16-common.xml | 1 + catalog/testData/Aircraft/f16/thumbnail.jpg | Bin catalog/test_catalog.py | 33 +++++++++++++++++ 6 files changed, 70 insertions(+), 9 deletions(-) create mode 100644 catalog/testData/Aircraft/c150/c150-set.xml create mode 100644 catalog/testData/Aircraft/f16/thumbnail.jpg diff --git a/.gitignore b/.gitignore index 47f661a..e336de7 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ osgbuild CMakeCache.txt *.pyc build-* +testOutput* diff --git a/catalog/catalog.py b/catalog/catalog.py index 12ffc7b..ecad6ff 100644 --- a/catalog/catalog.py +++ b/catalog/catalog.py @@ -38,8 +38,12 @@ def scan_set_file(aircraft_dir, set_file, includes): variant = {} variant['name'] = sim_node.getValue("description", None) variant['status'] = sim_node.getValue("status", None) - variant['author'] = sim_node.getValue("author", None) - variant['description'] = sim_node.getValue("long-description", None) + + if sim_node.hasChild('author'): + variant['author'] = sim_node.getValue("author", None) + + if sim_node.hasChild('long-description'): + variant['description'] = sim_node.getValue("long-description", None) variant['id'] = base_id # allow -set.xml files to declare themselves as primary. @@ -64,6 +68,10 @@ def scan_set_file(aircraft_dir, set_file, includes): variant['thumbnail'] = sim_node.getValue("thumbnail", None) variant['variant-of'] = sim_node.getValue("variant-of", None) + + if sim_node.hasChild('minimum-fg-version'): + variant['minimum-fg-version'] = sim_node.getValue('minimum-fg-version', None) + #print ' ', variant return variant @@ -128,7 +136,8 @@ def scan_aircraft_dir(aircraft_dir, includes): package = primaryAircraft[0] if not 'thumbnail' in package: - package['thumbnail'] = "thumbnail.jpg" + if (os.path.exists(os.path.join(aircraft_dir, "thumbnail.jpg"))): + package['thumbnail'] = "thumbnail.jpg" # variants is just all the set dicts except the first one variants = setDicts @@ -172,8 +181,16 @@ def make_aircraft_node(aircraftDirName, package, variants, downloadBase): package_node = ET.Element('package') package_node.append( make_xml_leaf('name', package['name']) ) package_node.append( make_xml_leaf('status', package['status']) ) - package_node.append( make_xml_leaf('author', package['author']) ) - package_node.append( make_xml_leaf('description', package['description']) ) + + if 'author' in package: + package_node.append( make_xml_leaf('author', package['author']) ) + + if 'description' in package: + package_node.append( make_xml_leaf('description', package['description']) ) + + if 'minimum-fg-version' in package: + package_node.append( make_xml_leaf('minimum-fg-version', package['minimum-fg-version']) ) + if 'rating_FDM' in package or 'rating_systems' in package \ or 'rating_cockpit' in package or 'rating_model' in package: rating_node = ET.Element('rating') @@ -217,11 +234,12 @@ def make_aircraft_node(aircraftDirName, package, variants, downloadBase): package_node.append( make_xml_leaf('dir', aircraftDirName) ) download_url = downloadBase + aircraftDirName + '.zip' - thumbnail_url = downloadBase + 'thumbnails/' + aircraftDirName + '_' + package['thumbnail'] - package_node.append( make_xml_leaf('url', download_url) ) - package_node.append( make_xml_leaf('thumbnail', thumbnail_url) ) - package_node.append( make_xml_leaf('thumbnail-path', package['thumbnail'])) + + if 'thumbnail' in package: + thumbnail_url = downloadBase + 'thumbnails/' + aircraftDirName + '_' + package['thumbnail'] + package_node.append( make_xml_leaf('thumbnail', thumbnail_url) ) + package_node.append( make_xml_leaf('thumbnail-path', package['thumbnail'])) append_preview_nodes(package_node, package, downloadBase, aircraftDirName) append_tag_nodes(package_node, package) diff --git a/catalog/testData/Aircraft/c150/c150-set.xml b/catalog/testData/Aircraft/c150/c150-set.xml new file mode 100644 index 0000000..9dbe34d --- /dev/null +++ b/catalog/testData/Aircraft/c150/c150-set.xml @@ -0,0 +1,8 @@ + + + + c150 + Cessna 150 + + + diff --git a/catalog/testData/Aircraft/f16/f16-common.xml b/catalog/testData/Aircraft/f16/f16-common.xml index 8e5a3d9..def9da9 100644 --- a/catalog/testData/Aircraft/f16/f16-common.xml +++ b/catalog/testData/Aircraft/f16/f16-common.xml @@ -7,6 +7,7 @@ 1980s glass-cockpit + 2017.4 diff --git a/catalog/testData/Aircraft/f16/thumbnail.jpg b/catalog/testData/Aircraft/f16/thumbnail.jpg new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/catalog/test_catalog.py b/catalog/test_catalog.py index e083bcd..00e7a22 100755 --- a/catalog/test_catalog.py +++ b/catalog/test_catalog.py @@ -17,6 +17,7 @@ class UpdateCatalogTests(unittest.TestCase): self.assertEqual(info['rating_FDM'], 3) self.assertEqual(info['rating_model'], 5) self.assertEqual(len(info['tags']), 3) + self.assertEqual(info['minimum-fg-version'], '2017.4') def test_scan_dir(self): (pkg, variants) = catalog.scan_aircraft_dir("testData/Aircraft/f16", ["testData/OtherDir"]) @@ -25,6 +26,7 @@ class UpdateCatalogTests(unittest.TestCase): f16trainer = next(v for v in variants if v['id'] == 'f16-trainer') self.assertEqual(pkg['author'], 'Wilbur Wright') self.assertEqual(len(variants), 3) + self.assertEqual(pkg['minimum-fg-version'], '2017.4') # test variant relatonship between self.assertEqual(pkg['variant-of'], None) @@ -90,6 +92,8 @@ class UpdateCatalogTests(unittest.TestCase): self.assertEqual(parsedPkgNode.getValue('description'), pkg['description']); self.assertEqual(parsedPkgNode.getValue('author'), "Wilbur Wright"); + self.assertEqual(parsedPkgNode.getValue('minimum-fg-version'), "2017.4"); + parsedVariants = parsedPkgNode.getChildren("variant") self.assertEqual(len(parsedVariants), 3) @@ -109,8 +113,37 @@ class UpdateCatalogTests(unittest.TestCase): self.assertEqual(pv.getValue('description'), 'The F16-B is an upgraded version of the F16A.') self.assertEqual(pv.getValue('author'), "James T Kirk"); + def test_minimalAircraft(self): + # test an aircraft with a deliberately spartan -set.xml file with + # most interesting data missing + (pkg, variants) = catalog.scan_aircraft_dir("testData/Aircraft/c150", ["testData/OtherDir"]) + catalog_node = ET.Element('PropertyList') + catalog_root = ET.ElementTree(catalog_node) + pkgNode = catalog.make_aircraft_node('c150', pkg, variants, "http://foo.com/testOutput/") + catalog_node.append(pkgNode) + + if not os.path.isdir("testOutput2"): + os.mkdir("testOutput2") + + cat_file = os.path.join("testOutput2", 'catalog_fragment.xml') + catalog_root.write(cat_file, encoding='utf-8', xml_declaration=True, pretty_print=True) + + parsed = sgprops.readProps(cat_file) + parsedPkgNode = parsed.getChild("package") + + self.assertEqual(parsedPkgNode.getValue('id'), pkg['id']) + self.assertEqual(parsedPkgNode.getValue('dir'), 'c150') + self.assertEqual(parsedPkgNode.getValue('url'), 'http://foo.com/testOutput/c150.zip') + self.assertFalse(parsedPkgNode.hasChild('thumbnail')) + self.assertFalse(parsedPkgNode.hasChild('thumbnail-path')); + + self.assertEqual(parsedPkgNode.getValue('name'), pkg['name']); + self.assertFalse(parsedPkgNode.hasChild('description')); + self.assertFalse(parsedPkgNode.hasChild('author')); + self.assertFalse(parsedPkgNode.hasChild('minimum-fg-version')); + self.assertFalse(parsedPkgNode.hasChild('variant')); if __name__ == '__main__': unittest.main()