aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevan Franchini <twitch153@gentoo.org>2015-07-20 09:57:09 -0400
committerDevan Franchini <twitch153@gentoo.org>2015-07-20 09:57:11 -0400
commite8160e953d4c1c9792c8640fd3edbe6ac1d39e9e (patch)
treedc67e8f126a9c38d6b7b48d9513b375a45b5496b
parentupdater.py: Modifies the db_type setting method (diff)
downloadlayman-e8160e953d4c1c9792c8640fd3edbe6ac1d39e9e.tar.gz
layman-e8160e953d4c1c9792c8640fd3edbe6ac1d39e9e.tar.bz2
layman-e8160e953d4c1c9792c8640fd3edbe6ac1d39e9e.zip
external.py: Adds json DB testing
updater.py: Adds proper line spacing for database migration output
-rwxr-xr-xlayman/tests/external.py28
-rw-r--r--layman/tests/testfiles/global-overlays.json44
-rw-r--r--layman/updater.py2
3 files changed, 73 insertions, 1 deletions
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": "twitch153@gentoo.org",
+ "name": "Devan Franchini"
+ },
+ "source": [
+ {
+ "#text": "git://github.com/twitch153/ebuilds.git",
+ "@type": "git"
+ }
+ ]
+ },
+ {
+ "description": [
+ "A collection of ebuilds from Gunnar Wrobel [wrobel@gentoo.org]."
+ ],
+ "name": "wrobel-stable",
+ "owner": {
+ "email": "nobody@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)