-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
tests: Add set_user_role helper method to ZulipTestCase. #37000
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
Conversation
corporate/tests/test_stripe.py
Outdated
| do_change_user_role(hamlet, UserProfile.ROLE_REALM_OWNER, acting_user=None) | ||
| do_change_user_role(iago, UserProfile.ROLE_REALM_OWNER, acting_user=None) | ||
| self.set_user_role(hamlet, UserProfile.ROLE_REALM_OWNER, acting_user=None) | ||
| self.set_user_role(iago, UserProfile.ROLE_REALM_OWNER, acting_user=None) |
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.
The intent was for this new test helper to have acting_user=None be the default, so all these tests don't need to spell that out either.
7697d6d to
abac33f
Compare
|
@0xthedance just a small note: You should always post a comment explaining how you addressed the feedback on GitHub PR threads; that can help a lot with explicit handoffs and results in faster review. |
zerver/tests/test_example.py
Outdated
| # It is a good idea for your tests to clearly demonstrate a | ||
| # **change** to a value. So here we want to make sure that | ||
| # do_change_user_role will change Hamlet such that | ||
| # self.set_user_role will change Hamlet such that |
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.
This looks to be incorrectly changed.
|
Looks great, merging with these changes: diff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.py
index 64af88a707..cef674a94f 100644
--- a/zerver/lib/test_classes.py
+++ b/zerver/lib/test_classes.py
@@ -2369,6 +2369,16 @@ class ZulipTestCase(ZulipTestCaseMixin, TestCase):
)
def set_user_role(self, user: UserProfile, role: int) -> None:
+ """
+ Test helper for switching a user to a given role. Hardcodes
+ acting_user=None, which means the change is treated as
+ though it was done by a management command, not another
+ user.
+
+ Tests using this should consider using users who have the
+ appropriate initial role; this is usually more readable and
+ a bit faster.
+ """
do_change_user_role(user, role, acting_user=None)
diff --git a/zerver/tests/test_example.py b/zerver/tests/test_example.py
index b19d03dd6e..f74b5d892f 100644
--- a/zerver/tests/test_example.py
+++ b/zerver/tests/test_example.py
@@ -60,7 +60,7 @@ class TestBasicUserStuff(ZulipTestCase):
# It is a good idea for your tests to clearly demonstrate a
# **change** to a value. So here we want to make sure that
- # self.set_user_role will change Hamlet such that
+ # do_change_user_role will change Hamlet such that
# is_administrator_role becomes True, but we first assert it's
# False.
self.assertFalse(is_administrator_role(hamlet.role)) |
This commit adds a set_user_role helper method to ZulipTestCase with acting_user defaulting to None, and updates all test files to use this helper. This is a prep commit for PR zulip#36208.
abac33f to
1b82537
Compare
This adds a helper method that wraps
do_change_user_rolefor use in tests. This is a preparatory commit for PR #36208.In PR #36208, a variable
notifyis added todo_change_user_role. This PR will make it easy to update all the tests withnotify=False.Updates all existing test files to use the new helper method instead of calling
do_change_user_roledirectly.Self-review checklist
(variable names, code reuse, readability, etc.).
Communicate decisions, questions, and potential concerns.
Individual commits are ready for review (see commit discipline).
Completed manual review and testing of the following: