Allow new package_search to be accessed via a GET request

This commit is contained in:
Aitor Magán 2014-06-30 16:46:09 +02:00
parent f746754c24
commit 2756bbd60f
2 changed files with 15 additions and 6 deletions

View File

@ -201,10 +201,15 @@ class PrivateDatasets(p.SingletonPlugin, tk.DefaultDatasetForm):
_old_package_search = tk.get_action('package_search')
@tk.side_effect_free
def _new_package_search(context, data_dict):
if request.path == '/dataset':
valid_urls = ['/dataset', '/api/3/action/package_search',
'/api/3/action/dataset_search']
if request.path in valid_urls:
context.update({'ignore_capacity_check': True})
return _old_package_search(context, data_dict)
_new_package_search.__doc__ = _old_package_search.__doc__
# Modify the package_show function used across the system
return {'package_search': _new_package_search}

View File

@ -156,10 +156,11 @@ class PluginTest(unittest.TestCase):
self.assertEquals(auth_functions['package_update'], plugin.package_update)
@parameterized.expand([
('/dataset', True), # Include ignore_capacity_check
('/', False), # Not include ignore_capacity_check
('/datasets', False), # Not include ignore_capacity_check
('/api/rest/dataset', False) # Not include ignore_capacity_check. TODO: Maybe in the future this must change
('/dataset', True), # Include ignore_capacity_check
('/', False), # Not include ignore_capacity_check
('/datasets', False), # Not include ignore_capacity_check
('/api/3/action/package_search', True), # Include ignore_capacity_check
('/api/3/action/dataset_search', True) # Include ignore_capacity_check
])
def test_package_seach_modified(self, request_path, include_ignore_capacity):
# Mock the default actions
@ -169,18 +170,21 @@ class PluginTest(unittest.TestCase):
# Mock request
plugin.request.path = request_path
# Unmock the decorator
plugin.tk.side_effect_free = self._tk.side_effect_free
# Get the actions returned by the plugin
actions = self.privateDatasets.get_actions()
# Call the function
context = {'id': 'test', 'another_test': 'test_value'}
expected_context = context.copy()
data_dict = {'example': 'test', 'key': 'value'}
actions['package_search'](context, data_dict)
# Test if the default function has been called properly
package_search_old.assert_called_once_with(ANY, data_dict)
context_called = package_search_old.call_args_list[0][0][0] # First call, first argument
expected_context = context.copy()
if include_ignore_capacity:
expected_context.update({'ignore_capacity_check': True})