Commits

Hong Minhee  committed c68c9cf

Made method decorators can take view function as default view and negotiative views by keywords.

  • Participants
  • Parent commits c2e7e46

Comments (0)

Files changed (2)

File test/rom_test.py

     def setUp(self):
         self.method = MethodDecorator("GET")
 
-    def assert_same(self, expected, actual):
-        self.assertEquals(id(expected), id(actual))
-
     def assert_handler(self, expected, resource, type):
         from vlastic.rom.resource import METHOD_HANDLER_ATTRIBUTE_NAME as name
         view = getattr(resource, name)["GET"]
         self.assertTrue(isinstance(view, NegotiativeView))
-        self.assert_same(expected, view[type])
+        self.assertEquals(id(expected), id(view[type]))
+
+    def assert_default_view(self, expected, resource):
+        from vlastic.rom.resource import METHOD_HANDLER_ATTRIBUTE_NAME as name
+        view = getattr(resource, name)["GET"]
+        self.assertTrue(isinstance(view, NegotiativeView))
+        self.assertEquals(id(expected), id(view.default_view))
 
     def test_negotiation(self):
         decorator = self.method({
         self.assert_handler(test_view, resource, "image/png")
 
 
+    def test_kwargs_with_default(self):
+        decorator = self.method(test_view, html=NegotiativeViewTest._html_view)
+        resource = lambda: None
+        decorator(resource)
+        self.assert_handler(
+            NegotiativeViewTest._html_view,
+            resource, "text/html"
+        )
+        self.assert_handler(
+            NegotiativeViewTest._html_view,
+            resource, "application/xhtml+xml"
+        )
+        self.assert_default_view(test_view, resource)
+
+
 class NegotiativeViewTest(unittest.TestCase):
     """Unit tests for NegotiativeView class."""
 

File vlastic/rom/decorator.py

         view = _
         if isinstance(view, dict):
             view = NegotiativeView(view)
-        elif _ is None:
+        elif kwtypes:
             view = NegotiativeView()
+            if hasattr(_, "__call__"):
+                view.default_view = _
         if isinstance(view, NegotiativeView):
             for type, view4type in kwtypes.items():
                 for mime in KEYWORDS_MIME_MAP[type]: