Prest correctly instantiates the desired object
authorAaron Bentley <abentley@panoramicfeedback.com>
Wed, 21 Dec 2005 14:04:46 +0000 (09:04 -0500)
committerAaron Bentley <abentley@panoramicfeedback.com>
Wed, 21 Dec 2005 14:04:46 +0000 (09:04 -0500)
beweb/beweb/prest.py

index 3a94ab537b2be982c4be7d0ea7b91dc25fc0328b..9a6c3376ba1b438e5ff82b8fb4e1bcc871f8f465 100644 (file)
@@ -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')