# 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 . 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): entity = { 'foo': 'foo is cool', } foo_id = 'foo is my entity' self.em.create(foo_id, entity) self.assertEqual(self.em.list(), [foo_id]) self.assertEqual(self.em.get(foo_id), entity) def test_deletes_an_entity(self): entity = { 'foo': 'foo is cool', } foo_id = 'foo is my entity' self.em.create(foo_id, entity) self.em.delete(foo_id) self.assertEqual(self.em.list(), []) with self.assertRaises(qvisqve.ResourceDoesNotExist): self.em.get('does-not-exist') 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])