Skip to content

Commit

Permalink
[#621] Add tests for duplicate extras key error
Browse files Browse the repository at this point in the history
This code path was not covered by the tests.

Conflicts:

	ckan/tests/logic/test_action.py
  • Loading branch information
Sean Hammond authored and amercader committed Apr 17, 2013
1 parent 2c19a2a commit 0440e44
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions ckan/tests/logic/test_action.py
Expand Up @@ -1132,6 +1132,40 @@ def test_42_resource_search_accessible_via_get_request(self):
assert "index" in resource['description'].lower()
assert "json" in resource['format'].lower()

def test_package_create_duplicate_extras_error(self):
import ckan.tests
import paste.fixture
import pylons.test

# Posting a dataset dict to package_create containing two extras dicts
# with the same key, should return a Validation Error.
app = paste.fixture.TestApp(pylons.test.pylonsapp)
error = ckan.tests.call_action_api(app, 'package_create',
apikey=self.sysadmin_user.apikey, status=409,
name='foobar', extras=[{'key': 'foo', 'value': 'bar'},
{'key': 'foo', 'value': 'gar'}])
assert error['__type'] == 'Validation Error'
assert error['extras_validation'] == 'Duplicate key "foo"'

def test_package_update_duplicate_extras_error(self):
import ckan.tests
import paste.fixture
import pylons.test

# We need to create a package first, so that we can update it.
app = paste.fixture.TestApp(pylons.test.pylonsapp)
package = ckan.tests.call_action_api(app, 'package_create',
apikey=self.sysadmin_user.apikey, name='foobar')

# Posting a dataset dict to package_update containing two extras dicts
# with the same key, should return a Validation Error.
package['extras'] = [{'key': 'foo', 'value': 'bar'},
{'key': 'foo', 'value': 'gar'}]
error = ckan.tests.call_action_api(app, 'package_update',
apikey=self.sysadmin_user.apikey, status=409, **package)
assert error['__type'] == 'Validation Error'
assert error['extras_validation'] == 'Duplicate key "foo"'

class TestActionTermTranslation(WsgiAppCase):

@classmethod
Expand Down Expand Up @@ -1470,5 +1504,3 @@ def test_before_view(self):

res = self.app.get('/dataset?q=')
assert res.body.count('string_not_found_in_rest_of_template') == 2


0 comments on commit 0440e44

Please sign in to comment.