Skip to content

Commit

Permalink
[#1894] Move test files to proper place
Browse files Browse the repository at this point in the history
Moved functional tests to ckan/new_tests/logic/test_conversion.py and
added new unit tests for `convert_to_extras` to
ckan/new_tests/logic/test_converters.py
  • Loading branch information
amercader committed Aug 25, 2014
1 parent 6f8a0ca commit 9762a85
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
@@ -1,3 +1,6 @@
'''Functional tests for converters in ckan/logic/converters.py.
'''
import nose

from ckan import model
Expand Down Expand Up @@ -96,3 +99,31 @@ def test_convert_to_extras_field_can_be_combined_with_more_extras(self):
['custom_text', 'proper_extra', 'proper_extra2'])
eq_(sorted([e['value'] for e in data['extras']]),
['Bye', 'Bye2', 'Hi'])

def test_convert_to_extras_field_can_be_combined_with_more_extras_deleted(self):

data_dict = {
'name': 'test-dataset',
'custom_text': 'Hi',
'extras': [
{'key': 'proper_extra', 'value': 'Bye', 'deleted': True},
{'key': 'proper_extra2', 'value': 'Bye2'},
]
}

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
eq_(len(data['extras']), 3)
eq_(sorted([e['key'] for e in data['extras']]),
['custom_text', 'proper_extra', 'proper_extra2'])
eq_(sorted([e['value'] for e in data['extras']]),
['Bye', 'Bye2', 'Hi'])
52 changes: 51 additions & 1 deletion ckan/new_tests/logic/test_converters.py
Expand Up @@ -2,10 +2,14 @@
'''Unit tests for ckan/logic/converters.py.
'''
import nose
import unittest
import ckan.logic.converters as converters


eq_ = nose.tools.eq_


class TestRemoveWhitespaceConverter(unittest.TestCase):
def test_leading_space(self):
string = ' http://example.com'
Expand All @@ -27,6 +31,52 @@ def test_space_between(self):

def test_not_a_string(self):
string = 12345
expected = 12345
converted = converters.remove_whitespace(string, {})
self.assertEqual(string, converted)


class TestConvertToExtras(unittest.TestCase):

def test_convert_to_extras_output_unflattened(self):

key = ('test_field',)
data = {
('test_field',): 'test_value',
}
errors = {}
context = {}

converters.convert_to_extras(key, data, errors, context)

eq_(data[('extras', 0, 'key')], 'test_field')
eq_(data[('extras', 0, 'value')], 'test_value')

assert not ('extras',) in data

eq_(errors, {})

def test_convert_to_extras_output_unflattened_with_correct_index(self):

key = ('test_field',)
data = {
('test_field',): 'test_value',
('extras', 0, 'deleted'): '',
('extras', 0, 'id'): '',
('extras', 0, 'key'): 'proper_extra',
('extras', 0, 'revision_timestamp'): '',
('extras', 0, 'state'): '',
('extras', 0, 'value'): 'proper_extra_value',
}
errors = {}
context = {}

converters.convert_to_extras(key, data, errors, context)

eq_(data[('extras', 0, 'key')], 'proper_extra')
eq_(data[('extras', 0, 'value')], 'proper_extra_value')
eq_(data[('extras', 1, 'key')], 'test_field')
eq_(data[('extras', 1, 'value')], 'test_value')

assert not ('extras',) in data

eq_(errors, {})

0 comments on commit 9762a85

Please sign in to comment.