Beispiel #1
0
def test_element_schema_build_no_value_with_attributes_validator_none_pass():
    es = ElementSchema('parent',
                       validator=None,
                       attributes=[
                           ElementSchema('id', validator=ID()),
                           ElementSchema('offset',
                                         validator=PositiveInteger()),
                       ])
    path = '/name-0,NCName,'
    stores = Stores()
    actual = es.build(path=path, stores=stores)
    expected = Element('parent',
                       value=None,
                       path=path,
                       attributes=OrderedDict([('id', 'testId0'),
                                               ('offset', 1)]))
    expected.isValidated = True
    validated = es.to_python(actual, path=path, stores=Stores())
    nose.tools.eq_(validated, expected)
Beispiel #2
0
def test_element_schema_validate_fail():
    utils.reset_message_counters()
    es = ElementSchema('testable', validator=PositiveInteger())
    # noinspection PyProtectedMember
    es._validate(es.validator, 'NaN', es.tag, path='/')
    nose.tools.eq_(utils.error_count, 1)
Beispiel #3
0
def test_element_schema_validate_pass():
    es = ElementSchema('testable', validator=PositiveInteger())
    # noinspection PyProtectedMember
    value = es._validate(es.validator, '42', es._tag, path='/')
    nose.tools.eq_(value, 42)
Beispiel #4
0
 class TestSchema(SequenceSchema):
     sequence = [
         ElementSchema('name', validator=NCName()),
         ElementSchema('count', validator=PositiveInteger())
     ]
Beispiel #5
0
def test_element_schema_to_python_no_element_fail():
    es = ElementSchema('testable', validator=PositiveInteger())
    es.to_python('42')
Beispiel #6
0
def test_positive_integer_range_fail():
    value = '0'
    PositiveInteger().to_python(value)
Beispiel #7
0
def test_positive_integer_build_value_pass():
    value = '00033'
    actual = PositiveInteger().build(value)
    nose.tools.eq_(actual, 33)
Beispiel #8
0
def test_positive_integer_build_pass():
    actual = PositiveInteger().build()
    nose.tools.eq_(actual, 1)
Beispiel #9
0
def test_positive_integer_pass():
    validator_inst = PositiveInteger()
    value = '00033'
    actual = validator_inst.to_python(value)
    nose.tools.eq_(actual, 33)