Rajaram/Vinkesh | Added examples of scoping extension alias in request and action extension

This commit is contained in:
vinkesh banka 2011-08-09 11:19:36 +05:30
parent 78dc8eef48
commit d2734a600a
2 changed files with 13 additions and 10 deletions

View File

@ -66,10 +66,12 @@ class Foxinsocks(object):
return resources
def get_actions(self):
return [extensions.ActionExtension('dummy_resources', 'add_tweedle',
return [extensions.ActionExtension('dummy_resources',
'FOXNSOX:add_tweedle',
self._add_tweedle_handler),
extensions.ActionExtension('dummy_resources',
'delete_tweedle', self._delete_tweedle_handler)]
'FOXNSOX:delete_tweedle',
self._delete_tweedle_handler)]
def get_request_extensions(self):
request_exts = []
@ -78,7 +80,7 @@ class Foxinsocks(object):
#NOTE: This only handles JSON responses.
# You can use content type header to test for XML.
data = json.loads(res.body)
data['googoose'] = req.GET.get('chewing')
data['FOXNSOX:googoose'] = req.GET.get('chewing')
res.body = json.dumps(data)
return res
@ -90,7 +92,7 @@ class Foxinsocks(object):
#NOTE: This only handles JSON responses.
# You can use content type header to test for XML.
data = json.loads(res.body)
data['big_bands'] = 'Pig Bands!'
data['FOXNSOX:big_bands'] = 'Pig Bands!'
res.body = json.dumps(data)
return res
@ -100,8 +102,9 @@ class Foxinsocks(object):
return request_exts
def _add_tweedle_handler(self, input_dict, req, id):
return "Tweedle {0} Added.".format(input_dict['add_tweedle']['name'])
return "Tweedle {0} Added.".format(
input_dict['FOXNSOX:add_tweedle']['name'])
def _delete_tweedle_handler(self, input_dict, req, id):
return "Tweedle {0} Deleted.".format(
input_dict['delete_tweedle']['name'])
input_dict['FOXNSOX:delete_tweedle']['name'])

View File

@ -114,7 +114,7 @@ class ActionExtensionTest(unittest.TestCase):
self.extension_app = setup_extensions_test_app()
def test_extended_action_for_adding_extra_data(self):
action_name = 'add_tweedle'
action_name = 'FOXNSOX:add_tweedle'
action_params = dict(name='Beetle')
req_body = json.dumps({action_name: action_params})
response = self.extension_app.post('/dummy_resources/1/action',
@ -122,7 +122,7 @@ class ActionExtensionTest(unittest.TestCase):
self.assertEqual("Tweedle Beetle Added.", response.body)
def test_extended_action_for_deleting_extra_data(self):
action_name = 'delete_tweedle'
action_name = 'FOXNSOX:delete_tweedle'
action_params = dict(name='Bailey')
req_body = json.dumps({action_name: action_params})
response = self.extension_app.post("/dummy_resources/1/action",
@ -187,8 +187,8 @@ class RequestExtensionTest(BaseTest):
response = app.get("/dummy_resources/1?chewing=newblue")
response_data = json.loads(response.body)
self.assertEqual('newblue', response_data['googoose'])
self.assertEqual("Pig Bands!", response_data['big_bands'])
self.assertEqual('newblue', response_data['FOXNSOX:googoose'])
self.assertEqual("Pig Bands!", response_data['FOXNSOX:big_bands'])
def test_edit_previously_uneditable_field(self):