diff options
author | Simo Sorce <simo@redhat.com> | 2015-04-07 12:08:37 -0400 |
---|---|---|
committer | Simo Sorce <simo@redhat.com> | 2015-04-07 12:08:37 -0400 |
commit | 74c7ff48e5917f0fda458f25fcbc39df8ed791d5 (patch) | |
tree | a2eaf01fa308a7de269a7392ab98081c63b7f26a /custodia | |
parent | f4a225670049f631332c89ce9db35ef41560e016 (diff) | |
download | custodia-74c7ff48e5917f0fda458f25fcbc39df8ed791d5.tar.gz custodia-74c7ff48e5917f0fda458f25fcbc39df8ed791d5.tar.xz custodia-74c7ff48e5917f0fda458f25fcbc39df8ed791d5.zip |
Add Sqlite store unit tests
Diffstat (limited to 'custodia')
-rw-r--r-- | custodia/store/sqlite.py | 89 | ||||
-rw-r--r-- | custodia/tests.py | 4 |
2 files changed, 92 insertions, 1 deletions
diff --git a/custodia/store/sqlite.py b/custodia/store/sqlite.py index a76540e..5f33a2a 100644 --- a/custodia/store/sqlite.py +++ b/custodia/store/sqlite.py @@ -71,3 +71,92 @@ class SqliteStore(CSStore): return value else: return None + + +import unittest +class SqliteStoreTests(unittest.TestCase): + + @classmethod + def setUpClass(cls): + cls.store = SqliteStore({'dburi': 'testdbstore.sqlite'}) + + @classmethod + def tearDownClass(self): + try: + os.unlink('testdbstore.sqlite') + except OSError: + pass + + def test_0_get_empty(self): + with self.assertRaises(CSStoreError) as err: + self.store.get('test') + + self.assertEqual(str(err.exception), + 'Error occurred while trying to get key') + + def test_1_list_empty(self): + with self.assertRaises(CSStoreError) as err: + self.store.list('test') + + self.assertEqual(str(err.exception), + 'Error occurred while trying to list keys') + + def test_2_set_key(self): + self.store.set('key', 'value') + value = self.store.get('key') + self.assertEqual(value, 'value') + + def test_3_list_key(self): + value = self.store.list('key') + self.assertEqual(value, {'key': 'value'}) + + value = self.store.list('k') + self.assertEqual(value, {'key': 'value'}) + + value = self.store.list('none') + self.assertEqual(value, None) + + def test_4_multiple_keys(self): + self.store.set('/sub1/key1', 'value11') + self.store.set('/sub1/key2', 'value12') + self.store.set('/sub1/key3', 'value13') + self.store.set('/sub2/key1', 'value21') + self.store.set('/sub2/key2', 'value22') + self.store.set('/oth3/key1', 'value31') + + value = self.store.list() + self.assertEqual(value, {'/sub1/key1': 'value11', + '/sub1/key2': 'value12', + '/sub1/key3': 'value13', + '/sub2/key1': 'value21', + '/sub2/key2': 'value22', + '/oth3/key1': 'value31'}) + + value = self.store.list('/sub') + self.assertEqual(value, {'/sub1/key1': 'value11', + '/sub1/key2': 'value12', + '/sub1/key3': 'value13', + '/sub2/key1': 'value21', + '/sub2/key2': 'value22'}) + + value = self.store.list('/sub2') + self.assertEqual(value, {'/sub2/key1': 'value21', + '/sub2/key2': 'value22'}) + + value = self.store.list('/o') + self.assertEqual(value, {'/oth3/key1': 'value31'}) + + value = self.store.list('/x') + self.assertEqual(value, None) + + value = self.store.list('/sub1/key1/') + self.assertEqual(value, None) + + value = self.store.get('/sub1') + self.assertEqual(value, None) + + value = self.store.get('/sub2/key1') + self.assertEqual(value, 'value21') + + value = self.store.get('/sub%') + self.assertEqual(value, None) diff --git a/custodia/tests.py b/custodia/tests.py index fadcf35..4eaae13 100644 --- a/custodia/tests.py +++ b/custodia/tests.py @@ -1,10 +1,12 @@ from custodia.secrets import SecretsTests +from custodia.store.sqlite import SqliteStoreTests import unittest if __name__ == '__main__': testLoad = unittest.TestLoader() - allUnitTests = [testLoad.loadTestsFromTestCase(SecretsTests)] + allUnitTests = [testLoad.loadTestsFromTestCase(SecretsTests), + testLoad.loadTestsFromTestCase(SqliteStoreTests)] allTestsSuite = unittest.TestSuite(allUnitTests) |