From 04d349cae45b2d37f009fe87113615eb7093d6e6 Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Sat, 27 Apr 2019 16:05:25 +0200 Subject: Remove concept of unknown object type --- pyapd/app.py | 7 ++----- pyapd/stores/exceptions.py | 6 ------ pyapd/stores/memory.py | 13 +++---------- tests/test_memory_store.py | 11 +++-------- 4 files changed, 8 insertions(+), 29 deletions(-) diff --git a/pyapd/app.py b/pyapd/app.py index 311e4f5..ec8d523 100644 --- a/pyapd/app.py +++ b/pyapd/app.py @@ -13,11 +13,8 @@ class ObjectHandler(tornado.web.RequestHandler): def get(self, oid): oid = self.request.full_url() try: - obj = self.application.store.get('object', oid) - except ( - stores.exceptions.UnknownObjectType, - stores.exceptions.DoesNotExist, - ): + obj = self.application.store.get(oid) + except stores.exceptions.DoesNotExist: raise tornado.web.HTTPError( status_code=404, ) diff --git a/pyapd/stores/exceptions.py b/pyapd/stores/exceptions.py index 644a237..4d80587 100644 --- a/pyapd/stores/exceptions.py +++ b/pyapd/stores/exceptions.py @@ -3,9 +3,3 @@ class DoesNotExist(Exception): """ Raised when an object is not found in the store. """ - - -class UnknownObjectType(Exception): - """ - Raised when an unknown object is referred. - """ diff --git a/pyapd/stores/memory.py b/pyapd/stores/memory.py index 0b1140c..e81b5cf 100644 --- a/pyapd/stores/memory.py +++ b/pyapd/stores/memory.py @@ -7,18 +7,11 @@ class Store(): self.objects = {} def add(self, obj: objects.Object): - obj_type = type(obj).__name__.lower() - if obj_type not in self.objects: - self.objects[obj_type] = {} - self.objects[obj_type][obj.ap_id] = obj + self.objects[obj.ap_id] = obj - def get(self, obj_type: str, oid: str) -> objects.Object: - if obj_type not in self.objects: - raise exceptions.UnknownObjectType( - "Object type {} is unknown".format(obj_type) - ) + def get(self, oid: str) -> objects.Object: try: - return self.objects[obj_type][oid] + return self.objects[oid] except KeyError: raise exceptions.DoesNotExist( "An object with id {} does not exist".format(oid) diff --git a/tests/test_memory_store.py b/tests/test_memory_store.py index 8c19954..899a776 100644 --- a/tests/test_memory_store.py +++ b/tests/test_memory_store.py @@ -15,18 +15,13 @@ class TestMemoryStore(unittest.TestCase): 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']) + self.assertIn(oid, self.store.objects) def test_get_object(self): - res = self.store.get('object', self.oid) + res = self.store.get(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) + self.store.get(oid) -- cgit v1.2.3