summaryrefslogtreecommitdiff
path: root/qvisqve/entity_manager_tests.py
blob: 4ad9bb12d23cbccd1ffd4589aabcd496fb5a6e72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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):
        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)


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])