Esempio n. 1
0
def test_identity_validation():

    converted_data, errors = validate_flattened(data, schema)
    print errors
    print converted_data

    assert not errors

    assert sorted(converted_data) == sorted({
        ('__junk', ): {
            ('2', 2, '21', 0, '210'): '210 value 2,0',
            ('4', 1, '30'): '30 value 1'
        },
        ('0', ): '0 value',
        ('1', ): missing,
        ('2', 0, '20'): '20 value 0',
        ('2', 0, '21', 0, '210'): '210 value 0,0',
        ('2', 0, '22'): missing,
        ('2', 1, '20'): '20 value 1',
        ('2', 1, '21', 0, '210'): '210 value 1,0',
        ('2', 1, '21', 1, '210'): '210 value 1,1',
        ('2', 1, '21', 3, '210'): '210 value 1,3',
        ('2', 1, '22'): '22 value 1',
        ('__extras', ): {
            '4': '4 value'
        }
    }), pformat(sorted(converted_data))
Esempio n. 2
0
def test_basic_errors():
    schema = {
        "__junk": [empty],
        "__extras": [empty],
        "0": [identity_converter],
        "1": [not_empty],
        "2": {
            "__before": [identity_converter],
            "__after": [identity_converter],
            "20": [identity_converter],
            "22": [identity_converter],
            "__extras": [empty],
            "21": {
                "210": [identity_converter],
            },
        },
        "3": {
            "30": [identity_converter],
        },
    }

    converted_data, errors = validate_flattened(data, schema)

    assert errors == {
        ('__junk', ): [u'The input field __junk was not expected.'],
        ('1', ): [u'Missing value'],
        ('__extras', ): [u'The input field __extras was not expected.']
    }, errors
Esempio n. 3
0
    def test_basic_errors(self):
        raise SkipTest()

        schema = {
            "__junk": [empty],
            "__extras": [empty],
            "0": [identity_converter],
            "1": [not_empty],
            "2": {
                "__before": [identity_converter],
                "__after": [identity_converter],
                "20": [identity_converter],
                "22": [identity_converter],
                "__extras": [empty],
                "21": {"210": [identity_converter]},
            },
            "3": {"30": [identity_converter]},
        }

        converted_data, errors = validate_flattened(data, schema)

        assert errors == {
            ("__junk",): [u"The input field __junk was not expected."],
            ("1",): [u"Missing value"],
            ("__extras",): [u"The input field __extras was not expected."],
        }, errors
Esempio n. 4
0
def test_ignore_missing():
    schema = {
        "__junk": [ignore],
        "__extras": [ignore, default("weee")],
        "0": [default("default")],
        "1": [ignore_missing, default("default")],
    }

    converted_data, errors = validate_flattened(data, schema)

    assert not errors
    assert converted_data == {('0', ): '0 value'}, converted_data
Esempio n. 5
0
    def test_ignore_missing(self):
        schema = {
            "__junk": [ignore],
            "__extras": [ignore, default("weee")],
            "0": [default("default")],
            "1": [ignore_missing, default("default")],
        }

        converted_data, errors = validate_flattened(data, schema)

        assert not errors
        assert converted_data == {("0",): "0 value"}, converted_data
Esempio n. 6
0
def test_default():
    schema = {
        "__junk": [ignore],
        "__extras": [ignore, default("weee")],
        "__before": [ignore],
        "__after": [ignore],
        "0": [default("default")],
        "1": [default("default")],
    }

    converted_data, errors = validate_flattened(data, schema)

    assert not errors
    assert converted_data == {('1',): 'default', ('0',): '0 value'}, converted_data
Esempio n. 7
0
def test_ignore_missing():
    log.debug('Starting test_ignore_missing()')

    schema = {
        "__junk": [ignore],
        "__extras": [ignore, default("weee")],
        "0": [default("default")],
        "1": [ignore_missing, default("default")],
    }

    converted_data, errors = validate_flattened(data, schema)

    log.debug('converted_data: {0}'.format(converted_data))

    assert not errors
    assert converted_data == {('0', ): '0 value'}, converted_data
Esempio n. 8
0
def test_ignore_missing():
    log.debug('Starting test_ignore_missing()')

    schema = {
        "__junk": [ignore],
        "__extras": [ignore, default("weee")],
        "0": [default("default")],
        "1": [ignore_missing, default("default")],
    }

    converted_data, errors = validate_flattened(data, schema)

    log.debug('converted_data: {0}'.format(converted_data))

    assert not errors
    assert converted_data == {('0',): '0 value'}, converted_data
Esempio n. 9
0
    def test_default(self):
        schema = {
            "__junk": [ignore],
            "__extras": [ignore, default("weee")],
            "__before": [ignore],
            "__after": [ignore],
            "0": [default("default")],
            "1": [default("default")],
        }

        converted_data, errors = validate_flattened(data, schema)

        assert not errors
        assert converted_data == {
            ('1', ): 'default',
            ('0', ): '0 value'
        }, converted_data
Esempio n. 10
0
    def test_identity_validation(self):
        raise SkipTest()

        converted_data, errors = validate_flattened(data, schema)
        print errors

        assert not errors

        assert sorted(converted_data) == sorted(
            {
                ("__junk",): {("2", 2, "21", 0, "210"): "210 value 2,0", ("4", 1, "30"): "30 value 1"},
                ("0",): "0 value",
                ("1",): missing,
                ("2", 0, "20"): "20 value 0",
                ("2", 0, "21", 0, "210"): "210 value 0,0",
                ("2", 0, "22"): missing,
                ("2", 1, "20"): "20 value 1",
                ("2", 1, "21", 0, "210"): "210 value 1,0",
                ("2", 1, "21", 1, "210"): "210 value 1,1",
                ("2", 1, "21", 3, "210"): "210 value 1,3",
                ("2", 1, "22"): "22 value 1",
                ("__extras",): {"4": "4 value"},
            }
        ), pprint(sorted(converted_data))
Esempio n. 11
0
def test_basic_errors():
    schema = {
        "__junk": [empty],
        "__extras": [empty],
        "0": [identity_converter],
        "1": [not_empty],
        "2": {
            "__before": [identity_converter],
            "__after": [identity_converter],
            "20": [identity_converter],
            "22": [identity_converter],
            "__extras": [empty],
            "21": {
                "210": [identity_converter],
            },
        },
        "3": {
            "30": [identity_converter],
        },
    }

    converted_data, errors = validate_flattened(data, schema)

    assert errors == {('__junk',): [u"The input field [('4', 1, '30')] was not expected."], ('1',): [u'Missing value'], ('__extras',): [u'The input field __extras was not expected.']}, errors
Esempio n. 12
0
def test_identity_validation():

    
    converted_data, errors = validate_flattened(data, schema)
    print errors
    print converted_data

    assert not errors


    assert sorted(converted_data) == sorted({
         ('__junk',): {('2', 2, '21', 0, '210'): '210 value 2,0',
                       ('4', 1, '30'): '30 value 1'},
         ('0',): '0 value',
         ('1',): missing,
         ('2', 0, '20'): '20 value 0',
         ('2', 0, '21', 0, '210'): '210 value 0,0',
         ('2', 0, '22'): missing,
         ('2', 1, '20'): '20 value 1',
         ('2', 1, '21', 0, '210'): '210 value 1,0',
         ('2', 1, '21', 1, '210'): '210 value 1,1',
         ('2', 1, '21', 3, '210'): '210 value 1,3',
         ('2', 1, '22'): '22 value 1',
         ('__extras',): {'4': '4 value'}}), pformat(sorted(converted_data))