def test_element_schema_to_python_sequence_schema_pass(): class TestSchema(SequenceSchema): sequence = [ ElementSchema('name', validator=NCName()), ElementSchema('count', validator=PositiveInteger()) ] es = ElementSchema('test', validator=TestSchema()) path = '/test-0,testName' name = Element('name', value='testName', path=path + '/name-0,') count = Element('count', value='3', path=path + '/count-0,') element = Element('test', value=[name, count], path=path) validated_name = Element(tag='name', path="/test-0,testName/name-0,", value='testName') validated_name.isValidated = True validated_count = Element(tag='count', path="/test-0,testName/count-0,", value=3) validated_count.isValidated = True expected = Element(tag='test', path="/test-0,testName", value=[validated_name, validated_count]) for el in expected.value: el.isValidated = True expected.isValidated = True actual = es.to_python(element) nose.tools.eq_(actual, expected)
def test_element_schema_to_python_int_list_pass(): es = ElementSchema('numbers', validator=PositiveInteger()) element = Element('numbers', value=['1', 2, 3, '4'], path='/top-0,name') expected = Element('numbers', value=[1, 2, 3, 4], path='/top-0,name') expected.isValidated = True actual = es.to_python(element) nose.tools.eq_(actual, expected)
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)
def test_element_schema_to_python_sequence_schema_pass(): class TestSchema(SequenceSchema): sequence = [ElementSchema('name', validator=NCName()), ElementSchema('count', validator=PositiveInteger())] es = ElementSchema('test', validator=TestSchema()) path = '/test-0,testName' name = Element('name', value='testName', path=path + '/name-0,') count = Element('count', value='3', path=path + '/count-0,') element = Element('test', value=[name, count], path=path) validated_name = Element(tag='name', path="/test-0,testName/name-0,", value='testName') validated_name.isValidated = True validated_count = Element(tag='count', path="/test-0,testName/count-0,", value=3) validated_count.isValidated = True expected = Element(tag='test', path="/test-0,testName", value=[ validated_name, validated_count]) for el in expected.value: el.isValidated = True expected.isValidated = True actual = es.to_python(element) nose.tools.eq_(actual, expected)
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)