Beispiel #1
0
def test_nested_field():
    with pytest.raises(fields.ModelViolationError):
        fields.Nested(BasicModel, allow_null=False)._convert_to_model(
            'something', 'test-value')
    with pytest.raises(fields.ModelViolationError):
        fields.Nested(BasicModel,
                      allow_null=False)._convert_to_model(None, 'test-value')
    fields.Nested(BasicModel,
                  allow_null=True)._convert_to_model(None, 'test-value')
Beispiel #2
0
def test_nested_model():
    m = WithNestedModel(basic=BasicModel(message='Some message'))
    m2 = WithNestedModel.create(m.dump())
    assert m.basic == m2.basic

    with pytest.raises(fields.ModelMisuseError):
        fields.Nested(fields.String())

    with pytest.raises(fields.ModelMisuseError):
        fields.Nested(fields.String)

    with pytest.raises(fields.ModelViolationError):
        WithNestedModel(basic='Some message')

    m = WithNestedModel()
    m.basic = None
    m.dump()

    with pytest.raises(fields.ModelViolationError):
        x = WithRequiredNestedModel(basic=BasicModel(message='Some message'))
        x.basic = None
        x.dump()

    with pytest.raises(fields.ModelViolationError):
        WithRequiredNestedModel.create(dict(basic=None))

    with pytest.raises(fields.ModelViolationError):
        WithRequiredNestedModel(basic=None)

    assert WithRequiredNestedModel.create({
        'basic': {
            'message': 'test-message'
        }
    }).basic.message == 'test-message'
    assert WithRequiredNestedModel(basic=BasicModel(
        message='test-message')).basic.message == 'test-message'
Beispiel #3
0
class WithNestedListModel(Model):
    topic = ModelTestTopic
    items = fields.List(fields.Nested(BasicModel), required=False)
Beispiel #4
0
def _create_nested_base_model_field(**kwargs):
    return fields.Nested(BasicModel, **kwargs)
Beispiel #5
0
class WithRequiredNestedModel(Model):
    topic = ModelTestTopic
    basic = fields.Nested(BasicModel, required=True)
Beispiel #6
0
class WithNestedModel(Model):
    topic = ModelTestTopic
    basic = fields.Nested(BasicModel, required=False, allow_null=True)
Beispiel #7
0
class InstalledRPM(Model):
    topic = SystemInfoTopic
    items = fields.List(fields.Nested(RPM), required=True, default=[])