commit:     e8160e953d4c1c9792c8640fd3edbe6ac1d39e9e
Author:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
AuthorDate: Mon Jul 20 13:57:09 2015 +0000
Commit:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
CommitDate: Mon Jul 20 13:57:11 2015 +0000
URL:        https://gitweb.gentoo.org/proj/layman.git/commit/?id=e8160e95

external.py: Adds json DB testing

updater.py: Adds proper line spacing for database migration output

 layman/tests/external.py                    | 28 ++++++++++++++++++
 layman/tests/testfiles/global-overlays.json | 44 +++++++++++++++++++++++++++++
 layman/updater.py                           |  2 +-
 3 files changed, 73 insertions(+), 1 deletion(-)

diff --git a/layman/tests/external.py b/layman/tests/external.py
index e9f419a..f61d4b6 100755
--- a/layman/tests/external.py
+++ b/layman/tests/external.py
@@ -673,6 +673,7 @@ class ReadWriteSelectListDbBase(unittest.TestCase):
 
     def read_db(self):
         output = Message()
+        # First test if XML databasing works.
         config = {'output': output,
                   'db_type': 'xml',}
         db = DbBase(config, [HERE + '/testfiles/global-overlays.xml', ])
@@ -682,6 +683,15 @@ class ReadWriteSelectListDbBase(unittest.TestCase):
         url = ['rsync://gunnarwrobel.de/wrobel-stable']
         self.assertEqual(list(db.overlays['wrobel-stable'].source_uris()), url)
 
+        # Test JSON databasing after.
+        config['db_type'] = 'json'
+        db = DbBase(config, [HERE + '/testfiles/global-overlays.json', ])
+        keys = sorted(db.overlays)
+        self.assertEqual(keys, ['twitch153', 'wrobel-stable'])
+
+        url = ['git://github.com/twitch153/ebuilds.git']
+        self.assertEqual(list(db.overlays['twitch153'].source_uris()), url)
+
 
     def select_db(self):
         output = Message()
@@ -691,10 +701,16 @@ class ReadWriteSelectListDbBase(unittest.TestCase):
         url = ['rsync://gunnarwrobel.de/wrobel-stable']
         self.assertEqual(list(db.select('wrobel-stable').source_uris()), url)
 
+        config['db_type'] = 'json'
+        db = DbBase(config, [HERE + '/testfiles/global-overlays.json', ])
+        url = ['git://github.com/twitch153/ebuilds.git']
+        self.assertEqual(list(db.select('twitch153').source_uris()), url)
+
 
     def write_db(self):
         tmpdir = tempfile.mkdtemp(prefix='laymantmp_')
         test_xml = os.path.join(tmpdir, 'test.xml')
+        test_json = os.path.join(tmpdir, 'test.json')
         config = BareConfig()
 
         a = DbBase(config, [HERE + '/testfiles/global-overlays.xml', ])
@@ -707,8 +723,20 @@ class ReadWriteSelectListDbBase(unittest.TestCase):
         keys = sorted(c.overlays)
         self.assertEqual(keys, ['wrobel-stable'])
 
+        config.set_option('db_type', 'json')
+        a = DbBase(config, [HERE + '/testfiles/global-overlays.json', ])
+        b = DbBase({'output': Message(), 'db_type': 'json'}, [test_json,])
+
+        b.overlays['twitch153'] = a.overlays['twitch153']
+        b.write(test_json)
+
+        c = DbBase({'output': Message(), 'db_type': 'json'}, [test_json,])
+        keys = sorted(c.overlays)
+        self.assertEqual(keys, ['twitch153'])
+
         # Clean up:
         os.unlink(test_xml)
+        os.unlink(test_json)
         shutil.rmtree(tmpdir)
 
 

diff --git a/layman/tests/testfiles/global-overlays.json 
b/layman/tests/testfiles/global-overlays.json
new file mode 100644
index 0000000..53267cf
--- /dev/null
+++ b/layman/tests/testfiles/global-overlays.json
@@ -0,0 +1,44 @@
+{
+  "@encoding": "unicode",
+  "@version": "1.0",
+  "repo": [
+    {
+      "@priority": "40",
+      "@quality": "experimental",
+      "@status": "unofficial",
+      "description": [
+        "Twitch test"
+      ],
+      "feed": [
+        "https://github.com/twitch153/ebuilds/commits/master.atom";
+      ],
+      "homepage": "https://github.com/twitch153/ebuilds";,
+      "name": "twitch153",
+      "owner": {
+        "email": "twitch...@gentoo.org",
+        "name": "Devan Franchini"
+      },
+      "source": [
+        {
+          "#text": "git://github.com/twitch153/ebuilds.git",
+          "@type": "git"
+        }
+      ]
+    },
+    {
+      "description": [
+        "A collection of ebuilds from Gunnar Wrobel [wro...@gentoo.org]."
+      ],
+      "name": "wrobel-stable",
+      "owner": {
+        "email": "nob...@gentoo.org"
+      },
+      "source": [
+        {
+          "#text": "rsync://gunnarwrobel.de/wrobel-stable",
+          "@type": "rsync"
+        }
+      ]
+    }
+  ]
+}

diff --git a/layman/updater.py b/layman/updater.py
index 9d7b176..746373d 100644
--- a/layman/updater.py
+++ b/layman/updater.py
@@ -158,7 +158,7 @@ class Main(object):
             raise err
 
         msg = '  Successfully migrated database from "%(from_type)s" to '\
-              '"%(to_type)s"\n' % {'from_type': self.config['db_type'],
+              ' "%(to_type)s"\n' % {'from_type': self.config['db_type'],
                                    'to_type': migrate_type}
         self.output.info(msg)
 

Reply via email to