Example #1
0
def test_model_builder_custom_class():
    data = {
        'foo*bar': 'foobar',
        'baz/qux': 'bazqux',
    }
    cls = model_class_builder('Model', data)

    birl = model_builder(data, cls=cls)

    assert isinstance(birl, cls)
Example #2
0
def test_model_class_builder():
    Birl = model_class_builder('Birl', {'f': 'foo', 'b': 'bar'})
    birl = Birl()

    assert isinstance(birl, Model)
    keys = ('f', 'b')
    assert len(Birl._meta.fields) == len(keys)
    assert set(Birl._meta.fields) == set(keys)

    assert birl.validate(raise_exception=False) is True
    assert to_dict(birl) == {'f': None, 'b': None}
Example #3
0
def test_model_class_builder_empty_data():
    Birl = model_class_builder('Birl', {})
    birl = Birl()

    assert isinstance(birl, Model)