aboutsummaryrefslogtreecommitdiff
path: root/tests/test_memory_store.py
blob: 8c199543a9a431b5af375ad22fb7bf27a2dd9998 (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
import unittest

from pyapd import objects
from pyapd.stores import memory, exceptions


class TestMemoryStore(unittest.TestCase):
    def setUp(self):
        self.store = memory.Store()
        self.oid = 'https://test/object/12345'
        self.obj = objects.Object(id=self.oid)
        self.store.add(self.obj)

    def test_add_object(self):
        oid = 'https://test/object/12345'
        obj = objects.Object(id=oid)
        self.store.add(obj)
        self.assertIn('object', self.store.objects)
        self.assertIn(oid, self.store.objects['object'])

    def test_get_object(self):
        res = self.store.get('object', self.oid)
        self.assertEqual(res, self.obj)

    def test_get_object_not_existing(self):
        oid = 'https://test/object/does_not_exist'
        with self.assertRaises(exceptions.DoesNotExist):
            self.store.get('object', oid)

    def test_get_object_wrong_type(self):
        with self.assertRaises(exceptions.UnknownObjectType):
            self.store.get('no_such_type', self.oid)