Skip to content

Commit

Permalink
Add example metadata field to metadata standard object
Browse files Browse the repository at this point in the history
This may be used for search catalogue initialization.
  • Loading branch information
mark-saeon committed Aug 21, 2018
1 parent 2c387be commit 43c365a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ckanext/metadata/logic/action/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def metadata_standard_create(context, data_dict):
:type standard_version: string
:param parent_standard_id: the id or name of the metadata standard from which this standard is derived (nullable)
:type parent_standard_id: string
:param example_metadata_json: example of a JSON metadata dictionary that conforms to this standard (nullable)
:type example_metadata_json: string
:returns: the newly created metadata standard (unless 'return_id_only' is set to True
in the context, in which case just the metadata standard id will be returned)
Expand Down
2 changes: 2 additions & 0 deletions ckanext/metadata/logic/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ def metadata_standard_create_schema():
'standard_name': [v.not_empty, unicode],
'standard_version': [v.not_missing, unicode],
'parent_standard_id': [v.not_missing, unicode, v.object_exists('metadata_standard')],
'example_metadata_json': [v.not_missing, unicode, v.json_dict_validator],
'state': [ignore_not_sysadmin, ignore_missing],

# post-validation
Expand All @@ -268,6 +269,7 @@ def metadata_standard_show_schema():
_make_show_schema(schema)
schema.update({
'parent_standard_id': [v.convert_id_to_name('metadata_standard')],
'example_metadata_json': [v.deserialize_json],
})
return schema

Expand Down
1 change: 1 addition & 0 deletions ckanext/metadata/model/metadata_standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# we implement the self-relation "softly", otherwise revision table
# auto-generation gets confused about how to join to this table
Column('parent_standard_id', types.UnicodeText), # ForeignKey('metadata_standard.id')),
Column('example_metadata_json', types.UnicodeText),
UniqueConstraint('standard_name', 'standard_version')
)

Expand Down
1 change: 1 addition & 0 deletions ckanext/metadata/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class MetadataStandard(factory.Factory):
standard_name = factory.Sequence(lambda n: 'test_standard_{0:02d}'.format(n))
standard_version = '1.0'
parent_standard_id = ''
example_metadata_json = '{ "testkey": "testvalue" }'
title = factory.LazyAttribute(lambda obj: obj.standard_name.replace('_', ' ').title())
description = 'A test description for this test metadata standard.'

Expand Down
15 changes: 14 additions & 1 deletion ckanext/metadata/tests/test_metadata_standard_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def test_create_valid(self):
'standard_name': 'DataCite',
'standard_version': '1.0',
'parent_standard_id': '',
'example_metadata_json': '{ "testkey": "testvalue" }',
}
result, obj = self.test_action('metadata_standard_create', **input_dict)
assert_object_matches_dict(obj, input_dict)
Expand All @@ -33,6 +34,7 @@ def test_create_valid_setname(self):
'standard_name': 'DataCite',
'standard_version': '1.0',
'parent_standard_id': '',
'example_metadata_json': '',
}
result, obj = self.test_action('metadata_standard_create', **input_dict)
assert_object_matches_dict(obj, input_dict)
Expand All @@ -43,6 +45,7 @@ def test_create_valid_with_parent(self):
'standard_name': 'DataCite',
'standard_version': '1.0',
'parent_standard_id': metadata_standard['id'],
'example_metadata_json': '',
}
result, obj = self.test_action('metadata_standard_create', **input_dict)
assert_object_matches_dict(obj, input_dict)
Expand All @@ -53,6 +56,7 @@ def test_create_valid_with_parent_byname(self):
'standard_name': 'DataCite',
'standard_version': '1.0',
'parent_standard_id': metadata_standard['name'],
'example_metadata_json': '',
}
result, obj = self.test_action('metadata_standard_create', **input_dict)
input_dict['parent_standard_id'] = metadata_standard['id']
Expand All @@ -64,6 +68,7 @@ def test_create_valid_sysadmin_setid(self):
'standard_name': 'DataCite',
'standard_version': '1.0',
'parent_standard_id': '',
'example_metadata_json': '',
}
result, obj = self.test_action('metadata_standard_create', sysadmin=True, check_auth=True, **input_dict)
assert_object_matches_dict(obj, input_dict)
Expand All @@ -74,6 +79,7 @@ def test_create_valid_same_name_new_version(self):
'standard_name': metadata_standard['standard_name'],
'standard_version': metadata_standard['standard_version'] + 'a',
'parent_standard_id': '',
'example_metadata_json': '',
}
result, obj = self.test_action('metadata_standard_create', **input_dict)
assert_object_matches_dict(obj, input_dict)
Expand All @@ -84,6 +90,7 @@ def test_create_valid_same_version_different_name(self):
'standard_name': metadata_standard['standard_name'] + '_foo',
'standard_version': metadata_standard['standard_version'],
'parent_standard_id': '',
'example_metadata_json': '',
}
result, obj = self.test_action('metadata_standard_create', **input_dict)
assert_object_matches_dict(obj, input_dict)
Expand All @@ -99,6 +106,7 @@ def test_create_invalid_missing_params(self):
assert_error(result, 'standard_name', 'Missing parameter')
assert_error(result, 'standard_version', 'Missing parameter')
assert_error(result, 'parent_standard_id', 'Missing parameter')
assert_error(result, 'example_metadata_json', 'Missing parameter')

def test_create_invalid_missing_values(self):
result, obj = self.test_action('metadata_standard_create', should_error=True,
Expand Down Expand Up @@ -156,6 +164,7 @@ def test_update_valid(self):
'standard_name': 'Updated Standard Name',
'standard_version': 'v99',
'parent_standard_id': '',
'example_metadata_json': '{ "newtestkey": "newtestvalue" }',
}
result, obj = self.test_action('metadata_standard_update', **input_dict)
assert_object_matches_dict(obj, input_dict)
Expand All @@ -169,6 +178,7 @@ def test_update_valid_partial(self):
'standard_name': metadata_standard['standard_name'],
'standard_version': metadata_standard['standard_name'],
'parent_standard_id': '',
'example_metadata_json': '',
}
result, obj = self.test_action('metadata_standard_update', **input_dict)
assert_object_matches_dict(obj, input_dict)
Expand All @@ -183,6 +193,7 @@ def test_update_valid_change_parent_1(self):
'standard_name': metadata_standard1['standard_name'],
'standard_version': metadata_standard1['standard_version'],
'parent_standard_id': metadata_standard2['id'],
'example_metadata_json': '',
}
result, obj = self.test_action('metadata_standard_update', **input_dict)
assert_object_matches_dict(obj, input_dict)
Expand All @@ -196,6 +207,7 @@ def test_update_valid_change_parent_2(self):
'standard_name': metadata_standard3['standard_name'],
'standard_version': metadata_standard3['standard_version'],
'parent_standard_id': metadata_standard1['id'],
'example_metadata_json': '',
}
result, obj = self.test_action('metadata_standard_update', **input_dict)
assert_object_matches_dict(obj, input_dict)
Expand All @@ -217,6 +229,7 @@ def test_update_invalid_missing_params(self):
assert_error(result, 'standard_name', 'Missing parameter')
assert_error(result, 'standard_version', 'Missing parameter')
assert_error(result, 'parent_standard_id', 'Missing parameter')
assert_error(result, 'example_metadata_json', 'Missing parameter')

def test_update_invalid_missing_values(self):
metadata_standard = ckanext_factories.MetadataStandard()
Expand Down Expand Up @@ -296,7 +309,7 @@ def test_delete_with_child_standards(self):
id=metadata_standard1['id'])
metadata_standard2['parent_standard_id'] = None
del metadata_standard2['revision_id']
assert_object_matches_dict(ckanext_model.MetadataStandard.get(metadata_standard2['id']), metadata_standard2)
assert_object_matches_dict(ckanext_model.MetadataStandard.get(metadata_standard2['id']), metadata_standard2, json_values=('example_metadata_json',))

def test_delete_with_dependencies(self):
metadata_standard = ckanext_factories.MetadataStandard()
Expand Down

0 comments on commit 43c365a

Please sign in to comment.