]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Vinkesh/Santhosh | Added tests to check the member and collection custom actions...
authorvinkesh banka <vinkeshb@thoughtworks.com>
Wed, 20 Jul 2011 13:38:16 +0000 (19:08 +0530)
committervinkesh banka <vinkeshb@thoughtworks.com>
Wed, 20 Jul 2011 13:38:16 +0000 (19:08 +0530)
tests/unit/test_extensions.py

index 750802381362abe548b4fc549efd424e257a269c..2e9bd05ce24efb97f54171b1afd58b68405780a0 100644 (file)
@@ -65,6 +65,28 @@ class ResourceExtensionTest(unittest.TestCase):
         self.assertEqual(200, response.status_int)
         self.assertEqual(extension_index_response, response.body)
 
+    def test_resource_extension_with_custom_member_action(self):
+        controller = StubController(extension_index_response)
+        member = {'custom_member_action': "GET"}
+        res_ext = extensions.ResourceExtension('tweedles', controller,
+                                               member_actions=member)
+        test_app = setup_extensions_test_app(StubExtensionManager(res_ext))
+
+        response = test_app.get("/tweedles/some_id/custom_member_action")
+        self.assertEqual(200, response.status_int)
+        self.assertEqual(json.loads(response.body)['member_action'], "value")
+
+    def test_resource_extension_with_custom_collection_action(self):
+        controller = StubController(extension_index_response)
+        collections = {'custom_collection_action': "GET"}
+        res_ext = extensions.ResourceExtension('tweedles', controller,
+                                               collection_actions=collections)
+        test_app = setup_extensions_test_app(StubExtensionManager(res_ext))
+
+        response = test_app.get("/tweedles/custom_collection_action")
+        self.assertEqual(200, response.status_int)
+        self.assertEqual(json.loads(response.body)['collection'], "value")
+
     def test_returns_404_for_non_existant_extension(self):
         test_app = setup_extensions_test_app(StubExtensionManager(None))
 
@@ -370,6 +392,12 @@ class StubController(wsgi.Controller):
     def update(self, request, id):
         return {'uneditable': 'original_value'}
 
+    def custom_member_action(self, request, id):
+        return {'member_action': 'value'}
+
+    def custom_collection_action(self, request):
+        return {'collection': 'value'}
+
 
 def app_factory(global_conf, **local_conf):
     conf = global_conf.copy()