[csw-devel] SF.net SVN: gar:[21065] csw/mgar/gar/v2/lib/python

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Mon May 13 19:27:58 CEST 2013


Revision: 21065
          http://gar.svn.sourceforge.net/gar/?rev=21065&view=rev
Author:   wahwah
Date:     2013-05-13 17:27:58 +0000 (Mon, 13 May 2013)
Log Message:
-----------
pkgdb: A multi-line test for generate-catalog-file

To be able to test adding new lines to the catalog.

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/python/generate_catalog_file.py
    csw/mgar/gar/v2/lib/python/generate_catalog_file_test.py

Modified: csw/mgar/gar/v2/lib/python/generate_catalog_file.py
===================================================================
--- csw/mgar/gar/v2/lib/python/generate_catalog_file.py	2013-05-13 17:07:10 UTC (rev 21064)
+++ csw/mgar/gar/v2/lib/python/generate_catalog_file.py	2013-05-13 17:27:58 UTC (rev 21065)
@@ -80,12 +80,19 @@
     out_file = os.path.join(out_dir, CATALOG_FN)
     if os.path.exists(out_file):
       raise Error("File %s already exists." % out_file)
+    lines = self._GenerateCatalogLines()
+    with open(out_file, "w") as fd:
+      fd.write("\n".join(lines))
+
+  def _GenerateCatalogAsLines(self):
+    """Return the complete catalog as a list of lines."""
     lines = []
+    # Potential additional lines might go here.
+    # liens.append("...")
     if self.catalog:  # the catalog might be None
       for pkg_data in self.catalog:
         lines.append(self.ComposeCatalogLine(pkg_data))
-    with open(out_file, "w") as fd:
-      fd.write("\n".join(lines))
+    return lines
 
   def GenerateDescriptions(self, out_dir):
     out_file = os.path.join(out_dir, DESC_FN)

Modified: csw/mgar/gar/v2/lib/python/generate_catalog_file_test.py
===================================================================
--- csw/mgar/gar/v2/lib/python/generate_catalog_file_test.py	2013-05-13 17:07:10 UTC (rev 21064)
+++ csw/mgar/gar/v2/lib/python/generate_catalog_file_test.py	2013-05-13 17:27:58 UTC (rev 21065)
@@ -17,6 +17,21 @@
         "version_string": "1.1.29,REV=2012.05.02"
 }
 
+FAKE_CATALOG_DATA = {
+    "deps": [
+      ["CSWfoo", ""],
+      ["CSWbar", ""],
+    ],
+    "i_deps": [],
+    "pkginfo_name": "389_admin - The 389 LDAP server Admin Tools",
+    "pkgname": "CSW389-admin-mock",
+}
+
+EXPECTED_LINE = ("389_admin 1.1.29,REV=2012.05.02 CSW389-admin-mock "
+                 "389_admin-1.1.29,REV=2012.05.02-SunOS5.10-sparc-CSW.pkg.gz "
+                 "fdb7912713da36afcbbe52266c15cb3f 395802 CSWfoo|CSWbar "
+                 "none none")
+
 class CatalogFileGeneratorUnitTest(mox.MoxTestBase):
 
   def testComposeCatalogLineBasic(self):
@@ -33,27 +48,27 @@
                                                      "sparc",
                                                      "SunOS5.10",
                                                      mock_pkgcache, mock_rest)
-    mock_rest.GetCatalogData('fdb7912713da36afcbbe52266c15cb3f').AndReturn({
-      "deps": [
-        ["CSWfoo", ""],
-        ["CSWbar", ""],
-      ],
-      "i_deps": [],
-      "pkginfo_name": "389_admin - The 389 LDAP server Admin Tools",
-      "pkgname": "CSW389-admin-mock",
-      })
+    md5_sum = 'fdb7912713da36afcbbe52266c15cb3f'
+    mock_rest.GetCatalogData(md5_sum).AndReturn(FAKE_CATALOG_DATA)
     self.mox.ReplayAll()
-    self.assertEquals(
-        "389_admin "
-        "1.1.29,REV=2012.05.02 "
-        "CSW389-admin-mock "
-        "389_admin-1.1.29,REV=2012.05.02-SunOS5.10-sparc-CSW.pkg.gz "
-        "fdb7912713da36afcbbe52266c15cb3f "
-        "395802 "
-        "CSWfoo|CSWbar "
-        "none none",
-        cfg.ComposeCatalogLine(PKG_DATA_1))
+    self.assertEquals(EXPECTED_LINE, cfg.ComposeCatalogLine(PKG_DATA_1))
 
+  def testGenerateCatalogAsLines(self):
+    mock_pkgcache = self.mox.CreateMock(rest.CachedPkgstats)
+    mock_rest = self.mox.CreateMock(rest.RestClient)
+    cfg = generate_catalog_file.CatalogFileGenerator("dublin",
+                                                     "sparc",
+                                                     "SunOS5.10",
+                                                     mock_pkgcache, mock_rest)
+    md5_sum = 'fdb7912713da36afcbbe52266c15cb3f'
+    mock_rest.GetCatalog('dublin', 'sparc', 'SunOS5.10').AndReturn([PKG_DATA_1])
+    mock_rest.GetCatalogData(md5_sum).AndReturn(FAKE_CATALOG_DATA)
+    self.mox.ReplayAll()
+    self.assertEquals([
+      # Potential additional lines go here.
+      EXPECTED_LINE,
+    ], cfg._GenerateCatalogAsLines())
 
+
 if __name__ == '__main__':
   unittest.main()

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the devel mailing list