summaryrefslogtreecommitdiffstats
path: root/custodia/secrets.py
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2015-04-06 14:11:32 -0400
committerSimo Sorce <simo@redhat.com>2015-04-06 17:04:28 -0400
commit3c9c13227a1469f6b3331a77f21bd1bad0c82905 (patch)
tree032b609951abcaa98e9f6c2b0677157b9e4c7547 /custodia/secrets.py
parent18f7a10d2bad6e8050fb1d34c82398ad8acf628c (diff)
downloadcustodia-3c9c13227a1469f6b3331a77f21bd1bad0c82905.tar.gz
custodia-3c9c13227a1469f6b3331a77f21bd1bad0c82905.tar.xz
custodia-3c9c13227a1469f6b3331a77f21bd1bad0c82905.zip
Initial testsuite commit
Diffstat (limited to 'custodia/secrets.py')
-rw-r--r--custodia/secrets.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/custodia/secrets.py b/custodia/secrets.py
index 6eb630e..8956bd5 100644
--- a/custodia/secrets.py
+++ b/custodia/secrets.py
@@ -101,3 +101,48 @@ class Secrets(HTTPConsumer):
self.root.store.set(key, value)
except CSStoreError:
raise HTTPError(500)
+
+
+# unit tests
+import unittest
+from custodia.store.sqlite import SqliteStore
+
+
+class SecretsTests(unittest.TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ cls.secrets = Secrets()
+ cls.secrets.root.store = SqliteStore({'dburi': 'testdb.sqlite'})
+
+ @classmethod
+ def tearDownClass(self):
+ try:
+ os.unlink('testdb.sqlite')
+ except OSError:
+ pass
+
+ def test_1_PUTKey(self):
+ req = {'headers': {'Content-Type': 'application/json'},
+ 'remote_user': 'test',
+ 'trail': ['test', 'key1'],
+ 'body': '{"type":"simple","value":"1234"}'}
+ rep = {}
+ self.secrets.PUT(req, rep)
+
+ def test_2_GETKey(self):
+ req = {'remote_user': 'test',
+ 'trail': ['test', 'key1']}
+ rep = {}
+ self.secrets.GET(req, rep)
+ self.assertEqual(rep['output'],
+ '{"type":"simple","value":"1234"}')
+
+ def test_3_LISTKeys(self):
+ req = {'remote_user': 'test',
+ 'trail': ['test', '']}
+ rep = {}
+ self.secrets.GET(req, rep)
+ self.assertEqual(json.loads(rep['output']),
+ json.loads('{"test/key1":'\
+ '{"type":"simple","value":"1234"}}'))