Skip to content

Commit

Permalink
Minor tweaks, need completing
Browse files Browse the repository at this point in the history
  • Loading branch information
rossjones committed Jan 27, 2014
1 parent 4667b34 commit f64b63b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion ckan/lib/dictization/model_dictize.py
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions ckan/lib/dictization/model_save.py
Expand Up @@ -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)

Expand Down
14 changes: 7 additions & 7 deletions ckan/tests/lib/test_dictization.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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)


Expand Down Expand Up @@ -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'
Expand All @@ -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):

Expand Down
2 changes: 1 addition & 1 deletion ckan/tests/logic/test_action.py
Expand Up @@ -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)})
Expand Down
2 changes: 1 addition & 1 deletion test-core.ini
Expand Up @@ -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
Expand Down

0 comments on commit f64b63b

Please sign in to comment.