diff --git a/ckan/new_tests/logic/test_conversion.py b/ckan/new_tests/logic/test_conversion.py index 8c892d5ea37..fad4c58da63 100644 --- a/ckan/new_tests/logic/test_conversion.py +++ b/ckan/new_tests/logic/test_conversion.py @@ -7,6 +7,8 @@ import ckan.plugins as p import ckan.lib.plugins as lib_plugins from ckan.lib.navl.dictization_functions import validate +from ckan.logic.schema import default_extras_schema +from ckan.logic.converters import convert_to_extras eq_ = nose.tools.eq_ @@ -14,18 +16,9 @@ class TestConvertToExtras(object): - @classmethod - def setup_class(cls): - p.load('example_idatasetform') - - @classmethod - def teardown_class(cls): - p.unload('example_idatasetform') - def test_convert_to_extras_field_gets_stored_as_extra(self): data_dict = { - 'name': 'test-dataset', 'custom_text': 'Hi', } @@ -34,8 +27,10 @@ def test_convert_to_extras_field_gets_stored_as_extra(self): 'session': model.Session, } - package_plugin = lib_plugins.lookup_package_plugin('dataset') - schema = package_plugin.create_package_schema() + schema = { + 'custom_text': [convert_to_extras], + 'extras': default_extras_schema(), + } data, errors = validate(data_dict, schema, context) @@ -47,7 +42,6 @@ def test_convert_to_extras_field_gets_stored_as_extra(self): def test_convert_to_extras_field_can_be_combined_with_a_proper_extra(self): data_dict = { - 'name': 'test-dataset', 'custom_text': 'Hi', 'extras': [ {'key': 'proper_extra', 'value': 'Bye'}, @@ -55,14 +49,16 @@ def test_convert_to_extras_field_can_be_combined_with_a_proper_extra(self): ] } + schema = { + 'custom_text': [convert_to_extras], + 'extras': default_extras_schema(), + } + context = { 'model': model, 'session': model.Session, } - package_plugin = lib_plugins.lookup_package_plugin('dataset') - schema = package_plugin.create_package_schema() - data, errors = validate(data_dict, schema, context) assert 'extras' in data @@ -75,7 +71,6 @@ def test_convert_to_extras_field_can_be_combined_with_a_proper_extra(self): def test_convert_to_extras_field_can_be_combined_with_more_extras(self): data_dict = { - 'name': 'test-dataset', 'custom_text': 'Hi', 'extras': [ {'key': 'proper_extra', 'value': 'Bye'}, @@ -83,14 +78,16 @@ def test_convert_to_extras_field_can_be_combined_with_more_extras(self): ] } + schema = { + 'custom_text': [convert_to_extras], + 'extras': default_extras_schema(), + } + context = { 'model': model, 'session': model.Session, } - package_plugin = lib_plugins.lookup_package_plugin('dataset') - schema = package_plugin.create_package_schema() - data, errors = validate(data_dict, schema, context) assert 'extras' in data @@ -103,7 +100,6 @@ def test_convert_to_extras_field_can_be_combined_with_more_extras(self): def test_convert_to_extras_field_can_be_combined_with_extras_deleted(self): data_dict = { - 'name': 'test-dataset', 'custom_text': 'Hi', 'extras': [ {'key': 'proper_extra', 'value': 'Bye', 'deleted': True}, @@ -111,14 +107,16 @@ def test_convert_to_extras_field_can_be_combined_with_extras_deleted(self): ] } + schema = { + 'custom_text': [convert_to_extras], + 'extras': default_extras_schema(), + } + context = { 'model': model, 'session': model.Session, } - package_plugin = lib_plugins.lookup_package_plugin('dataset') - schema = package_plugin.create_package_schema() - data, errors = validate(data_dict, schema, context) assert 'extras' in data @@ -131,21 +129,22 @@ def test_convert_to_extras_field_can_be_combined_with_extras_deleted(self): def test_convert_to_extras_free_extra_can_not_have_the_same_key(self): data_dict = { - 'name': 'test-dataset', 'custom_text': 'Hi', 'extras': [ {'key': 'custom_text', 'value': 'Bye'}, ] } + schema = { + 'custom_text': [convert_to_extras], + 'extras': default_extras_schema(), + } + context = { 'model': model, 'session': model.Session, } - package_plugin = lib_plugins.lookup_package_plugin('dataset') - schema = package_plugin.create_package_schema() - data, errors = validate(data_dict, schema, context) assert 'extras' in errors