Skip to content

Commit

Permalink
[#1894] Simplify conversion tests
Browse files Browse the repository at this point in the history
Don't load `example_idatasetform` as this causes failures in other
tests. Rather pass a schema directly.
  • Loading branch information
amercader committed Aug 26, 2014
1 parent 3158a75 commit 80c8c44
Showing 1 changed file with 26 additions and 27 deletions.
53 changes: 26 additions & 27 deletions ckan/new_tests/logic/test_conversion.py
Expand Up @@ -7,25 +7,18 @@
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_


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',
}

Expand All @@ -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)

Expand All @@ -47,22 +42,23 @@ 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'},

]
}

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
Expand All @@ -75,22 +71,23 @@ 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'},
{'key': 'proper_extra2', 'value': 'Bye2'},
]
}

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
Expand All @@ -103,22 +100,23 @@ 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},
{'key': 'proper_extra2', 'value': 'Bye2'},
]
}

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
Expand All @@ -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
Expand Down

0 comments on commit 80c8c44

Please sign in to comment.