From bb4c1a764072d06f9d650d8c3287da3b1d26379d Mon Sep 17 00:00:00 2001 From: vinkesh banka Date: Wed, 20 Jul 2011 19:08:16 +0530 Subject: [PATCH] Vinkesh/Santhosh | Added tests to check the member and collection custom actions of ResourceExtensions --- tests/unit/test_extensions.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/unit/test_extensions.py b/tests/unit/test_extensions.py index 750802381..2e9bd05ce 100644 --- a/tests/unit/test_extensions.py +++ b/tests/unit/test_extensions.py @@ -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() -- 2.45.2