diff options
Diffstat (limited to 'qvisqve/entity_manager_tests.py')
-rw-r--r-- | qvisqve/entity_manager_tests.py | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/qvisqve/entity_manager_tests.py b/qvisqve/entity_manager_tests.py new file mode 100644 index 0000000..5088da4 --- /dev/null +++ b/qvisqve/entity_manager_tests.py @@ -0,0 +1,69 @@ +# Copyright (C) 2018 Lars Wirzenius +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + + +import shutil +import tempfile +import unittest + +import qvisqve + + +class EntityManagerTests(unittest.TestCase): + + def setUp(self): + self.tempdir = tempfile.mkdtemp() + fs = qvisqve.FileStore(self.tempdir) + self.em = qvisqve.EntityManager(fs, 'foo') + + def tearDown(self): + shutil.rmtree(self.tempdir) + + def test_has_no_entities_initially(self): + self.assertEqual(self.em.list(), []) + with self.assertRaises(qvisqve.ResourceDoesNotExist): + self.em.get('does-not-exist') + + def test_creates_an_entity(self): + foo = { + 'foo': 'foo is cool', + } + foo_id = 'foo is my entity' + self.em.create(foo_id, foo) + self.assertEqual(self.em.list(), [foo_id]) + self.assertEqual(self.em.get(foo_id), foo) + + +class ApplicationManagerTests(unittest.TestCase): + + def setUp(self): + self.tempdir = tempfile.mkdtemp() + fs = qvisqve.FileStore(self.tempdir) + self.am = qvisqve.ApplicationManager(fs) + + def tearDown(self): + shutil.rmtree(self.tempdir) + + def test_returns_no_callbacks_initially(self): + appid = 'test-app' + self.am.create(appid, {}) + self.assertEqual(self.am.get_callbacks(appid), []) + + def test_sets_callbacks(self): + appid = 'test-app' + url = 'http://facade.example.com/callback' + self.am.create(appid, {}) + self.am.add_callback(appid, url) + self.assertEqual(self.am.get_callbacks(appid), [url]) |