diff options
author | Aaron Bentley <abentley@panoramicfeedback.com> | 2005-12-21 09:04:46 -0500 |
---|---|---|
committer | Aaron Bentley <abentley@panoramicfeedback.com> | 2005-12-21 09:04:46 -0500 |
commit | bfd516c51fa78f8a1d83c5aabc7b2f2048f3bdb6 (patch) | |
tree | f258beb8c8512c0e440bf22ee44d4c394972e326 /beweb | |
parent | 426f2d8304a6928aeb8e43392cf911912ec34908 (diff) | |
download | bugseverywhere-bfd516c51fa78f8a1d83c5aabc7b2f2048f3bdb6.tar.gz |
Prest correctly instantiates the desired object
Diffstat (limited to 'beweb')
-rw-r--r-- | beweb/beweb/prest.py | 16 |
1 files changed, 10 insertions, 6 deletions
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') |