Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/1664.changes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added test coverage for DataStore column name errors from upstream [PR#224](https://github.com/open-data/ckan/pull/224)
35 changes: 34 additions & 1 deletion ckanext/canada/tests/test_datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from ckanext.xloader.job_exceptions import LoaderError
from ckanext.validation.jobs import run_validation_job

from ckanapi import LocalCKAN
from ckanapi import LocalCKAN, ValidationError

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -55,6 +55,8 @@ def setup_class(self):
if not plugins.plugin_loaded('validation'):
plugins.load('validation')

resource = Resource()
self.resource_id = resource['id']
self.action = LocalCKAN().action

@classmethod
Expand Down Expand Up @@ -91,6 +93,37 @@ def _setup_resource_upload(self, filename):

return resource, fake_stream

def test_max_column_length(self):
"""
Column length max is the pSQL 63 bytes max
"""
with pytest.raises(ValidationError) as ve:
self.action.datastore_create(
resource_id=self.resource_id,
force=True,
records=[],
fields=[{'id': 'thisfieldissooooooooolonnggggggthisfieldissooooooooolonnggggggthisfieldissooooooooolonngggggg', 'type': 'text'},])
err = ve.value.error_dict
assert err['fields'] == ['Column heading "thisfieldissooooooooolonnggggggthisfieldissooooooooolonnggggggthisfieldissooooooooolonngggggg" exceeds limit of 63 characters.']

def test_duplicate_column_names(self):
"""
Duplicate column names is not allowed and should show
them in the error message
"""
with pytest.raises(ValidationError) as ve:
self.action.datastore_create(
resource_id=self.resource_id,
force=True,
records=[],
fields=[{'id': 'this_is_a_field', 'type': 'text'},
{'id': 'this_is_a_field', 'type': 'text'},
{'id': 'this_is_a_field', 'type': 'text'},
{'id': 'another_dupe', 'type': 'text'},
{'id': 'another_dupe', 'type': 'text'}])
err = ve.value.error_dict
assert err['field'] == ['Duplicate column names are not supported: this_is_a_field, another_dupe']

@change_config('ckanext.validation.run_on_create_async', False)
@change_config('ckanext.validation.run_on_update_async', False)
@change_config('ckanext.validation.locales_offered', 'en')
Expand Down
Loading