Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix format normalization configuration #175

Merged
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
4 changes: 2 additions & 2 deletions ckanext/dcat/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,8 +947,8 @@ def parse_dataset(self, dataset_dict, dataset_ref):
resource_dict[key] = json.dumps(values)

# Format and media type
normalize_ckan_format = config.get(
'ckanext.dcat.normalize_ckan_format', True)
normalize_ckan_format = toolkit.asbool(config.get(
'ckanext.dcat.normalize_ckan_format', True))
imt, label = self._distribution_format(distribution,
normalize_ckan_format)

Expand Down
34 changes: 29 additions & 5 deletions ckanext/dcat/tests/test_euro_dcatap_profile_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ def test_distribution_format_format_only(self):
resource = datasets[0]['resources'][0]

eq_(resource['format'], u'CSV')
assert 'mimetype' not in resource

def test_distribution_format_imt_only(self):
g = Graph()
Expand All @@ -389,7 +390,7 @@ def test_distribution_format_imt_only(self):
else:
eq_(resource['format'], u'text/csv')

@helpers.change_config('ckanext.dcat.normalize_ckan_format', False)
@helpers.change_config('ckanext.dcat.normalize_ckan_format', 'False')
def test_distribution_format_imt_only_normalize_false(self):
g = Graph()

Expand All @@ -412,16 +413,16 @@ def test_distribution_format_imt_only_normalize_false(self):
eq_(resource['format'], u'text/csv')
eq_(resource['mimetype'], u'text/csv')

@helpers.change_config('ckanext.dcat.normalize_ckan_format', False)
def test_distribution_format_format_only_normalize_false(self):
@helpers.change_config('ckanext.dcat.normalize_ckan_format', 'False')
def test_distribution_format_format_only_without_slash_normalize_false(self):
g = Graph()

dataset1 = URIRef("http://example.org/datasets/1")
g.add((dataset1, RDF.type, DCAT.Dataset))

distribution1_1 = URIRef("http://example.org/datasets/1/ds/1")
g.add((distribution1_1, RDF.type, DCAT.Distribution))
g.add((distribution1_1, DCT['format'], Literal('CSV')))
g.add((distribution1_1, DCT['format'], Literal('Comma Separated Values')))
g.add((dataset1, DCAT.distribution, distribution1_1))

p = RDFParser(profiles=['euro_dcat_ap'])
Expand All @@ -432,9 +433,32 @@ def test_distribution_format_format_only_normalize_false(self):

resource = datasets[0]['resources'][0]

eq_(resource['format'], u'CSV')
eq_(resource['format'], u'Comma Separated Values')
assert 'mimetype' not in resource

@helpers.change_config('ckanext.dcat.normalize_ckan_format', 'False')
def test_distribution_format_format_only_with_slash_normalize_false(self):
g = Graph()

dataset1 = URIRef("http://example.org/datasets/1")
g.add((dataset1, RDF.type, DCAT.Dataset))

distribution1_1 = URIRef("http://example.org/datasets/1/ds/1")
g.add((distribution1_1, RDF.type, DCAT.Distribution))
g.add((distribution1_1, DCT['format'], Literal('text/csv')))
g.add((dataset1, DCAT.distribution, distribution1_1))

p = RDFParser(profiles=['euro_dcat_ap'])

p.g = g

datasets = [d for d in p.datasets()]

resource = datasets[0]['resources'][0]

eq_(resource['format'], u'text/csv')
eq_(resource['mimetype'], u'text/csv')

def test_distribution_format_unknown_imt(self):
g = Graph()

Expand Down