|
1 | 1 | # encoding: utf-8 |
2 | 2 | """Unit tests for ckan/logic/action/patch.py.""" |
3 | 3 | import pytest |
| 4 | +import mock |
4 | 5 |
|
5 | 6 | from ckan.tests import helpers, factories |
| 7 | +from ckan.logic.action.get import package_show as core_package_show |
6 | 8 |
|
7 | 9 |
|
8 | 10 | @pytest.mark.usefixtures("clean_db", "with_request_context") |
@@ -171,3 +173,38 @@ def test_organization_patch_updating_single_field_when_public_user_details_is_fa |
171 | 173 | assert organization2["description"] == "somethingnew" |
172 | 174 | assert len(organization2["users"]) == 1 |
173 | 175 | assert organization2["users"][0]["name"] == user["name"] |
| 176 | + |
| 177 | + def test_package_patch_for_update(self): |
| 178 | + |
| 179 | + dataset = factories.Dataset() |
| 180 | + |
| 181 | + mock_package_show = mock.MagicMock() |
| 182 | + mock_package_show.side_effect = lambda context, data_dict: core_package_show(context, data_dict) |
| 183 | + |
| 184 | + with mock.patch.dict('ckan.logic._actions', {'package_show': mock_package_show}): |
| 185 | + helpers.call_action('package_patch', id=dataset['id'], notes='hey') |
| 186 | + assert mock_package_show.call_args_list[0][0][0].get('for_update') is True |
| 187 | + |
| 188 | + def test_resource_patch_for_update(self): |
| 189 | + |
| 190 | + dataset = factories.Dataset() |
| 191 | + resource = factories.Resource(package_id=dataset['id']) |
| 192 | + |
| 193 | + mock_package_show = mock.MagicMock() |
| 194 | + mock_package_show.side_effect = lambda context, data_dict: core_package_show(context, data_dict) |
| 195 | + |
| 196 | + with mock.patch.dict('ckan.logic._actions', {'package_show': mock_package_show}): |
| 197 | + helpers.call_action('resource_patch', id=resource['id'], description='hey') |
| 198 | + assert mock_package_show.call_args_list[0][0][0].get('for_update') is True |
| 199 | + |
| 200 | + def test_resource_update_for_update(self): |
| 201 | + |
| 202 | + dataset = factories.Dataset() |
| 203 | + resource = factories.Resource(package_id=dataset['id']) |
| 204 | + |
| 205 | + mock_package_show = mock.MagicMock() |
| 206 | + mock_package_show.side_effect = lambda context, data_dict: core_package_show(context, data_dict) |
| 207 | + |
| 208 | + with mock.patch.dict('ckan.logic._actions', {'package_show': mock_package_show}): |
| 209 | + helpers.call_action('resource_update', id=resource['id'], description='hey') |
| 210 | + assert mock_package_show.call_args_list[0][0][0].get('for_update') is True |
0 commit comments