Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
refactor: Make acting_user a mandatory kwarg for do_create_user.
shanukun4b6794660548
diff --git a/analytics/tests/test_counts.py b/analytics/tests/test_counts.pyindex 7b892a7e6fe..579391ed8ba 100644--- a/analytics/tests/test_counts.py+++ b/analytics/tests/test_counts.py@@ -1309,7 +1309,9 @@ class TestLoggingCountStats(AnalyticsTestCase):def test_active_users_log_by_is_bot(self) -> None:property = "active_users_log:is_bot:day"- user = do_create_user("email", "password", self.default_realm, "full_name")+ user = do_create_user(+ "email", "password", self.default_realm, "full_name", acting_user=None+ )self.assertEqual(1,RealmCount.objects.filter(property=property, subgroup=False).aggregate(Sum("value"))[@@ -1644,10 +1646,18 @@ class TestActiveUsersAudit(AnalyticsTestCase):self.assertTableState(UserCount, ["user", "subgroup"], [[user1, "false"], [user2, "false"]])def test_end_to_end_with_actions_dot_py(self) -> None:- user1 = do_create_user("email1", "password", self.default_realm, "full_name")- user2 = do_create_user("email2", "password", self.default_realm, "full_name")- user3 = do_create_user("email3", "password", self.default_realm, "full_name")- user4 = do_create_user("email4", "password", self.default_realm, "full_name")+ user1 = do_create_user(+ "email1", "password", self.default_realm, "full_name", acting_user=None+ )+ user2 = do_create_user(+ "email2", "password", self.default_realm, "full_name", acting_user=None+ )+ user3 = do_create_user(+ "email3", "password", self.default_realm, "full_name", acting_user=None+ )+ user4 = do_create_user(+ "email4", "password", self.default_realm, "full_name", acting_user=None+ )do_deactivate_user(user2)do_activate_user(user3)do_reactivate_user(user4)@@ -1761,9 +1771,13 @@ class TestRealmActiveHumans(AnalyticsTestCase):)def test_end_to_end(self) -> None:- user1 = do_create_user("email1", "password", self.default_realm, "full_name")- user2 = do_create_user("email2", "password", self.default_realm, "full_name")- do_create_user("email3", "password", self.default_realm, "full_name")+ user1 = do_create_user(+ "email1", "password", self.default_realm, "full_name", acting_user=None+ )+ user2 = do_create_user(+ "email2", "password", self.default_realm, "full_name", acting_user=None+ )+ do_create_user("email3", "password", self.default_realm, "full_name", acting_user=None)time_zero = floor_to_day(timezone_now()) + self.DAYupdate_user_activity_interval(user1, time_zero)update_user_activity_interval(user2, time_zero)diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.pyindex 4ed30496e8d..95e7ac95731 100644--- a/corporate/tests/test_stripe.py+++ b/corporate/tests/test_stripe.py@@ -2710,7 +2710,7 @@ class LicenseLedgerTest(StripeTestCase):def test_user_changes(self) -> None:self.local_upgrade(self.seat_count, True, CustomerPlan.ANNUAL, "token")- user = do_create_user("email", "password", get_realm("zulip"), "name")+ user = do_create_user("email", "password", get_realm("zulip"), "name", acting_user=None)do_deactivate_user(user)do_reactivate_user(user)# Not a proper use of do_activate_user, but fine for this testdiff --git a/tools/test-api b/tools/test-apiindex 1f6ddb1cbc8..0af88172cdb 100755--- a/tools/test-api+++ b/tools/test-api@@ -73,10 +73,7 @@ with test_server_running(force=options.force, external_host="zulipdev.com:9981")# Prepare the non-admin clientemail = "[email protected]" # guest is not an adminguest_user = do_create_user(- "[email protected]",- "secret",- get_realm("zulip"),- "Mr. Guest",+ "[email protected]", "secret", get_realm("zulip"), "Mr. Guest", acting_user=None)api_key = get_api_key(guest_user)nonadmin_client = Client(diff --git a/zerver/lib/actions.py b/zerver/lib/actions.pyindex b4b10ef5505..a39f83943f6 100644--- a/zerver/lib/actions.py+++ b/zerver/lib/actions.py@@ -614,7 +614,8 @@ def do_create_user(default_stream_groups: Sequence[DefaultStreamGroup] = [],source_profile: Optional[UserProfile] = None,realm_creation: bool = False,- acting_user: Optional[UserProfile] = None,+ *,+ acting_user: Optional[UserProfile],) -> UserProfile:user_profile = create_user(diff --git a/zerver/openapi/curl_param_value_generators.py b/zerver/openapi/curl_param_value_generators.pyindex b32da7b1c2c..71fb467e63c 100644--- a/zerver/openapi/curl_param_value_generators.py+++ b/zerver/openapi/curl_param_value_generators.py@@ -271,6 +271,10 @@ def upload_custom_emoji() -> Dict[str, object]:@openapi_param_value_generator(["/users/{user_id}:delete"])def deactivate_user() -> Dict[str, object]:user_profile = do_create_user(- email="[email protected]", password=None, full_name="test_user", realm=get_realm("zulip")+ email="[email protected]",+ password=None,+ full_name="test_user",+ realm=get_realm("zulip"),+ acting_user=None,)return {"user_id": user_profile.id}diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.pyindex f277328edd1..b9370815fe2 100644--- a/zerver/tests/test_auth_backends.py+++ b/zerver/tests/test_auth_backends.py@@ -3245,7 +3245,9 @@ class GitHubAuthBackendTest(SocialAuthBase):# Now we create the user account with the noreply email and verify that it's# possible to sign in to it.realm = get_realm("zulip")- do_create_user(noreply_email, "password", realm, account_data_dict["name"])+ do_create_user(+ noreply_email, "password", realm, account_data_dict["name"], acting_user=None+ )result = self.social_auth_test(account_data_dict,subdomain="zulip",@@ -5349,12 +5351,7 @@ class TestZulipLDAPUserPopulator(ZulipLDAPTestCase):test_realm = do_create_realm("test", "test", False)hamlet = self.example_user("hamlet")email = hamlet.delivery_email- hamlet2 = do_create_user(- email,- None,- test_realm,- hamlet.full_name,- )+ hamlet2 = do_create_user(email, None, test_realm, hamlet.full_name, acting_user=None)self.change_ldap_user_attr("hamlet", "cn", "Second Hamlet")expected_call_args = [hamlet2, "Second Hamlet", None]diff --git a/zerver/tests/test_digest.py b/zerver/tests/test_digest.pyindex 409ee28d783..99ace905243 100644--- a/zerver/tests/test_digest.py+++ b/zerver/tests/test_digest.py@@ -384,6 +384,7 @@ class TestDigestEmailMessages(ZulipTestCase):realm,"some_bot",bot_type=UserProfile.DEFAULT_BOT,+ acting_user=None,)# Check that bots are not sent emailsdiff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.pyindex bcf3dd0acea..dfecda37ec7 100644--- a/zerver/tests/test_events.py+++ b/zerver/tests/test_events.py@@ -667,6 +667,7 @@ class NormalActionsTest(BaseAction):self.user_profile.realm,"full name",prereg_user=prereg_user,+ acting_user=None,),state_change_expected=True,num_events=4,diff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.pyindex 1c2e57e31ee..c2cda7a4ba9 100644--- a/zerver/tests/test_home.py+++ b/zerver/tests/test_home.py@@ -487,15 +487,13 @@ class HomeTest(ZulipTestCase):full_name=bot_name,bot_type=UserProfile.DEFAULT_BOT,bot_owner=owner,+ acting_user=None,)return userdef create_non_active_user(self, realm: Realm, email: str, name: str) -> UserProfile:user = do_create_user(- email=email,- password="123",- realm=realm,- full_name=name,+ email=email, password="123", realm=realm, full_name=name, acting_user=None)# Doing a full-stack deactivation would be expensive here,diff --git a/zerver/tests/test_hotspots.py b/zerver/tests/test_hotspots.pyindex 1ac264e7779..f4213649728 100644--- a/zerver/tests/test_hotspots.py+++ b/zerver/tests/test_hotspots.py@@ -12,10 +12,7 @@ class TestGetNextHotspots(ZulipTestCase):def setUp(self) -> None:super().setUp()self.user = do_create_user(- "[email protected]",- "password",- get_realm("zulip"),- "user",+ "[email protected]", "password", get_realm("zulip"), "user", acting_user=None)def test_first_hotspot(self) -> None:diff --git a/zerver/tests/test_import_export.py b/zerver/tests/test_import_export.pyindex f73de71ceaf..32f77ebf40d 100644--- a/zerver/tests/test_import_export.py+++ b/zerver/tests/test_import_export.py@@ -818,6 +818,7 @@ class ImportExportTest(ZulipTestCase):full_name="bot",bot_type=UserProfile.EMBEDDED_BOT,bot_owner=sample_user,+ acting_user=None,)storage = StateHandler(bot_profile)storage.put("some key", "some value")diff --git a/zerver/tests/test_management_commands.py b/zerver/tests/test_management_commands.pyindex d5c0a505779..f3277e9c7a0 100644--- a/zerver/tests/test_management_commands.py+++ b/zerver/tests/test_management_commands.py@@ -78,7 +78,7 @@ class TestZulipBaseCommand(ZulipTestCase):with self.assertRaisesRegex(CommandError, "server does not contain a user with email"):self.command.get_user("[email protected]", None)- do_create_user(email, "password", mit_realm, "full_name")+ do_create_user(email, "password", mit_realm, "full_name", acting_user=None)with self.assertRaisesRegex(CommandError, "server contains multiple users with that email"):self.command.get_user(email, None)diff --git a/zerver/tests/test_message_send.py b/zerver/tests/test_message_send.pyindex 93d4e8c1161..5382a240625 100644--- a/zerver/tests/test_message_send.py+++ b/zerver/tests/test_message_send.py@@ -210,6 +210,7 @@ class MessagePOSTTest(ZulipTestCase):realm=non_admin_profile.realm,full_name="freebot",bot_type=UserProfile.DEFAULT_BOT,+ acting_user=None,)self._send_and_verify_message(bot_without_owner,@@ -297,6 +298,7 @@ class MessagePOSTTest(ZulipTestCase):realm=non_admin_profile.realm,full_name="freebot",bot_type=UserProfile.DEFAULT_BOT,+ acting_user=None,)self._send_and_verify_message(bot_without_owner, stream_name, "New members cannot send to this stream."@@ -1560,6 +1562,7 @@ class StreamMessagesTest(ZulipTestCase):full_name="Normal Bot",bot_type=UserProfile.DEFAULT_BOT,bot_owner=cordelia,+ acting_user=None,)content = "test @**Normal Bot** rules"@@ -2305,6 +2308,7 @@ class CheckMessageTest(ZulipTestCase):full_name="",bot_type=UserProfile.DEFAULT_BOT,bot_owner=parent,+ acting_user=None,)bot.last_reminder = Nonediff --git a/zerver/tests/test_outgoing_webhook_system.py b/zerver/tests/test_outgoing_webhook_system.pyindex f1c5b7406d3..01b178085c0 100644--- a/zerver/tests/test_outgoing_webhook_system.py+++ b/zerver/tests/test_outgoing_webhook_system.py@@ -245,6 +245,7 @@ class TestOutgoingWebhookMessaging(ZulipTestCase):email="whatever",realm=bot_owner.realm,password=None,+ acting_user=None,)add_service(diff --git a/zerver/tests/test_realm_emoji.py b/zerver/tests/test_realm_emoji.pyindex ec361813a5a..94d910fa07a 100644--- a/zerver/tests/test_realm_emoji.py+++ b/zerver/tests/test_realm_emoji.py@@ -268,10 +268,7 @@ class RealmEmojiTest(ZulipTestCase):# having same name can be administered independently.realm_1 = do_create_realm("test_realm", "test_realm")emoji_author_1 = do_create_user(- "[email protected]",- password="abc",- realm=realm_1,- full_name="abc",+ "[email protected]", password="abc", realm=realm_1, full_name="abc", acting_user=None)self.create_test_emoji("test_emoji", emoji_author_1)diff --git a/zerver/tests/test_service_bot_system.py b/zerver/tests/test_service_bot_system.pyindex f5f03dab6df..775f80318a1 100644--- a/zerver/tests/test_service_bot_system.py+++ b/zerver/tests/test_service_bot_system.py@@ -30,6 +30,7 @@ class TestServiceBotBasics(ZulipTestCase):full_name="BarBot",bot_type=UserProfile.OUTGOING_WEBHOOK_BOT,bot_owner=self.example_user("cordelia"),+ acting_user=None,)return outgoing_bot@@ -178,6 +179,7 @@ class TestServiceBotStateHandler(ZulipTestCase):full_name="EmbeddedBo1",bot_type=UserProfile.EMBEDDED_BOT,bot_owner=self.user_profile,+ acting_user=None,)self.second_bot_profile = do_create_user(email="[email protected]",@@ -186,6 +188,7 @@ class TestServiceBotStateHandler(ZulipTestCase):full_name="EmbeddedBot2",bot_type=UserProfile.EMBEDDED_BOT,bot_owner=self.user_profile,+ acting_user=None,)def test_basic_storage_and_retrieval(self) -> None:@@ -436,6 +439,7 @@ class TestServiceBotEventTriggers(ZulipTestCase):full_name="FooBot",bot_type=UserProfile.OUTGOING_WEBHOOK_BOT,bot_owner=self.user_profile,+ acting_user=None,)self.second_bot_profile = do_create_user(email="[email protected]",@@ -444,6 +448,7 @@ class TestServiceBotEventTriggers(ZulipTestCase):full_name="BarBot",bot_type=UserProfile.OUTGOING_WEBHOOK_BOT,bot_owner=self.user_profile,+ acting_user=None,)@for_all_bot_typesdiff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.pyindex 00ac297773b..36db670ce37 100644--- a/zerver/tests/test_signup.py+++ b/zerver/tests/test_signup.py@@ -1786,6 +1786,7 @@ so we didn't send them an invitation. We did send invitations to everyone else!"self.user_profile.realm,"full name",prereg_user=prereg_user,+ acting_user=None,)accepted_invite = PreregistrationUser.objects.filter(diff --git a/zerver/tests/test_users.py b/zerver/tests/test_users.pyindex 589817a6afc..37282388d4c 100644--- a/zerver/tests/test_users.py+++ b/zerver/tests/test_users.py@@ -808,6 +808,7 @@ class QueryCountTest(ZulipTestCase):realm=realm,full_name="Fred Flintstone",prereg_user=prereg_user,+ acting_user=None,)self.assert_length(queries, 68)@@ -1658,6 +1659,7 @@ class RecipientInfoTest(ZulipTestCase):realm=realm,full_name="",bot_type=UserProfile.EMBEDDED_BOT,+ acting_user=None,)info = get_recipient_info(@@ -1680,6 +1682,7 @@ class RecipientInfoTest(ZulipTestCase):realm=realm,full_name="",bot_type=UserProfile.DEFAULT_BOT,+ acting_user=None,)info = get_recipient_info(