コード例 #1
0
ファイル: event_schema.py プロジェクト: mandepsingh/zuliper
def check_realm_bot_add(
    var_name: str,
    event: Dict[str, object],
) -> None:
    _check_realm_bot_add(var_name, event)

    assert isinstance(event["bot"], dict)
    bot_type = event["bot"]["bot_type"]

    services_field = f"{var_name}['bot']['services']"
    services = event["bot"]["services"]

    if bot_type == UserProfile.DEFAULT_BOT:
        check_data(Equals([]), services_field, services)
    elif bot_type == UserProfile.OUTGOING_WEBHOOK_BOT:
        check_data(ListType(bot_services_outgoing_type, length=1), services_field, services)
    elif bot_type == UserProfile.EMBEDDED_BOT:
        check_data(ListType(bot_services_embedded_type, length=1), services_field, services)
    else:
        raise AssertionError(f"Unknown bot_type: {bot_type}")
コード例 #2
0
    def test_data_type_schema(self) -> None:
        """
        We really only test this to get test coverage.  The
        code covered here is really only used in testing tools.
        """
        test_schema = DictType([
            ("type", Equals("realm")),
            ("maybe_n", OptionalType(int)),
            ("s", str),
            ("timestamp", NumberType()),
            ("flag", bool),
            ("tup", TupleType([int, str])),
            ("level", EnumType([1, 2, 3])),
            ("lst", ListType(int)),
            ("config", StringDictType(str)),
            ("value", UnionType([int, str])),
            ("url", UrlType()),
        ])
        expected = """
test (dict):
    config (string_dict):
        value: str
    flag: bool
    level in [1, 2, 3]
    lst (list):
        type: int
    maybe_n: int
    s: str
    timestamp: number
    tup (tuple):
        0: int
        1: str
    type in ['realm']
    url: str
    value (union):
        type: int
        type: str
"""
        self.assertEqual(schema("test", test_schema).strip(), expected.strip())
コード例 #3
0
ファイル: event_schema.py プロジェクト: aryanshridhar/zulip
    ("in_home_view", bool),
    ("is_muted", bool),
    ("pin_to_top", bool),
    ("push_notifications", OptionalType(bool)),
    ("role", EnumType(Subscription.ROLE_TYPES)),
    ("stream_weekly_traffic", OptionalType(int)),
    # We may try to remove subscribers from some events in
    # the future for clients that don't want subscriber
    # info.
    ("subscribers", ListType(int)),
    ("wildcard_mentions_notify", OptionalType(bool)),
]

equals_add_or_remove = UnionType([
    # force vertical
    Equals("add"),
    Equals("remove"),
])

value_type = UnionType([
    # force vertical formatting
    bool,
    int,
    str,
])

optional_value_type = UnionType([
    # force vertical formatting
    bool,
    int,
    str,