Пример #1
0
    def test_init(self):
        f = Field()
        self.assertIsInstance(f, Field)

        f = Field(name="LIST", instanciator=list)
        self.assertEqual(f.name, "LIST")
        self.assertEqual(f.instance_name, "_LIST")
        self.assertEqual(f.instanciator, list)
class Repository(WatcherTyping2):
    name = Field()
    permission = Field()

    def __eq__(self, other):
        if not isinstance(other, Repository):
            return False

        return self.name == other.name
Пример #3
0
class RepositoryPipelinesConfiguration(Typing2):
    enabled = Field(default=False)

    def __eq__(self, other):
        if not isinstance(other, RepositoryPipelinesConfiguration):
            return False
        return other.enabled == self.enabled
Пример #4
0
    def test_match(self):
        f = Field(name="NAME")
        f.mapping("PRETTY_NAME")

        self.assertEqual(f.match("NAME"), True)
        self.assertEqual(f.match("PRETTY_NAME"), True)
        self.assertEqual(f.match("OTHER"), False)
class Links(Typing2):
    clone = Field().list_of(inside_instanciator=LinksClone)

    def find_clone_by_name(self, name):
        for i in self.clone:
            if i.name == name:
                return i

        return None
class Repository(Typing2):
    scm = Field(default=Scm.GIT) \
        .converter(loads=Scm, dumps=str)
    project = Field(instanciator=Project)
    is_private = Field(default=True)
    name = Field()
    description = Field()
    fork_policy = Field(default=ForkPolicy.NO_PUBLIC_FORKS) \
        .converter(loads=ForkPolicy, dumps=str)
    language = Field(default="")
    links = Field(instanciator=Links)
class PullRequest(Typing2):
    title = Field()
    id = Field()
    close_source_branch = Field().converter(loads=bool)
    source = Field(instanciator=SrcDst)
    destination = Field(instanciator=SrcDst)
    state = Field().converter(loads=State, dumps=str)
    links = Field(instanciator=Links)
Пример #8
0
    def test_get_inside_instance(self):
        f = Field(name="NAME")
        f.list_of(inside_instanciator=dict)

        value = f.get_inside_instance({"data": "DATA"}, None)
        self.assertIsInstance(value, dict)
        self.assertEqual(value, {"data": "DATA"})

        f.list_of()
        value = f.get_inside_instance("data", None)
        self.assertIsInstance(value, str)
        self.assertEqual(value, "data")
Пример #9
0
class GroupPrivilege(Typing2):
    """
    Privilege/group view
    """
    def __get_group_slug_only(self, value):
        if isinstance(value, dict):
            return value.get("slug")

        return value

    privilege = Field() \
        .converter(loads=Privilege, dumps=str)
    group = Field() \
        .getters(__get_group_slug_only)

    def __eq__(self, other):
        if not isinstance(other, GroupPrivilege):
            return False

        return self.privilege == other.privilege and self.group == other.group
Пример #10
0
    def test_list_of(self):
        f = Field(name="NAME")
        f.list_of()
        self.assertIsNone(f.inside_instanciator)
        self.assertEqual(f.instanciator, list)
        self.assertEqual(f.is_list, True)

        f.list_of(inside_instanciator=dict)
        self.assertEqual(f.inside_instanciator, dict)
Пример #11
0
    def test_hide(self):
        f = Field(name="NAME")
        f.hide()

        self.assertEqual(f.hidden, True)

        f.unhide()

        self.assertEqual(f.hidden, False)
Пример #12
0
    def test_setters(self):
        f = Field(name="NAME")

        def func1(instance, value):
            return value

        def func2(instance, value):
            return value

        f.setters(func1)
        self.assertEqual(f.setters_funcs[0], func1)

        f.setters(func2)
        self.assertEqual(f.setters_funcs[0], func1)
        self.assertEqual(f.setters_funcs[1], func2)

        f.setters(clear=True)
        self.assertEqual(len(f.setters_funcs), 0)
Пример #13
0
    def test_delete(self):
        f = Field(name="NAME")

        instance = Typing2()

        f.direct_set(instance, 10)
        self.assertEqual(instance._NAME, 10)

        f.__delete__(instance)
        self.assertEqual(getattr(instance, "_NAME", "DONOTEXIST"),
                         "DONOTEXIST")
Пример #14
0
    def test_dumps_convert(self):
        f = Field(name="NAME")
        f.converter(dumps=int)

        self.assertIsNone(f.dumps_convert(None))

        value = f.dumps_convert("10")
        self.assertIsInstance(value, int)
        self.assertEqual(value, 10)

        value = f.dumps_convert(10)
        self.assertIsInstance(value, int)
        self.assertEqual(value, 10)

        self.assertRaises(ValueError, f.dumps_convert, "not a number")
class BranchRestriction(Typing2):
    id = Field()
    kind = Field() \
        .converter(loads=Kind, dumps=str)
    branch_match_kind = Field() \
        .converter(loads=BranchMatchKind, dumps=str)
    branch_type = Field() \
        .converter(loads=BranchType, dumps=str)
    pattern = Field()
    groups = Field().list_of()
    users = Field().list_of()
    value = Field()

    def post_dumps(self, raw, dump):
        if self.branch_match_kind != BranchMatchKind.BRANCHING_MODEL:
            # Do not use it when branch_match_kind is not branching_model.
            dump.pop("branch_type")

    def __eq__(self, other):
        if not isinstance(other, BranchRestriction):
            return False

        if len(self.users) != len(other.users) or len(self.groups) != len(
                other.groups):
            return False

        # test users
        for user in self.users:
            if user not in other.users:
                return False

        # test groups
        for group in self.groups:
            if group not in other.groups:
                return False

        return \
            self.kind == other.kind and \
            self.branch_match_kind == other.branch_match_kind and \
            self.branch_type == other.branch_type and \
            self.pattern == other.pattern and \
            self.value == other.value
Пример #16
0
    def test_set(self):
        f = Field(name="NAME")

        def func1(instance, value):
            return value + 10

        f.setters(func1)
        f.setters(func1)

        instance = Typing2()

        f.direct_set(instance, 10)
        self.assertEqual(instance._NAME, 10)

        f.__set__(instance, 40)
        self.assertEqual(instance._NAME, 60)

        f.setters(clear=True)
        f.__set__(instance, 40)
        self.assertEqual(instance._NAME, 40)
Пример #17
0
    def test_get(self):
        f = Field(name="NAME")

        def func1(instance, value):
            return "OTHER"

        f.getters(func1)

        instance = Typing2()
        instance._NAME = 10

        self.assertEqual(f.direct_get(instance), 10)

        self.assertEqual(f.__get__(instance, None), "OTHER")

        f.default(33)
        self.assertEqual(instance._NAME, 10)

        del instance._NAME
        self.assertEqual(f.__get__(instance, None), "OTHER")
        self.assertEqual(instance._NAME, 33)

        f.getters(clear=True)
        self.assertEqual(f.__get__(instance, None), 33)
Пример #18
0
class DeployKey(Typing2):
    label = Field(default="")
    key = Field()
    id = Field()
Пример #19
0
class Event(Typing2):
    key = Field()
    type_ = Field(instanciator=EventType).converter(dumps=str).mapping("type")
    value = Field()
Пример #20
0
class PipelineUUID(Typing2):
    state = Field(instanciator=State)
    target = Field(instanciator=Target)
    build_number = Field()
Пример #21
0
class StateResult(Typing2):
    name = Field()
Пример #22
0
    def test_converter(self):
        f = Field(name="NAME")
        f.converter(loads=int, dumps=str)

        self.assertEqual(f.loads_converter, int)
        self.assertEqual(f.dumps_converter, str)
Пример #23
0
    def test_default(self):
        f = Field(name="NAME", default="name_value")
        self.assertEqual(f.default_value, "name_value")

        f.default(None)
        self.assertEqual(f.default_value, None)
Пример #24
0
class State(Typing2):
    name = Field()
    result = Field(instanciator=StateResult)
Пример #25
0
class Commit(Typing2):
    hash = Field()
Пример #26
0
class Target(Typing2):
    ref_type = Field()
    ref_name = Field()
    commit = Field(instanciator=Commit)
Пример #27
0
    def test_get_name(self):
        f = Field(name="NAME")
        f.mapping("PRETTY_NAME")

        self.assertEqual(f.get_name(), "PRETTY_NAME")
        self.assertEqual(f.get_name(no_mapping=True), "NAME")
Пример #28
0
    def test_get_instance(self):
        f = Field(name="NAME")
        self.assertIsNone(f.get_instance(None))

        f.default("coucou")
        self.assertEqual(f.get_instance(None), "coucou")
Пример #29
0
    def test_mapping(self):
        f = Field(name="NAME")
        f.mapping("PRETTY_NAME")

        self.assertEqual(f.mapping_name, "PRETTY_NAME")
Пример #30
0
class LinksClone(Typing2):
    href = Field()
    name = Field()