Skip to content

Commit

Permalink
Merge branch 'fix-context-hacks'
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Dec 17, 2012
2 parents b83207b + 1b650f4 commit 94bf606
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 20 deletions.
7 changes: 0 additions & 7 deletions ckan/logic/action/create.py
Expand Up @@ -104,8 +104,6 @@ def package_create(context, data_dict):
'''
model = context['model']
user = context['user']
model.Session.remove()
model.Session()._context = context

package_type = data_dict.get('type')
package_plugin = lib_plugins.lookup_package_plugin(package_type)
Expand Down Expand Up @@ -179,8 +177,6 @@ def package_create(context, data_dict):
def package_create_validate(context, data_dict):
model = context['model']
schema = lib_plugins.lookup_package_plugin().form_to_db_schema()
model.Session.remove()
model.Session()._context = context

_check_access('package_create',context,data_dict)

Expand Down Expand Up @@ -867,9 +863,6 @@ def vocabulary_create(context, data_dict):
model = context['model']
schema = context.get('schema') or ckan.logic.schema.default_create_vocabulary_schema()

model.Session.remove()
model.Session()._context = context

_check_access('vocabulary_create', context, data_dict)

data, errors = _validate(data_dict, schema, context)
Expand Down
2 changes: 0 additions & 2 deletions ckan/logic/action/delete.py
Expand Up @@ -268,8 +268,6 @@ def task_status_delete(context, data_dict):
'''
model = context['model']
id = _get_or_bust(data_dict, 'id')
model.Session.remove()
model.Session()._context = context

entity = model.TaskStatus.get(id)

Expand Down
7 changes: 0 additions & 7 deletions ckan/logic/action/update.py
Expand Up @@ -107,7 +107,6 @@ def make_latest_pending_package_active(context, data_dict):

if not context.get('defer_commit'):
session.commit()
session.remove()


def related_update(context, data_dict):
Expand All @@ -129,7 +128,6 @@ def related_update(context, data_dict):
id = _get_or_bust(data_dict, "id")

schema = context.get('schema') or ckan.logic.schema.default_related_schema()
model.Session.remove()

related = model.Related.get(id)
context["related"] = related
Expand Down Expand Up @@ -170,7 +168,6 @@ def resource_update(context, data_dict):
user = context['user']
id = _get_or_bust(data_dict, "id")
schema = context.get('schema') or ckan.logic.schema.default_update_resource_schema()
model.Session.remove()

resource = model.Resource.get(id)
context["resource"] = resource
Expand Down Expand Up @@ -224,8 +221,6 @@ def package_update(context, data_dict):
model = context['model']
user = context['user']
name_or_id = data_dict.get("id") or data_dict['name']
model.Session.remove()
model.Session()._context = context

pkg = model.Package.get(name_or_id)
if pkg is None:
Expand Down Expand Up @@ -296,8 +291,6 @@ def package_update_validate(context, data_dict):
user = context['user']

id = _get_or_bust(data_dict, "id")
model.Session.remove()
model.Session()._context = context

pkg = model.Package.get(id)
context["package"] = pkg
Expand Down
9 changes: 5 additions & 4 deletions ckan/tests/functional/api/model/test_vocabulary.py
Expand Up @@ -42,6 +42,7 @@ def setup(self):
ckan.model.Session.commit()
self.sysadmin_user = ckan.model.User.get('admin')
self.normal_user = ckan.model.User.get('normal')
self.sysadmin_apikey = self.sysadmin_user.apikey

def clean_vocab(self):
ckan.model.Session.execute('delete from package_tag_revision')
Expand Down Expand Up @@ -237,7 +238,7 @@ def test_vocabulary_create_with_tags(self):
response = self._post('/api/action/vocabulary_create',
params=params,
extra_environ = {'Authorization':
str(self.sysadmin_user.apikey)})
str(self.sysadmin_apikey)})
assert response['success'] == True
assert response['result']
created_vocab = response['result']
Expand Down Expand Up @@ -284,7 +285,7 @@ def test_vocabulary_create_bad_tags(self):
response = self.app.post('/api/action/vocabulary_create',
params=json.dumps(params),
extra_environ = {'Authorization':
str(self.sysadmin_user.apikey)},
str(self.sysadmin_apikey)},
status=409)
assert response.json['success'] == False
assert response.json['error'].has_key('tags')
Expand Down Expand Up @@ -367,7 +368,7 @@ def test_vocabulary_create_invalid_name(self):
response = self.app.post('/api/action/vocabulary_create',
params=param_string,
extra_environ = {'Authorization':
str(self.sysadmin_user.apikey)},
str(self.sysadmin_apikey)},
status=409)
assert response.json['success'] == False
assert response.json['error']['name']
Expand Down Expand Up @@ -750,7 +751,7 @@ def test_add_tag_invalid_name(self):
response = self.app.post('/api/action/tag_create',
params=tag_string,
extra_environ = {'Authorization':
str(self.sysadmin_user.apikey)},
str(self.sysadmin_apikey)},
status=409)
assert response.json['success'] == False
assert response.json['error']['name']
Expand Down

0 comments on commit 94bf606

Please sign in to comment.