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')
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: []}
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: []}
def test_array_field(): s_f = StringField() n_f = NumberField() field = ArrayField(Var({ 'role_1': s_f, 'role_2': n_f, })) schema = field.get_schema(role='role_1') assert schema['items'] == s_f.get_schema() schema = field.get_schema(role='role_2') assert schema['items'] == n_f.get_schema() schema = field.get_schema() assert 'items' not in schema _ = lambda value: Var({'role_1': value}) field = ArrayField(s_f, min_items=_(1), max_items=_(2), unique_items=_(True), additional_items=_(True)) assert field.get_schema() == { 'type': 'array', 'items': s_f.get_schema(), } assert field.get_schema(role='role_1') == { 'type': 'array', 'items': s_f.get_schema(), 'minItems': 1, 'maxItems': 2, 'uniqueItems': True, 'additionalItems': True, }
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: []}
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')