diff --git a/ckan/lib/dictization/model_dictize.py b/ckan/lib/dictization/model_dictize.py index f57e4cee6b7..4cae9aceb2d 100644 --- a/ckan/lib/dictization/model_dictize.py +++ b/ckan/lib/dictization/model_dictize.py @@ -240,7 +240,7 @@ def package_dictize(pkg, context): resource_rev = model.resource_revision_table q = select([resource_rev]).where(resource_rev.c.package_id == pkg.id) result = _execute_with_revision(q, resource_rev, context) - result_dict["resources"] = resource_list_dictize(result or [], context) + result_dict["resources"] = resource_list_dictize(result, context) result_dict['num_resources'] = len(result_dict.get('resources', [])) #tags diff --git a/ckan/lib/dictization/model_save.py b/ckan/lib/dictization/model_save.py index 0fe2c319541..57c151e6b7e 100644 --- a/ckan/lib/dictization/model_save.py +++ b/ckan/lib/dictization/model_save.py @@ -76,6 +76,8 @@ def package_resource_list_save(res_dicts, package, context): obj_list = [] for res_dict in res_dicts or []: + if not u'package_id' in res_dict or not res_dict[u'package_id']: + res_dict[u'package_id'] = package.id obj = resource_dict_save(res_dict, context) obj_list.append(obj) diff --git a/ckan/tests/lib/test_dictization.py b/ckan/tests/lib/test_dictization.py index b7352e5b427..4edbcd162ef 100644 --- a/ckan/tests/lib/test_dictization.py +++ b/ckan/tests/lib/test_dictization.py @@ -141,7 +141,7 @@ def teardown_class(cls): def remove_changable_columns(self, dict): for key, value in dict.items(): - if key.endswith('id') and key not in ('license_id', 'creator_user_id'): + if key.endswith('id') and key not in ('license_id', 'creator_user_id','package_id'): dict.pop(key) if key == 'created': dict.pop(key) @@ -200,7 +200,6 @@ def test_01_dictize_main_objects_simple(self): result = resource_dictize(resource, context) self.remove_changable_columns(result) - assert result == { u'alt_url': u'alt123', 'cache_last_updated': None, @@ -220,7 +219,8 @@ def test_01_dictize_main_objects_simple(self): 'url': u'http://www.annakarenina.com/download/x=1&y=2', 'url_type': None, 'webstore_last_updated': None, - 'webstore_url': None + 'webstore_url': None, + 'package_id': pkg.id }, pprint(result) ## package extra @@ -233,7 +233,8 @@ def test_01_dictize_main_objects_simple(self): assert result == { 'key': u'genre', 'state': u'active', - 'value': u'romantic novel' + 'value': u'romantic novel', + 'package_id': pkg.id }, pprint(result) @@ -369,8 +370,6 @@ def test_08_package_save(self): anna1 = model.Session.query(model.Package).filter_by(name='annakarenina').one() - - anna_dictized = self.remove_changable_columns(package_dictize(anna1, context)) anna_dictized["name"] = u'annakarenina3' @@ -386,7 +385,8 @@ def test_08_package_save(self): anna_original = pformat(anna_dictized) anna_after_save = pformat(package_dictized) - assert self.remove_changable_columns(package_dictize(pkg, context)) == anna_dictized, "\n".join(unified_diff(anna_original.split("\n"), anna_after_save.split("\n"))) + assert self.remove_changable_columns(package_dictize(pkg, context)) == anna_dictized,\ + "\n".join(unified_diff(anna_original.split("\n"), anna_after_save.split("\n"))) def test_09_package_alter(self): diff --git a/ckan/tests/logic/test_action.py b/ckan/tests/logic/test_action.py index 316d6533a5e..690baa1c012 100644 --- a/ckan/tests/logic/test_action.py +++ b/ckan/tests/logic/test_action.py @@ -814,7 +814,7 @@ def test_19_update_resource(self): 'title': u'A Novel By Tolstoy', 'url': u'http://www.annakarenina.com', } - +# TODO: How do we get the package_id set in resource when creating a package postparams = '%s=1' % json.dumps(package) res = self.app.post('/api/action/package_create', params=postparams, extra_environ={'Authorization': str(self.sysadmin_user.apikey)}) diff --git a/test-core.ini b/test-core.ini index 74e35eb5ef0..5a124d281bd 100644 --- a/test-core.ini +++ b/test-core.ini @@ -18,7 +18,7 @@ debug = false # Specify the database for SQLAlchemy to use: # * Postgres is currently required for a production CKAN deployment # * Sqlite (memory or file) can be used as a quick alternative for testing -sqlalchemy.url = postgresql://ckan_default:pass@localhost/ckan_test +sqlalchemy.url = postgresql://ross:pass@localhost/ckan_test #sqlalchemy.url = sqlite:/// ## Datastore