aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2019-04-14 17:46:11 +0200
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2019-04-14 17:46:11 +0200
commit615c439ad45eee9eb709200e3727d1d6eacaecfe (patch)
tree304341561189d78795c463c00be79a55088efa0f /tests
parentc279b53fb219e1a943b7092d8db49a28d56f0b08 (diff)
Start working on storage backends
Diffstat (limited to 'tests')
-rw-r--r--tests/test_memory_store.py32
-rw-r--r--tests/test_objects.py6
2 files changed, 35 insertions, 3 deletions
diff --git a/tests/test_memory_store.py b/tests/test_memory_store.py
new file mode 100644
index 0000000..8c19954
--- /dev/null
+++ b/tests/test_memory_store.py
@@ -0,0 +1,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)
diff --git a/tests/test_objects.py b/tests/test_objects.py
index 68bc900..4358e41 100644
--- a/tests/test_objects.py
+++ b/tests/test_objects.py
@@ -6,14 +6,14 @@ from pyapd import objects
class TestObjects(unittest.TestCase):
def test_activity_from_json(self):
- act = objects.ActivityObject.from_jsons('''{
+ act = objects.Object.from_jsons('''{
"id": "http://example.org/123456"
}''')
- self.assertIsInstance(act, objects.ActivityObject)
+ self.assertIsInstance(act, objects.Object)
self.assertEqual(act.ap_id, 'http://example.org/123456')
def test_activity_to_json(self):
- act = objects.ActivityObject(
+ act = objects.Object(
id="http://example.org/123456"
)
data = act.to_jsons()