From: Aaron Bentley Date: Wed, 21 Dec 2005 14:04:46 +0000 (-0500) Subject: Prest correctly instantiates the desired object X-Git-Tag: 1.0.0~253 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=bfd516c51fa78f8a1d83c5aabc7b2f2048f3bdb6;p=be.git Prest correctly instantiates the desired object --- diff --git a/beweb/beweb/prest.py b/beweb/beweb/prest.py index 3a94ab5..9a6c337 100644 --- a/beweb/beweb/prest.py +++ b/beweb/beweb/prest.py @@ -7,15 +7,15 @@ class PrestHandler(object): def __init__(self): object.__init__(self) - def decode(self, path, data=None, has_id=False): - """Convert the """ + def decode(self, path, data=None): + """Convert the path into a handler, a resource, data, and extra_path""" if data is None: data = {} - if len(path) < 2 or not hasattr(self, path[1]): - if len(path) == 1: - resource = self.instantiate(*data) - else: + if len(path) < 2 or not (path[0] is None or hasattr(self, path[0])): + if len(path) == 0: resource = None + else: + resource = self.instantiate(**data) return self, resource, data, path[1:] if len(path) > 2: data[path[1]] = path[2] @@ -31,6 +31,7 @@ class PrestTester(TestCase): class ProjectHandler(PrestHandler): def dispatch(self, project_data, project, *args, **kwargs): self.project_id = project_data['project'] + self.project_data = project_data self.resource = project self.args = args self.kwargs = kwargs @@ -47,6 +48,9 @@ class PrestTester(TestCase): self.assertEqual(['bloop', 'yeah'], extra) foo.default(*['project', '27', 'extra'], **{'a':'b', 'b':'97'}) self.assertEqual(foo.project.args, ('extra',)) + self.assertEqual(foo.project.kwargs, {'a':'b', 'b':'97'}) + self.assertEqual(foo.project.project_data, {'project': '27'}) + self.assertEqual(foo.project.resource, ['27']) def test(): patchesTestSuite = unittest.makeSuite(PrestTester,'test')