From 3c9c13227a1469f6b3331a77f21bd1bad0c82905 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 6 Apr 2015 14:11:32 -0400 Subject: Initial testsuite commit --- custodia/secrets.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'custodia/secrets.py') 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"}}')) -- cgit