Skip to content

Commit

Permalink
Update lib tests
Browse files Browse the repository at this point in the history
  • Loading branch information
smotornyuk committed Oct 25, 2019
1 parent 72a3656 commit cefe30b
Show file tree
Hide file tree
Showing 19 changed files with 3,676 additions and 3,308 deletions.
4 changes: 2 additions & 2 deletions ckan/tests/lib/__init__.py
@@ -1,6 +1,6 @@
# encoding: utf-8

'''**All lib functions should have tests**.
"""**All lib functions should have tests**.
.. todo::
Expand All @@ -16,4 +16,4 @@
extensions) to use, so all of these functions should really have tests and
docstrings. It's probably worth focusing on these modules first.
'''
"""
739 changes: 396 additions & 343 deletions ckan/tests/lib/dictization/test_model_dictize.py

Large diffs are not rendered by default.

64 changes: 25 additions & 39 deletions ckan/tests/lib/navl/test_dictization_functions.py
Expand Up @@ -5,89 +5,75 @@
from ckan.lib.navl.dictization_functions import validate, Invalid


eq_ = nose.tools.eq_


class TestValidate(object):

def test_validate_passes_a_copy_of_the_context_to_validators(self):

# We need to pass some keys on the context, otherwise validate
# will do context = context || {}, which creates a new one, defeating
# the purpose of this test
context = {'foo': 'bar'}
context = {"foo": "bar"}

def my_validator(key, data, errors, context_in_validator):

assert not id(context) == id(context_in_validator)

data_dict = {
'my_field': 'test',
}
data_dict = {"my_field": "test"}

schema = {
'my_field': [my_validator],
}
schema = {"my_field": [my_validator]}

data, errors = validate(data_dict, schema, context)

def test_validate_adds_schema_keys_to_context(self):

def my_validator(key, data, errors, context):

assert 'schema_keys' in context
assert "schema_keys" in context

eq_(context['schema_keys'], ['my_field'])
assert context["schema_keys"] == ["my_field"]

data_dict = {
'my_field': 'test',
}
data_dict = {"my_field": "test"}

schema = {
'my_field': [my_validator],
}
schema = {"my_field": [my_validator]}

context = {}

data, errors = validate(data_dict, schema, context)


class TestDictizationError(object):

def test_str_error(self):
err_obj = Invalid('Some ascii error')
eq_(str(err_obj), "Invalid: 'Some ascii error'")
err_obj = Invalid("Some ascii error")
assert str(err_obj) == "Invalid: 'Some ascii error'"

def test_unicode_error(self):
err_obj = Invalid('Some ascii error')
eq_(text_type(err_obj), u"Invalid: 'Some ascii error'")
err_obj = Invalid("Some ascii error")
assert text_type(err_obj) == u"Invalid: 'Some ascii error'"

def test_repr_error(self):
err_obj = Invalid('Some ascii error')
eq_(repr(err_obj), "<Invalid 'Some ascii error'>")
err_obj = Invalid("Some ascii error")
assert repr(err_obj) == "<Invalid 'Some ascii error'>"

# Error msgs should be ascii, but let's just see what happens for unicode

def test_str_unicode_error(self):
err_obj = Invalid(u'Some unicode \xa3 error')
eq_(str(err_obj), "Invalid: u'Some unicode \\xa3 error'")
err_obj = Invalid(u"Some unicode \xa3 error")
assert str(err_obj) == "Invalid: u'Some unicode \\xa3 error'"

def test_unicode_unicode_error(self):
err_obj = Invalid(u'Some unicode \xa3 error')
eq_(text_type(err_obj), "Invalid: u'Some unicode \\xa3 error'")
err_obj = Invalid(u"Some unicode \xa3 error")
assert text_type(err_obj) == "Invalid: u'Some unicode \\xa3 error'"

def test_repr_unicode_error(self):
err_obj = Invalid(u'Some unicode \xa3 error')
eq_(repr(err_obj), "<Invalid u'Some unicode \\xa3 error'>")
err_obj = Invalid(u"Some unicode \xa3 error")
assert repr(err_obj) == "<Invalid u'Some unicode \\xa3 error'>"

def test_str_blank(self):
err_obj = Invalid('')
eq_(str(err_obj), "Invalid")
err_obj = Invalid("")
assert str(err_obj) == "Invalid"

def test_unicode_blank(self):
err_obj = Invalid('')
eq_(text_type(err_obj), u"Invalid")
err_obj = Invalid("")
assert text_type(err_obj) == u"Invalid"

def test_repr_blank(self):
err_obj = Invalid('')
eq_(repr(err_obj), "<Invalid>")
err_obj = Invalid("")
assert repr(err_obj) == "<Invalid>"

0 comments on commit cefe30b

Please sign in to comment.