mirror of https://github.com/zulip/zulip.git
event_schema: Extract check_realm_user_add.
Note that we make the schema for profile_data slightly more realistic, but it doesn't actually get exercised by our current tests (apart from making sure it's a dict), since we don't have profile data for our test realm. We also don't have the optional fields for bots, since our tests don't exercise that, nor delivery_email. So we exempt realm_user_add_event from openapi checks for now. When we try to match the openapi specs better, we will probably want to add a few tests to test_events. Obviously getting good coverage for adding users would be nice for all these scenarios: * delivery_email matters * bots * realm has profile fields
This commit is contained in:
parent
dc2176a965
commit
4084f0b949
|
@ -71,6 +71,8 @@ EXEMPT_OPENAPI_NAMES = [
|
|||
# tuple handling
|
||||
"muted_topics_event",
|
||||
"realm_filters_event",
|
||||
# bots, delivery_email, profile_data
|
||||
"realm_user_add_event",
|
||||
]
|
||||
|
||||
|
||||
|
|
|
@ -664,6 +664,33 @@ def check_realm_update(var_name: str, event: Dict[str, object], prop: str,) -> N
|
|||
raise AssertionError(f"Unexpected property type {property_type}")
|
||||
|
||||
|
||||
realm_user_type = DictType(
|
||||
required_keys=[
|
||||
("user_id", int),
|
||||
("email", str),
|
||||
("avatar_url", OptionalType(str)),
|
||||
("avatar_version", int),
|
||||
("full_name", str),
|
||||
("is_admin", bool),
|
||||
("is_owner", bool),
|
||||
("is_bot", bool),
|
||||
("is_guest", bool),
|
||||
("is_active", bool),
|
||||
("profile_data", StringDictType(dict)),
|
||||
("timezone", str),
|
||||
("date_joined", str),
|
||||
]
|
||||
)
|
||||
|
||||
realm_user_add_event = event_dict_type(
|
||||
required_keys=[
|
||||
("type", Equals("realm_user")),
|
||||
("op", Equals("add")),
|
||||
("person", realm_user_type),
|
||||
]
|
||||
)
|
||||
check_realm_user_add = make_checker(realm_user_add_event)
|
||||
|
||||
custom_profile_field_type = DictType(
|
||||
required_keys=[
|
||||
# vertical formatting
|
||||
|
|
|
@ -111,6 +111,7 @@ from zerver.lib.event_schema import (
|
|||
check_realm_export,
|
||||
check_realm_filters,
|
||||
check_realm_update,
|
||||
check_realm_user_add,
|
||||
check_realm_user_update,
|
||||
check_stream_create,
|
||||
check_stream_delete,
|
||||
|
@ -147,7 +148,6 @@ from zerver.lib.validator import (
|
|||
check_dict_only,
|
||||
check_int,
|
||||
check_list,
|
||||
check_none_or,
|
||||
check_string,
|
||||
equals,
|
||||
)
|
||||
|
@ -760,61 +760,21 @@ class NormalActionsTest(BaseAction):
|
|||
)
|
||||
|
||||
def test_register_events(self) -> None:
|
||||
realm_user_add_checker = check_events_dict([
|
||||
('type', equals('realm_user')),
|
||||
('op', equals('add')),
|
||||
('person', check_dict_only([
|
||||
('user_id', check_int),
|
||||
('email', check_string),
|
||||
('avatar_url', check_none_or(check_string)),
|
||||
('avatar_version', check_int),
|
||||
('full_name', check_string),
|
||||
('is_admin', check_bool),
|
||||
('is_owner', check_bool),
|
||||
('is_bot', check_bool),
|
||||
('is_guest', check_bool),
|
||||
('is_active', check_bool),
|
||||
('profile_data', check_dict_only([])),
|
||||
('timezone', check_string),
|
||||
('date_joined', check_string),
|
||||
])),
|
||||
])
|
||||
|
||||
events = self.verify_action(
|
||||
lambda: self.register("test1@zulip.com", "test1"))
|
||||
self.assert_length(events, 1)
|
||||
realm_user_add_checker('events[0]', events[0])
|
||||
check_realm_user_add('events[0]', events[0])
|
||||
new_user_profile = get_user_by_delivery_email("test1@zulip.com", self.user_profile.realm)
|
||||
self.assertEqual(new_user_profile.delivery_email, "test1@zulip.com")
|
||||
|
||||
def test_register_events_email_address_visibility(self) -> None:
|
||||
realm_user_add_checker = check_events_dict([
|
||||
('type', equals('realm_user')),
|
||||
('op', equals('add')),
|
||||
('person', check_dict_only([
|
||||
('user_id', check_int),
|
||||
('email', check_string),
|
||||
('avatar_url', check_none_or(check_string)),
|
||||
('avatar_version', check_int),
|
||||
('full_name', check_string),
|
||||
('is_active', check_bool),
|
||||
('is_admin', check_bool),
|
||||
('is_owner', check_bool),
|
||||
('is_bot', check_bool),
|
||||
('is_guest', check_bool),
|
||||
('profile_data', check_dict_only([])),
|
||||
('timezone', check_string),
|
||||
('date_joined', check_string),
|
||||
])),
|
||||
])
|
||||
|
||||
do_set_realm_property(self.user_profile.realm, "email_address_visibility",
|
||||
Realm.EMAIL_ADDRESS_VISIBILITY_ADMINS)
|
||||
|
||||
events = self.verify_action(
|
||||
lambda: self.register("test1@zulip.com", "test1"))
|
||||
self.assert_length(events, 1)
|
||||
realm_user_add_checker('events[0]', events[0])
|
||||
check_realm_user_add('events[0]', events[0])
|
||||
new_user_profile = get_user_by_delivery_email("test1@zulip.com", self.user_profile.realm)
|
||||
self.assertEqual(new_user_profile.email, f"user{new_user_profile.id}@zulip.testserver")
|
||||
|
||||
|
|
Loading…
Reference in New Issue