Exemplo n.º 1
0
    def test_register_events(self):
        realm_user_add_checker = check_dict([
            ('type', equals('realm_user')),
            ('op', equals('add')),
            ('person', check_dict([
                ('email', check_string),
                ('full_name', check_string),
                ('is_admin', check_bool),
                ('is_bot', check_bool),
            ])),
        ])
        stream_create_checker = check_dict([
            ('type', equals('stream')),
            ('op', equals('create')),
            ('streams', check_list(check_dict([
                ('description', check_string),
                ('invite_only', check_bool),
                ('name', check_string),
                ('stream_id', check_int),
            ])))
        ])

        events = self.do_test(lambda: self.register("test1", "test1"))
        error = realm_user_add_checker('events[0]', events[0])
        self.assert_on_error(error)
        error = stream_create_checker('events[1]', events[1])
        self.assert_on_error(error)
Exemplo n.º 2
0
    def test_register_events(self):
        realm_user_add_checker = check_dict([
            ('type', equals('realm_user')),
            ('op', equals('add')),
            ('person', check_dict([
                ('email', check_string),
                ('full_name', check_string),
                ('is_admin', check_bool),
                ('is_bot', check_bool),
            ])),
        ])
        stream_create_checker = check_dict([
            ('type', equals('stream')),
            ('op', equals('create')),
            ('streams', check_list(check_dict([
                ('description', check_string),
                ('invite_only', check_bool),
                ('name', check_string),
                ('stream_id', check_int),
            ])))
        ])

        events = self.do_test(lambda: self.register("test1", "test1"))
        error = realm_user_add_checker('events[0]', events[0])
        self.assert_on_error(error)
        error = stream_create_checker('events[1]', events[1])
        self.assert_on_error(error)
Exemplo n.º 3
0
    def test_send_message_events(self):
        schema_checker = check_dict([
            ('type', equals('message')),
            ('flags', check_list(None)),
            ('message',
             check_dict([
                 ('avatar_url', check_string),
                 ('client', check_string),
                 ('content', check_string),
                 ('content_type', equals('text/html')),
                 ('display_recipient', check_string),
                 ('gravatar_hash', check_string),
                 ('id', check_int),
                 ('recipient_id', check_int),
                 ('sender_domain', check_string),
                 ('sender_email', check_string),
                 ('sender_full_name', check_string),
                 ('sender_id', check_int),
                 ('sender_short_name', check_string),
                 ('subject', check_string),
                 ('subject_links', check_list(None)),
                 ('timestamp', check_int),
                 ('type', check_string),
             ])),
        ])
        events = self.do_test(lambda: self.send_message(
            "*****@*****.**", "Verona", Recipient.STREAM, "hello"))
        error = schema_checker('events[0]', events[0])
        self.assert_on_error(error)

        schema_checker = check_dict([
            ('type', equals('update_message')),
            ('flags', check_list(None)),
            ('content', check_string),
            ('edit_timestamp', check_int),
            ('flags', check_list(None)),
            ('message_id', check_int),
            ('message_ids', check_list(check_int)),
            ('orig_content', check_string),
            ('orig_rendered_content', check_string),
            ('orig_subject', check_string),
            ('propagate_mode', check_string),
            ('rendered_content', check_string),
            ('sender', check_string),
            ('stream_id', check_int),
            ('subject', check_string),
            ('subject_links', check_list(None)),
            # There is also a timestamp field in the event, but we ignore it, as
            # it's kind of an unwanted but harmless side effect of calling log_event.
        ])

        message_id = Message.objects.order_by('-id')[0].id
        topic = 'new_topic'
        propagate_mode = 'change_all'
        content = 'new content'
        events = self.do_test(lambda: do_update_message(
            self.user_profile, message_id, topic, propagate_mode, content))
        error = schema_checker('events[0]', events[0])
        self.assert_on_error(error)
Exemplo n.º 4
0
 def realm_bot_schema(self, field_name, check):
     return check_dict([
         ('type', equals('realm_bot')),
         ('op', equals('update')),
         ('bot', check_dict([
             ('email', check_string),
             (field_name, check),
         ])),
     ])
Exemplo n.º 5
0
 def realm_bot_schema(self, field_name, check):
     return check_dict([
         ('type', equals('realm_bot')),
         ('op', equals('update')),
         ('bot', check_dict([
             ('email', check_string),
             (field_name, check),
         ])),
     ])
Exemplo n.º 6
0
    def test_send_message_events(self):
        schema_checker = check_dict([
            ('type', equals('message')),
            ('flags', check_list(None)),
            ('message', check_dict([
                ('avatar_url', check_string),
                ('client', check_string),
                ('content', check_string),
                ('content_type', equals('text/html')),
                ('display_recipient', check_string),
                ('gravatar_hash', check_string),
                ('id', check_int),
                ('recipient_id', check_int),
                ('sender_domain', check_string),
                ('sender_email', check_string),
                ('sender_full_name', check_string),
                ('sender_id', check_int),
                ('sender_short_name', check_string),
                ('subject', check_string),
                ('subject_links', check_list(None)),
                ('timestamp', check_int),
                ('type', check_string),
            ])),
        ])
        events = self.do_test(lambda: self.send_message("*****@*****.**", "Verona", Recipient.STREAM, "hello"))
        error = schema_checker('events[0]', events[0])
        self.assert_on_error(error)

        schema_checker = check_dict([
            ('type', equals('update_message')),
            ('flags', check_list(None)),
            ('content', check_string),
            ('edit_timestamp', check_int),
            ('flags', check_list(None)),
            ('message_id', check_int),
            ('message_ids', check_list(check_int)),
            ('orig_content', check_string),
            ('orig_rendered_content', check_string),
            ('orig_subject', check_string),
            ('propagate_mode', check_string),
            ('rendered_content', check_string),
            ('sender', check_string),
            ('stream_id', check_int),
            ('subject', check_string),
            ('subject_links', check_list(None)),
            # There is also a timestamp field in the event, but we ignore it, as
            # it's kind of an unwanted but harmless side effect of calling log_event.
        ])

        message_id = Message.objects.order_by('-id')[0].id
        topic = 'new_topic'
        propagate_mode = 'change_all'
        content = 'new content'
        events = self.do_test(lambda: do_update_message(self.user_profile, message_id, topic, propagate_mode, content))
        error = schema_checker('events[0]', events[0])
        self.assert_on_error(error)
Exemplo n.º 7
0
 def test_change_realm_name(self):
     schema_checker = check_dict([
         ('type', equals('realm')),
         ('op', equals('update')),
         ('property', equals('name')),
         ('value', check_string),
     ])
     events = self.do_test(lambda: do_set_realm_name(self.user_profile.realm, 'New Realm Name'))
     error = schema_checker('events[0]', events[0])
     self.assert_on_error(error)
Exemplo n.º 8
0
 def test_change_realm_name(self):
     schema_checker = check_dict([
         ('type', equals('realm')),
         ('op', equals('update')),
         ('property', equals('name')),
         ('value', check_string),
     ])
     events = self.do_test(lambda: do_set_realm_name(self.user_profile.realm, 'New Realm Name'))
     error = schema_checker('events[0]', events[0])
     self.assert_on_error(error)
Exemplo n.º 9
0
    def test_rename_stream(self):
        realm = get_realm('zulip.com')
        stream, _ = create_stream_if_needed(realm, 'old_name')
        new_name = u'stream with a brand new name'
        self.subscribe_to_stream(self.user_profile.email, stream.name)

        action = lambda: do_rename_stream(realm, stream.name, new_name)
        events = self.do_test(action)

        schema_checker = check_dict([
            ('type', equals('stream')),
            ('op', equals('update')),
            ('property', equals('email_address')),
            ('value', check_string),
            ('name', equals('old_name')),
        ])
        error = schema_checker('events[0]', events[0])
        self.assert_on_error(error)

        schema_checker = check_dict([
            ('type', equals('stream')),
            ('op', equals('update')),
            ('property', equals('name')),
            ('value', equals(new_name)),
            ('name', equals('old_name')),
        ])
        error = schema_checker('events[1]', events[1])
        self.assert_on_error(error)
Exemplo n.º 10
0
    def test_rename_stream(self):
        realm = get_realm('zulip.com')
        stream, _ = create_stream_if_needed(realm, 'old_name')
        new_name = u'stream with a brand new name'
        self.subscribe_to_stream(self.user_profile.email, stream.name)

        action = lambda: do_rename_stream(realm, stream.name, new_name)
        events = self.do_test(action)

        schema_checker = check_dict([
            ('type', equals('stream')),
            ('op', equals('update')),
            ('property', equals('email_address')),
            ('value', check_string),
            ('name', equals('old_name')),
        ])
        error = schema_checker('events[0]', events[0])
        self.assert_on_error(error)

        schema_checker = check_dict([
            ('type', equals('stream')),
            ('op', equals('update')),
            ('property', equals('name')),
            ('value', equals(new_name)),
            ('name', equals('old_name')),
        ])
        error = schema_checker('events[1]', events[1])
        self.assert_on_error(error)
Exemplo n.º 11
0
 def test_change_realm_invite_by_admins_only(self):
     schema_checker = check_dict([
         ('type', equals('realm')),
         ('op', equals('update')),
         ('property', equals('invite_by_admins_only')),
         ('value', check_bool),
     ])
     # The first False is probably a noop, then we get transitions in both directions.
     for invite_by_admins_only in (False, True, False):
         events = self.do_test(lambda: do_set_realm_invite_by_admins_only(self.user_profile.realm, invite_by_admins_only))
         error = schema_checker('events[0]', events[0])
         self.assert_on_error(error)
Exemplo n.º 12
0
 def test_change_full_name(self):
     schema_checker = check_dict([
         ('type', equals('realm_user')),
         ('op', equals('update')),
         ('person', check_dict([
             ('email', check_string),
             ('full_name', check_string),
         ])),
     ])
     events = self.do_test(lambda: do_change_full_name(self.user_profile, 'Sir Hamlet'))
     error = schema_checker('events[0]', events[0])
     self.assert_on_error(error)
Exemplo n.º 13
0
 def test_change_full_name(self):
     schema_checker = check_dict([
         ('type', equals('realm_user')),
         ('op', equals('update')),
         ('person', check_dict([
             ('email', check_string),
             ('full_name', check_string),
         ])),
     ])
     events = self.do_test(lambda: do_change_full_name(self.user_profile, 'Sir Hamlet'))
     error = schema_checker('events[0]', events[0])
     self.assert_on_error(error)
Exemplo n.º 14
0
 def test_change_left_side_userlist(self):
     schema_checker = check_dict([
         ('type', equals('update_display_settings')),
         ('setting_name', equals('left_side_userlist')),
         ('user', check_string),
         ('setting', check_bool),
         ])
     # The first False is probably a noop, then we get transitions in both directions.
     for setting_value in [False, True, False]:
         events = self.do_test(lambda: do_change_left_side_userlist(self.user_profile, setting_value))
         error = schema_checker('events[0]', events[0])
         self.assert_on_error(error)
Exemplo n.º 15
0
 def test_change_realm_restricted_to_domain(self):
     schema_checker = check_dict([
         ('type', equals('realm')),
         ('op', equals('update')),
         ('property', equals('restricted_to_domain')),
         ('value', check_bool),
     ])
     # The first True is probably a noop, then we get transitions in both directions.
     for restricted_to_domain in (True, False, True):
         events = self.do_test(lambda: do_set_realm_restricted_to_domain(self.user_profile.realm, restricted_to_domain))
         error = schema_checker('events[0]', events[0])
         self.assert_on_error(error)
Exemplo n.º 16
0
 def test_change_left_side_userlist(self):
     schema_checker = check_dict([
         ('type', equals('update_display_settings')),
         ('setting_name', equals('left_side_userlist')),
         ('user', check_string),
         ('setting', check_bool),
         ])
     # The first False is probably a noop, then we get transitions in both directions.
     for setting_value in [False, True, False]:
         events = self.do_test(lambda: do_change_left_side_userlist(self.user_profile, setting_value))
         error = schema_checker('events[0]', events[0])
         self.assert_on_error(error)
Exemplo n.º 17
0
 def test_change_realm_invite_by_admins_only(self):
     schema_checker = check_dict([
         ('type', equals('realm')),
         ('op', equals('update')),
         ('property', equals('invite_by_admins_only')),
         ('value', check_bool),
     ])
     # The first False is probably a noop, then we get transitions in both directions.
     for invite_by_admins_only in (False, True, False):
         events = self.do_test(lambda: do_set_realm_invite_by_admins_only(self.user_profile.realm, invite_by_admins_only))
         error = schema_checker('events[0]', events[0])
         self.assert_on_error(error)
Exemplo n.º 18
0
 def test_change_realm_restricted_to_domain(self):
     schema_checker = check_dict([
         ('type', equals('realm')),
         ('op', equals('update')),
         ('property', equals('restricted_to_domain')),
         ('value', check_bool),
     ])
     # The first True is probably a noop, then we get transitions in both directions.
     for restricted_to_domain in (True, False, True):
         events = self.do_test(lambda: do_set_realm_restricted_to_domain(self.user_profile.realm, restricted_to_domain))
         error = schema_checker('events[0]', events[0])
         self.assert_on_error(error)
Exemplo n.º 19
0
    def test_realm_emoji_events(self):
        schema_checker = check_dict([
            ('type', equals('realm_emoji')),
            ('op', equals('update')),
            ('realm_emoji', check_dict([])),
        ])
        events = self.do_test(lambda: do_add_realm_emoji(get_realm("zulip.com"), "my_emoji",
                                                         "https://realm.com/my_emoji"))
        error = schema_checker('events[0]', events[0])
        self.assert_on_error(error)

        events = self.do_test(lambda: do_remove_realm_emoji(get_realm("zulip.com"), "my_emoji"))
        error = schema_checker('events[0]', events[0])
        self.assert_on_error(error)
Exemplo n.º 20
0
 def test_do_deactivate_user(self):
     bot_deactivate_checker = check_dict([
         ('type', equals('realm_bot')),
         ('op', equals('remove')),
         ('bot', check_dict([
             ('email', check_string),
             ('full_name', check_string),
         ])),
     ])
     bot = self.create_bot('*****@*****.**')
     action = lambda: do_deactivate_user(bot)
     events = self.do_test(action)
     error = bot_deactivate_checker('events[1]', events[1])
     self.assert_on_error(error)
Exemplo n.º 21
0
 def test_change_is_admin(self):
     schema_checker = check_dict([
         ('type', equals('realm_user')),
         ('op', equals('update')),
         ('person', check_dict([
             ('email', check_string),
             ('is_admin', check_bool),
         ])),
     ])
     # The first False is probably a noop, then we get transitions in both directions.
     for is_admin in [False, True, False]:
         events = self.do_test(lambda: do_change_is_admin(self.user_profile, is_admin))
         error = schema_checker('events[0]', events[0])
         self.assert_on_error(error)
Exemplo n.º 22
0
    def test_realm_emoji_events(self):
        schema_checker = check_dict([
            ('type', equals('realm_emoji')),
            ('op', equals('update')),
            ('realm_emoji', check_dict([])),
        ])
        events = self.do_test(lambda: do_add_realm_emoji(get_realm("zulip.com"), "my_emoji",
                                                         "https://realm.com/my_emoji"))
        error = schema_checker('events[0]', events[0])
        self.assert_on_error(error)

        events = self.do_test(lambda: do_remove_realm_emoji(get_realm("zulip.com"), "my_emoji"))
        error = schema_checker('events[0]', events[0])
        self.assert_on_error(error)
Exemplo n.º 23
0
 def test_change_is_admin(self):
     schema_checker = check_dict([
         ('type', equals('realm_user')),
         ('op', equals('update')),
         ('person', check_dict([
             ('email', check_string),
             ('is_admin', check_bool),
         ])),
     ])
     # The first False is probably a noop, then we get transitions in both directions.
     for is_admin in [False, True, False]:
         events = self.do_test(lambda: do_change_is_admin(self.user_profile, is_admin))
         error = schema_checker('events[0]', events[0])
         self.assert_on_error(error)
Exemplo n.º 24
0
 def test_do_deactivate_user(self):
     bot_deactivate_checker = check_dict([
         ('type', equals('realm_bot')),
         ('op', equals('remove')),
         ('bot', check_dict([
             ('email', check_string),
             ('full_name', check_string),
         ])),
     ])
     bot = self.create_bot('*****@*****.**')
     action = lambda: do_deactivate_user(bot)
     events = self.do_test(action)
     error = bot_deactivate_checker('events[1]', events[1])
     self.assert_on_error(error)
Exemplo n.º 25
0
def check_realm_bot_add(var_name: str, event: Dict[str, Any],) -> None:
    _check_realm_bot_add(var_name, event)

    bot_type = event["bot"]["bot_type"]

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

    if bot_type == UserProfile.DEFAULT_BOT:
        equals([])(services_field, services)
    elif bot_type == UserProfile.OUTGOING_WEBHOOK_BOT:
        check_list(_check_bot_services_outgoing, length=1)(services_field, services)
    elif bot_type == UserProfile.EMBEDDED_BOT:
        check_list(_check_bot_services_embedded, length=1)(services_field, services)
    else:
        raise AssertionError(f"Unknown bot_type: {bot_type}")
Exemplo n.º 26
0
 def test_pointer_events(self):
     schema_checker = check_dict([('type', equals('pointer')),
                                  ('pointer', check_int)])
     events = self.do_test(
         lambda: do_update_pointer(self.user_profile, 1500))
     error = schema_checker('events[0]', events[0])
     self.assert_on_error(error)
Exemplo n.º 27
0
 def test_muted_topics_events(self):
     muted_topics_checker = check_dict([
         ('type', equals('muted_topics')),
         ('muted_topics', check_list(check_list(check_string, 2))),
     ])
     events = self.do_test(lambda: do_set_muted_topics(self.user_profile, [["Denmark", "topic"]]))
     error = muted_topics_checker('events[0]', events[0])
     self.assert_on_error(error)
Exemplo n.º 28
0
 def test_muted_topics_events(self):
     muted_topics_checker = check_dict([
         ('type', equals('muted_topics')),
         ('muted_topics', check_list(check_list(check_string, 2))),
     ])
     events = self.do_test(lambda: do_set_muted_topics(self.user_profile, [["Denmark", "topic"]]))
     error = muted_topics_checker('events[0]', events[0])
     self.assert_on_error(error)
Exemplo n.º 29
0
 def test_pointer_events(self):
     schema_checker = check_dict([
         ('type', equals('pointer')),
         ('pointer', check_int)
     ])
     events = self.do_test(lambda: do_update_pointer(self.user_profile, 1500))
     error = schema_checker('events[0]', events[0])
     self.assert_on_error(error)
Exemplo n.º 30
0
 def test_create_bot(self):
     bot_created_checker = check_dict([
         ('type', equals('realm_bot')),
         ('op', equals('add')),
         ('bot', check_dict([
             ('email', check_string),
             ('full_name', check_string),
             ('api_key', check_string),
             ('default_sending_stream', check_none_or(check_string)),
             ('default_events_register_stream', check_none_or(check_string)),
             ('default_all_public_streams', check_bool),
             ('avatar_url', check_string),
         ])),
     ])
     action = lambda: self.create_bot('*****@*****.**')
     events = self.do_test(action)
     error = bot_created_checker('events[1]', events[1])
     self.assert_on_error(error)
Exemplo n.º 31
0
 def test_create_bot(self):
     bot_created_checker = check_dict([
         ('type', equals('realm_bot')),
         ('op', equals('add')),
         ('bot', check_dict([
             ('email', check_string),
             ('full_name', check_string),
             ('api_key', check_string),
             ('default_sending_stream', check_none_or(check_string)),
             ('default_events_register_stream', check_none_or(check_string)),
             ('default_all_public_streams', check_bool),
             ('avatar_url', check_string),
         ])),
     ])
     action = lambda: self.create_bot('*****@*****.**')
     events = self.do_test(action)
     error = bot_created_checker('events[1]', events[1])
     self.assert_on_error(error)
Exemplo n.º 32
0
    def test_alert_words_events(self):
        alert_words_checker = check_dict([
            ('type', equals('alert_words')),
            ('alert_words', check_list(check_string)),
        ])

        events = self.do_test(lambda: do_add_alert_words(self.user_profile, ["alert_word"]))
        error = alert_words_checker('events[0]', events[0])
        self.assert_on_error(error)

        events = self.do_test(lambda: do_remove_alert_words(self.user_profile, ["alert_word"]))
        error = alert_words_checker('events[0]', events[0])
        self.assert_on_error(error)
Exemplo n.º 33
0
    def test_realm_filter_events(self):
        schema_checker = check_dict([
            ('type', equals('realm_filters')),
            ('realm_filters', check_list(None)), # TODO: validate tuples in the list
        ])
        events = self.do_test(lambda: do_add_realm_filter(get_realm("zulip.com"), "#[123]",
                                                          "https://realm.com/my_realm_filter/%(id)s"))
        error = schema_checker('events[0]', events[0])
        self.assert_on_error(error)

        self.do_test(lambda: do_remove_realm_filter(get_realm("zulip.com"), "#[123]"))
        error = schema_checker('events[0]', events[0])
        self.assert_on_error(error)
Exemplo n.º 34
0
    def test_realm_filter_events(self):
        schema_checker = check_dict([
            ('type', equals('realm_filters')),
            ('realm_filters', check_list(None)), # TODO: validate tuples in the list
        ])
        events = self.do_test(lambda: do_add_realm_filter(get_realm("zulip.com"), "#[123]",
                                                          "https://realm.com/my_realm_filter/%(id)s"))
        error = schema_checker('events[0]', events[0])
        self.assert_on_error(error)

        self.do_test(lambda: do_remove_realm_filter(get_realm("zulip.com"), "#[123]"))
        error = schema_checker('events[0]', events[0])
        self.assert_on_error(error)
Exemplo n.º 35
0
    def test_alert_words_events(self):
        alert_words_checker = check_dict([
            ('type', equals('alert_words')),
            ('alert_words', check_list(check_string)),
        ])

        events = self.do_test(lambda: do_add_alert_words(self.user_profile, ["alert_word"]))
        error = alert_words_checker('events[0]', events[0])
        self.assert_on_error(error)

        events = self.do_test(lambda: do_remove_alert_words(self.user_profile, ["alert_word"]))
        error = alert_words_checker('events[0]', events[0])
        self.assert_on_error(error)
Exemplo n.º 36
0
    check_union,
    check_url,
    equals,
)
from zerver.models import Realm, Stream, UserProfile

# These fields are used for "stream" events, and are included in the
# larger "subscription" events that also contain personal settings.
basic_stream_fields = [
    ("description", check_string),
    ("first_message_id", check_none_or(check_int)),
    ("history_public_to_subscribers", check_bool),
    ("invite_only", check_bool),
    ("is_announcement_only", check_bool),
    ("is_web_public", check_bool),
    ("message_retention_days", equals(None)),
    ("name", check_string),
    ("rendered_description", check_string),
    ("stream_id", check_int),
    ("stream_post_policy", check_int),
    ("date_created", check_int),
]

subscription_fields: Sequence[Tuple[str, Validator[object]]] = [
    *basic_stream_fields,
    ("audible_notifications", check_none_or(check_bool)),
    ("color", check_string),
    ("desktop_notifications", check_none_or(check_bool)),
    ("email_address", check_string),
    ("email_notifications", check_none_or(check_bool)),
    ("in_home_view", check_bool),
Exemplo n.º 37
0
    def test_subscribe_events(self):
        subscription_schema_checker = check_list(
            check_dict([
                ('color', check_string),
                ('description', check_string),
                ('email_address', check_string),
                ('invite_only', check_bool),
                ('in_home_view', check_bool),
                ('name', check_string),
                ('desktop_notifications', check_bool),
                ('audible_notifications', check_bool),
                ('stream_id', check_int),
                ('subscribers', check_list(check_int)),
            ])
        )
        add_schema_checker = check_dict([
            ('type', equals('subscription')),
            ('op', equals('add')),
            ('subscriptions', subscription_schema_checker),
        ])
        remove_schema_checker = check_dict([
            ('type', equals('subscription')),
            ('op', equals('remove')),
            ('subscriptions', check_list(
                check_dict([
                    ('name', equals('test_stream')),
                    ('stream_id', check_int),
                ]),
            )),
        ])
        peer_add_schema_checker = check_dict([
            ('type', equals('subscription')),
            ('op', equals('peer_add')),
            ('user_email', check_string),
            ('subscriptions', check_list(check_string)),
        ])
        peer_remove_schema_checker = check_dict([
            ('type', equals('subscription')),
            ('op', equals('peer_remove')),
            ('user_email', check_string),
            ('subscriptions', check_list(check_string)),
        ])
        stream_update_schema_checker = check_dict([
            ('type', equals('stream')),
            ('op', equals('update')),
            ('property', equals('description')),
            ('value', check_string),
            ('name', check_string),
        ])

        action = lambda: self.subscribe_to_stream("*****@*****.**", "test_stream")
        events = self.do_test(action, event_types=["subscription", "realm_user"])
        error = add_schema_checker('events[0]', events[0])
        self.assert_on_error(error)

        action = lambda: self.subscribe_to_stream("*****@*****.**", "test_stream")
        events = self.do_test(action)
        error = peer_add_schema_checker('events[0]', events[0])
        self.assert_on_error(error)

        stream = get_stream("test_stream", self.user_profile.realm)

        action = lambda: do_remove_subscription(get_user_profile_by_email("*****@*****.**"), stream)
        events = self.do_test(action)
        error = peer_remove_schema_checker('events[0]', events[0])
        self.assert_on_error(error)

        action = lambda: do_remove_subscription(get_user_profile_by_email("*****@*****.**"), stream)
        events = self.do_test(action)
        error = remove_schema_checker('events[1]', events[1])
        self.assert_on_error(error)

        action = lambda: self.subscribe_to_stream("*****@*****.**", "test_stream")
        events = self.do_test(action)
        error = add_schema_checker('events[1]', events[1])
        self.assert_on_error(error)

        action = lambda: do_change_stream_description(get_realm('zulip.com'), 'test_stream', u'new description')
        events = self.do_test(action)
        error = stream_update_schema_checker('events[0]', events[0])
        self.assert_on_error(error)
Exemplo n.º 38
0
    def test_subscribe_events(self):
        subscription_schema_checker = check_list(
            check_dict([
                ('color', check_string),
                ('description', check_string),
                ('email_address', check_string),
                ('invite_only', check_bool),
                ('in_home_view', check_bool),
                ('name', check_string),
                ('desktop_notifications', check_bool),
                ('audible_notifications', check_bool),
                ('stream_id', check_int),
                ('subscribers', check_list(check_int)),
            ])
        )
        add_schema_checker = check_dict([
            ('type', equals('subscription')),
            ('op', equals('add')),
            ('subscriptions', subscription_schema_checker),
        ])
        remove_schema_checker = check_dict([
            ('type', equals('subscription')),
            ('op', equals('remove')),
            ('subscriptions', check_list(
                check_dict([
                    ('name', equals('test_stream')),
                    ('stream_id', check_int),
                ]),
            )),
        ])
        peer_add_schema_checker = check_dict([
            ('type', equals('subscription')),
            ('op', equals('peer_add')),
            ('user_email', check_string),
            ('subscriptions', check_list(check_string)),
        ])
        peer_remove_schema_checker = check_dict([
            ('type', equals('subscription')),
            ('op', equals('peer_remove')),
            ('user_email', check_string),
            ('subscriptions', check_list(check_string)),
        ])
        stream_update_schema_checker = check_dict([
            ('type', equals('stream')),
            ('op', equals('update')),
            ('property', equals('description')),
            ('value', check_string),
            ('name', check_string),
        ])

        action = lambda: self.subscribe_to_stream("*****@*****.**", "test_stream")
        events = self.do_test(action, event_types=["subscription", "realm_user"])
        error = add_schema_checker('events[0]', events[0])
        self.assert_on_error(error)

        action = lambda: self.subscribe_to_stream("*****@*****.**", "test_stream")
        events = self.do_test(action)
        error = peer_add_schema_checker('events[0]', events[0])
        self.assert_on_error(error)

        stream = get_stream("test_stream", self.user_profile.realm)

        action = lambda: do_remove_subscription(get_user_profile_by_email("*****@*****.**"), stream)
        events = self.do_test(action)
        error = peer_remove_schema_checker('events[0]', events[0])
        self.assert_on_error(error)

        action = lambda: do_remove_subscription(get_user_profile_by_email("*****@*****.**"), stream)
        events = self.do_test(action)
        error = remove_schema_checker('events[1]', events[1])
        self.assert_on_error(error)

        action = lambda: self.subscribe_to_stream("*****@*****.**", "test_stream")
        events = self.do_test(action)
        error = add_schema_checker('events[1]', events[1])
        self.assert_on_error(error)

        action = lambda: do_change_stream_description(get_realm('zulip.com'), 'test_stream', u'new description')
        events = self.do_test(action)
        error = stream_update_schema_checker('events[0]', events[0])
        self.assert_on_error(error)
Exemplo n.º 39
0
 def test_equals(self):
     # type: () -> None
     x = 5  # type: Any
     self.assertEqual(equals(5)('x', x), None)
     self.assertEqual(equals(6)('x', x), 'x != 6 (5 is wrong)')
Exemplo n.º 40
0
 def test_equals(self):
     # type: () -> None
     x = 5  # type: Any
     self.assertEqual(equals(5)('x', x), None)
     self.assertEqual(equals(6)('x', x), 'x != 6 (5 is wrong)')