-
-
Notifications
You must be signed in to change notification settings - Fork 277
Add handling for User update events #1249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -237,6 +237,7 @@ def test_register_initial_desired_events(self, mocker, initial_data): | |
"update_display_settings", | ||
"user_settings", | ||
"realm_emoji", | ||
"realm_user", | ||
] | ||
fetch_event_types = [ | ||
"realm", | ||
|
@@ -3346,6 +3347,48 @@ def test__handle_subscription_event_subscribers_one_user_multiple_streams( | |
new_subscribers = model.stream_dict[stream_id]["subscribers"] | ||
assert new_subscribers == expected_subscribers | ||
|
||
@pytest.mark.parametrize( | ||
"person, changed_details", | ||
[ | ||
( | ||
{"full_name": "New Full Name"}, | ||
"full_name", | ||
), | ||
({"timezone": "New Timezone"}, "timezone"), | ||
({"is_billing_admin": False}, "is_billing_admin"), | ||
({"role": 10}, "role"), | ||
( | ||
{"avatar_url": "new_avatar_url", "avatar_version": 21}, | ||
"avatar_url", | ||
), | ||
({"new_email": "new_display@email.com"}, "email"), | ||
( | ||
{"delivery_email": "new_delivery@email.com"}, | ||
"delivery_email", | ||
), | ||
], | ||
ids=[ | ||
"full_name", | ||
"timezone", | ||
"billing_admin_role", | ||
"role", | ||
"avatar", | ||
"display_email", | ||
"delivery_email", | ||
], | ||
) | ||
def test__handle_realm_user_event( | ||
self, person, changed_details, model, initial_data | ||
): | ||
# For testing purposes, initial_data["realm_users"][1] from the initial_data fixture is used here. | ||
person["user_id"] = 11 | ||
event = {"type": "realm_user", "op": "update", "id": 1000, "person": person} | ||
model._handle_realm_user_event(event) | ||
assert ( | ||
initial_data["realm_users"][1][changed_details] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm guessing the If that's the case, it would be more reliable to make that explicit in the test code, eg. if the initial data gets reordered at a later stage, this would make this test fail even though it's functionally correct? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I'll add a comment for this 👍 |
||
== event["person"][changed_details] | ||
) | ||
|
||
@pytest.mark.parametrize("value", [True, False]) | ||
def test__handle_user_settings_event(self, mocker, model, value): | ||
setting = "send_private_typing_notifications" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -167,6 +167,37 @@ class ReactionEvent(TypedDict): | |
message_id: int | ||
|
||
|
||
class RealmUserEventPerson(TypedDict, total=False): | ||
user_id: int | ||
|
||
full_name: str | ||
|
||
avatar_url: str | ||
avatar_source: str | ||
avatar_url_medium: str | ||
avatar_version: int | ||
|
||
# NOTE: This field will be removed in future as it is redundant with the user_id | ||
# email: str | ||
timezone: str | ||
|
||
role: int | ||
|
||
email: str | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In comparing the fields that can be updated, this one stands out as different from the remaining one field possible (custom_profile_field), unless I'm missing another use of email? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I see your point. Can we avoid that by moving the conditional into the loop where we've found the user-id? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, let me just read the code again, I may just merge these first two commits roughly as they are. |
||
|
||
new_email: str | ||
|
||
delivery_email: str | ||
|
||
is_billing_admin: bool | ||
|
||
|
||
class RealmUserEvent(TypedDict): | ||
type: Literal["realm_user"] | ||
op: Literal["update"] | ||
person: RealmUserEventPerson | ||
|
||
|
||
class SubscriptionEvent(TypedDict): | ||
type: Literal["subscription"] | ||
op: str | ||
|
@@ -249,4 +280,5 @@ class UpdateGlobalNotificationsEvent(TypedDict): | |
UpdateRealmEmojiEvent, | ||
UpdateUserSettingsEvent, | ||
UpdateGlobalNotificationsEvent, | ||
RealmUserEvent, | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There a lot of test cases & ids, so it's simpler to keep them inline - then later we wouldn't have to check where in each list to add/remove/edit them, or to move them around.