Esempio n. 1
0
def test_keyword_of_fields(keyword, field_cls):
    s_f = StringField()
    n_f = NumberField()
    i_f = IntField()
    field = field_cls([n_f, Var({'role_1': s_f}), Var({'role_2': i_f})])
    assert field.get_schema() == {keyword: [n_f.get_schema()]}
    assert field.get_schema(role='role_1') == {
        keyword: [n_f.get_schema(), s_f.get_schema()]
    }
    assert field.get_schema(role='role_2') == {
        keyword: [n_f.get_schema(), i_f.get_schema()]
    }

    field = field_cls(
        Var(
            {
                'role_1': [n_f,
                           Var({'role_1': s_f}),
                           Var({'role_2': i_f})],
                'role_2': [Var({'role_2': i_f})],
            },
            propagate='role_1'))
    assert field.get_schema() == {keyword: []}
    assert field.get_schema(role='role_1') == {
        keyword: [n_f.get_schema(), s_f.get_schema()]
    }
    assert field.get_schema(role='role_2') == {keyword: []}
Esempio n. 2
0
def test_keyword_of_fields(keyword, field_cls):
    s_f = StringField()
    n_f = NumberField()
    i_f = IntField()
    field = field_cls([n_f, Var({'role_1': s_f}), Var({'role_2': i_f})])
    assert s(field.get_schema()) == {keyword: [n_f.get_schema()]}
    assert s(field.get_schema(role='role_1')) == {
        keyword: [n_f.get_schema(), s_f.get_schema()]
    }
    assert s(field.get_schema(role='role_2')) == {
        keyword: [n_f.get_schema(), i_f.get_schema()]
    }

    field = field_cls(
        Var(
            {
                'role_1': [n_f,
                           Var({'role_1': s_f}),
                           Var({'role_2': i_f})],
                'role_2': [Var({'role_2': i_f})],
            },
            propagate='role_1'))
    assert s(field.get_schema(role='role_1')) == {
        keyword: [n_f.get_schema(), s_f.get_schema()]
    }
    with pytest.raises(SchemaGenerationException):
        field.get_schema(role='role_2')
Esempio n. 3
0
def test_keyword_of_fields(keyword, field_cls):
    s_f = StringField()
    n_f = NumberField()
    i_f = IntField()
    field = field_cls([n_f, Var(role_1=s_f), Var(role_2=i_f)])
    assert field.get_schema() == {
        keyword: [n_f.get_schema()]
    }
    assert field.get_schema(role='role_1') == {
        keyword: [n_f.get_schema(), s_f.get_schema()]
    }
    assert field.get_schema(role='role_2') == {
        keyword: [n_f.get_schema(), i_f.get_schema()]
    }

    field = field_cls(Var(
        role_1=[n_f, Var(role_1=s_f), Var(role_2=i_f)],
        role_2=[Var(role_2=i_f)],
        roles_to_pass_down=['role_1']
    ))
    assert field.get_schema() == {keyword: []}
    assert field.get_schema(role='role_1') == {
        keyword: [n_f.get_schema(), s_f.get_schema()]
    }
    assert field.get_schema(role='role_2') == {keyword: []}
Esempio n. 4
0
def test_keyword_of_fields(keyword, field_cls):
    s_f = StringField()
    n_f = NumberField()
    i_f = IntField()
    field = field_cls([n_f, Var({'role_1': s_f}), Var({'role_2': i_f})])
    assert field.get_schema() == {
        keyword: [n_f.get_schema()]
    }
    assert field.get_schema(role='role_1') == {
        keyword: [n_f.get_schema(), s_f.get_schema()]
    }
    assert field.get_schema(role='role_2') == {
        keyword: [n_f.get_schema(), i_f.get_schema()]
    }

    field = field_cls(Var({
        'role_1': [n_f, Var({'role_1': s_f}), Var({'role_2': i_f})],
        'role_2': [Var({'role_2': i_f})],
    }, propagate='role_1'))
    assert field.get_schema() == {keyword: []}
    assert field.get_schema(role='role_1') == {
        keyword: [n_f.get_schema(), s_f.get_schema()]
    }
    assert field.get_schema(role='role_2') == {keyword: []}
Esempio n. 5
0
def test_keyword_of_fields(keyword, field_cls):
    s_f = StringField()
    n_f = NumberField()
    i_f = IntField()
    field = field_cls([n_f, Var({'role_1': s_f}), Var({'role_2': i_f})])
    assert s(field.get_schema()) == {
        keyword: [n_f.get_schema()]
    }
    assert s(field.get_schema(role='role_1')) == {
        keyword: [n_f.get_schema(), s_f.get_schema()]
    }
    assert s(field.get_schema(role='role_2')) == {
        keyword: [n_f.get_schema(), i_f.get_schema()]
    }

    field = field_cls(Var({
        'role_1': [n_f, Var({'role_1': s_f}), Var({'role_2': i_f})],
        'role_2': [Var({'role_2': i_f})],
    }, propagate='role_1'))
    assert s(field.get_schema(role='role_1')) == {
        keyword: [n_f.get_schema(), s_f.get_schema()]
    }
    with pytest.raises(SchemaGenerationException):
        field.get_schema(role='role_2')