Esempio n. 1
0
class RepositorySchema(mm.Schema):
    """A schema for Repository class."""
    name = fields.Str()
    branch = fields.Str()
    commit = fields.Nested(CommitInfoSchema())
    format = schema.Enum(constants.RepositoryFormat)
    contents = fields.Nested(ContentSchema(), many=True)
    readme = fields.Nested(ReadmeFileSchema())

    @mm.post_load
    def make_object(self, data):
        return Repository(**data)
Esempio n. 2
0
class RoleMetaSchema(mm.Schema):
    author = fields.Str()
    company = fields.Str()
    license = fields.Str()
    min_ansible_version = fields.Str(allow_none=True)
    min_ansible_container_version = fields.Str(allow_none=True)
    issue_tracker = fields.Str()
    github_branch = fields.Str()

    role_type = schema.Enum(constants.RoleType)
    tags = fields.List(fields.Str())
    platforms = fields.Nested(PlatformInfoSchema(), many=True)
    cloud_platforms = fields.List(fields.Str())
    dependencies = fields.Nested(DependencyInfoSchema(), many=True)
    video_links = fields.Nested(VideoLinkSchema(), many=True)
Esempio n. 3
0
class ContentSchema(mm.Schema):
    """A schema for Content class."""
    name = fields.Str()
    original_name = fields.Str()
    path = fields.Str()
    content_type = schema.Enum(constants.ContentType)
    description = fields.Str()
    # Note(cutwater): This is workaround to make properly serializable
    # role metadata.
    role_meta = fields.Nested(RoleMetaSchema())
    readme = fields.Nested(ReadmeFileSchema())
    metadata = fields.Dict()

    @mm.post_load
    def make_object(self, data):
        return Content(**data)
Esempio n. 4
0
 def test_deserialize_fail(self):
     field = schema.Enum(Color)
     with pytest.raises(ValueError):
         field.deserialize('magenta')
Esempio n. 5
0
 def test_deserialize(self):
     field = schema.Enum(Color)
     assert field.deserialize('red') is Color.RED
     assert field.deserialize('green') is Color.GREEN
     assert field.deserialize('blue') is Color.BLUE
Esempio n. 6
0
 def test_serialize_fail(self):
     field = schema.Enum(Color)
     with pytest.raises(ValueError):
         field.serialize('attr', {'attr': 'magenta'})
Esempio n. 7
0
 def test_serialize_str(self):
     field = schema.Enum(Color)
     assert field.serialize('attr', {'attr': 'red'}) == 'red'
     assert field.serialize('attr', {'attr': 'green'}) == 'green'
     assert field.serialize('attr', {'attr': 'blue'}) == 'blue'
Esempio n. 8
0
 def test_serialize_allow_none(self):
     field = schema.Enum(Color, allow_none=True)
     assert field.serialize('attr', {'attr': None}) is None
Esempio n. 9
0
 def test_serialize(self):
     field = schema.Enum(Color)
     assert field.serialize('attr', {'attr': Color.RED}) == 'red'
     assert field.serialize('attr', {'attr': Color.GREEN}) == 'green'
     assert field.serialize('attr', {'attr': Color.BLUE}) == 'blue'