actions: Rename do_change_plan_type -> do change_realm_plan_type.

We will soon be adding an equivalent function for RemoteZulipServer,
so it makes sense to rename this function to be more descriptive.
This commit is contained in:
Eeshan Garg 2021-11-30 20:10:40 -05:00 committed by Tim Abbott
parent 42ecabe967
commit 2cdaae681d
12 changed files with 53 additions and 51 deletions

View File

@ -334,7 +334,7 @@ class TestSupportEndpoint(ZulipTestCase):
["Billing method of zulip updated to pay by invoice"], result ["Billing method of zulip updated to pay by invoice"], result
) )
def test_change_plan_type(self) -> None: def test_change_realm_plan_type(self) -> None:
cordelia = self.example_user("cordelia") cordelia = self.example_user("cordelia")
self.login_user(cordelia) self.login_user(cordelia)
@ -347,7 +347,7 @@ class TestSupportEndpoint(ZulipTestCase):
iago = self.example_user("iago") iago = self.example_user("iago")
self.login_user(iago) self.login_user(iago)
with mock.patch("analytics.views.support.do_change_plan_type") as m: with mock.patch("analytics.views.support.do_change_realm_plan_type") as m:
result = self.client_post( result = self.client_post(
"/activity/support", {"realm_id": f"{iago.realm_id}", "plan_type": "2"} "/activity/support", {"realm_id": f"{iago.realm_id}", "plan_type": "2"}
) )
@ -356,7 +356,7 @@ class TestSupportEndpoint(ZulipTestCase):
["Plan type of zulip changed from self hosted to limited"], result ["Plan type of zulip changed from self hosted to limited"], result
) )
with mock.patch("analytics.views.support.do_change_plan_type") as m: with mock.patch("analytics.views.support.do_change_realm_plan_type") as m:
result = self.client_post( result = self.client_post(
"/activity/support", {"realm_id": f"{iago.realm_id}", "plan_type": "10"} "/activity/support", {"realm_id": f"{iago.realm_id}", "plan_type": "10"}
) )

View File

@ -19,8 +19,8 @@ from confirmation.settings import STATUS_ACTIVE
from zerver.decorator import require_server_admin from zerver.decorator import require_server_admin
from zerver.forms import check_subdomain_available from zerver.forms import check_subdomain_available
from zerver.lib.actions import ( from zerver.lib.actions import (
do_change_plan_type,
do_change_realm_org_type, do_change_realm_org_type,
do_change_realm_plan_type,
do_change_realm_subdomain, do_change_realm_subdomain,
do_deactivate_realm, do_deactivate_realm,
do_scrub_realm, do_scrub_realm,
@ -169,7 +169,7 @@ def support(
assert isinstance(acting_user, UserProfile) assert isinstance(acting_user, UserProfile)
if plan_type is not None: if plan_type is not None:
current_plan_type = realm.plan_type current_plan_type = realm.plan_type
do_change_plan_type(realm, plan_type, acting_user=acting_user) do_change_realm_plan_type(realm, plan_type, acting_user=acting_user)
msg = f"Plan type of {realm.string_id} changed from {get_plan_name(current_plan_type)} to {get_plan_name(plan_type)} " msg = f"Plan type of {realm.string_id} changed from {get_plan_name(current_plan_type)} to {get_plan_name(plan_type)} "
context["success_message"] = msg context["success_message"] = msg
elif org_type is not None: elif org_type is not None:

View File

@ -714,9 +714,9 @@ def process_initial_upgrade(
) )
stripe.Invoice.finalize_invoice(stripe_invoice) stripe.Invoice.finalize_invoice(stripe_invoice)
from zerver.lib.actions import do_change_plan_type from zerver.lib.actions import do_change_realm_plan_type
do_change_plan_type(realm, Realm.PLAN_TYPE_STANDARD, acting_user=user) do_change_realm_plan_type(realm, Realm.PLAN_TYPE_STANDARD, acting_user=user)
def update_license_ledger_for_manual_plan( def update_license_ledger_for_manual_plan(
@ -937,9 +937,9 @@ def update_sponsorship_status(
def approve_sponsorship(realm: Realm, *, acting_user: Optional[UserProfile]) -> None: def approve_sponsorship(realm: Realm, *, acting_user: Optional[UserProfile]) -> None:
from zerver.lib.actions import do_change_plan_type, internal_send_private_message from zerver.lib.actions import do_change_realm_plan_type, internal_send_private_message
do_change_plan_type(realm, Realm.PLAN_TYPE_STANDARD_FREE, acting_user=acting_user) do_change_realm_plan_type(realm, Realm.PLAN_TYPE_STANDARD_FREE, acting_user=acting_user)
customer = get_customer_by_realm(realm) customer = get_customer_by_realm(realm)
if customer is not None and customer.sponsorship_pending: if customer is not None and customer.sponsorship_pending:
customer.sponsorship_pending = False customer.sponsorship_pending = False
@ -986,10 +986,10 @@ def do_change_plan_status(plan: CustomerPlan, status: int) -> None:
def process_downgrade(plan: CustomerPlan) -> None: def process_downgrade(plan: CustomerPlan) -> None:
from zerver.lib.actions import do_change_plan_type from zerver.lib.actions import do_change_realm_plan_type
assert plan.customer.realm is not None assert plan.customer.realm is not None
do_change_plan_type(plan.customer.realm, Realm.PLAN_TYPE_LIMITED, acting_user=None) do_change_realm_plan_type(plan.customer.realm, Realm.PLAN_TYPE_LIMITED, acting_user=None)
plan.status = CustomerPlan.ENDED plan.status = CustomerPlan.ENDED
plan.save(update_fields=["status"]) plan.save(update_fields=["status"])

View File

@ -4619,7 +4619,7 @@ def do_change_realm_org_type(
) )
def do_change_plan_type( def do_change_realm_plan_type(
realm: Realm, plan_type: int, *, acting_user: Optional[UserProfile] realm: Realm, plan_type: int, *, acting_user: Optional[UserProfile]
) -> None: ) -> None:
old_value = realm.plan_type old_value = realm.plan_type
@ -5148,7 +5148,7 @@ def do_create_realm(
realm.save(update_fields=["notifications_stream", "signup_notifications_stream"]) realm.save(update_fields=["notifications_stream", "signup_notifications_stream"])
if plan_type is None and settings.BILLING_ENABLED: if plan_type is None and settings.BILLING_ENABLED:
do_change_plan_type(realm, Realm.PLAN_TYPE_LIMITED, acting_user=None) do_change_realm_plan_type(realm, Realm.PLAN_TYPE_LIMITED, acting_user=None)
admin_realm = get_realm(settings.SYSTEM_BOT_REALM) admin_realm = get_realm(settings.SYSTEM_BOT_REALM)
sender = get_system_bot(settings.NOTIFICATION_BOT, admin_realm.id) sender = get_system_bot(settings.NOTIFICATION_BOT, admin_realm.id)

View File

@ -20,7 +20,7 @@ from zerver.lib.actions import (
UserMessageLite, UserMessageLite,
bulk_insert_ums, bulk_insert_ums,
do_change_avatar_fields, do_change_avatar_fields,
do_change_plan_type, do_change_realm_plan_type,
) )
from zerver.lib.avatar_hash import user_avatar_path_from_ids from zerver.lib.avatar_hash import user_avatar_path_from_ids
from zerver.lib.bulk_create import bulk_create_users, bulk_set_users_or_streams_recipient_fields from zerver.lib.bulk_create import bulk_create_users, bulk_set_users_or_streams_recipient_fields
@ -1286,9 +1286,9 @@ def do_import_realm(import_dir: Path, subdomain: str, processes: int = 1) -> Rea
import_analytics_data(realm=realm, import_dir=import_dir) import_analytics_data(realm=realm, import_dir=import_dir)
if settings.BILLING_ENABLED: if settings.BILLING_ENABLED:
do_change_plan_type(realm, Realm.PLAN_TYPE_LIMITED, acting_user=None) do_change_realm_plan_type(realm, Realm.PLAN_TYPE_LIMITED, acting_user=None)
else: else:
do_change_plan_type(realm, Realm.PLAN_TYPE_SELF_HOSTED, acting_user=None) do_change_realm_plan_type(realm, Realm.PLAN_TYPE_SELF_HOSTED, acting_user=None)
return realm return realm

View File

@ -39,8 +39,8 @@ from zerver.lib.actions import (
do_change_full_name, do_change_full_name,
do_change_icon_source, do_change_icon_source,
do_change_logo_source, do_change_logo_source,
do_change_plan_type,
do_change_realm_domain, do_change_realm_domain,
do_change_realm_plan_type,
do_change_stream_description, do_change_stream_description,
do_change_stream_message_retention_days, do_change_stream_message_retention_days,
do_change_stream_permission, do_change_stream_permission,
@ -1546,7 +1546,7 @@ class NormalActionsTest(BaseAction):
self.assertEqual(state_data["zulip_plan_is_not_limited"], True) self.assertEqual(state_data["zulip_plan_is_not_limited"], True)
events = self.verify_action( events = self.verify_action(
lambda: do_change_plan_type( lambda: do_change_realm_plan_type(
realm, Realm.PLAN_TYPE_LIMITED, acting_user=self.user_profile realm, Realm.PLAN_TYPE_LIMITED, acting_user=self.user_profile
) )
) )

View File

@ -13,7 +13,7 @@ from django.test import override_settings
from django.utils.timezone import now as timezone_now from django.utils.timezone import now as timezone_now
from corporate.models import Customer, CustomerPlan from corporate.models import Customer, CustomerPlan
from zerver.lib.actions import change_user_is_active, do_change_plan_type, do_create_user from zerver.lib.actions import change_user_is_active, do_change_realm_plan_type, do_create_user
from zerver.lib.compatibility import LAST_SERVER_UPGRADE_TIME, is_outdated_server from zerver.lib.compatibility import LAST_SERVER_UPGRADE_TIME, is_outdated_server
from zerver.lib.home import ( from zerver.lib.home import (
get_billing_info, get_billing_info,
@ -752,7 +752,7 @@ class HomeTest(ZulipTestCase):
self.assertFalse(billing_info.show_plans) self.assertFalse(billing_info.show_plans)
# realm owner, with inactive CustomerPlan and realm plan_type LIMITED -> show billing link and plans # realm owner, with inactive CustomerPlan and realm plan_type LIMITED -> show billing link and plans
do_change_plan_type(user.realm, Realm.PLAN_TYPE_LIMITED, acting_user=None) do_change_realm_plan_type(user.realm, Realm.PLAN_TYPE_LIMITED, acting_user=None)
with self.settings(CORPORATE_ENABLED=True): with self.settings(CORPORATE_ENABLED=True):
billing_info = get_billing_info(user) billing_info = get_billing_info(user)
self.assertTrue(billing_info.show_billing) self.assertTrue(billing_info.show_billing)
@ -781,7 +781,7 @@ class HomeTest(ZulipTestCase):
# billing admin, with CustomerPlan and realm plan_type STANDARD -> show only billing link # billing admin, with CustomerPlan and realm plan_type STANDARD -> show only billing link
user.role = UserProfile.ROLE_MEMBER user.role = UserProfile.ROLE_MEMBER
user.is_billing_admin = True user.is_billing_admin = True
do_change_plan_type(user.realm, Realm.PLAN_TYPE_STANDARD, acting_user=None) do_change_realm_plan_type(user.realm, Realm.PLAN_TYPE_STANDARD, acting_user=None)
user.save(update_fields=["role", "is_billing_admin"]) user.save(update_fields=["role", "is_billing_admin"])
with self.settings(CORPORATE_ENABLED=True): with self.settings(CORPORATE_ENABLED=True):
billing_info = get_billing_info(user) billing_info = get_billing_info(user)
@ -789,7 +789,7 @@ class HomeTest(ZulipTestCase):
self.assertFalse(billing_info.show_plans) self.assertFalse(billing_info.show_plans)
# billing admin, with CustomerPlan and realm plan_type PLUS -> show only billing link # billing admin, with CustomerPlan and realm plan_type PLUS -> show only billing link
do_change_plan_type(user.realm, Realm.PLAN_TYPE_PLUS, acting_user=None) do_change_realm_plan_type(user.realm, Realm.PLAN_TYPE_PLUS, acting_user=None)
user.save(update_fields=["role", "is_billing_admin"]) user.save(update_fields=["role", "is_billing_admin"])
with self.settings(CORPORATE_ENABLED=True): with self.settings(CORPORATE_ENABLED=True):
billing_info = get_billing_info(user) billing_info = get_billing_info(user)
@ -797,7 +797,7 @@ class HomeTest(ZulipTestCase):
self.assertFalse(billing_info.show_plans) self.assertFalse(billing_info.show_plans)
# member, with CustomerPlan and realm plan_type STANDARD -> neither billing link or plans # member, with CustomerPlan and realm plan_type STANDARD -> neither billing link or plans
do_change_plan_type(user.realm, Realm.PLAN_TYPE_STANDARD, acting_user=None) do_change_realm_plan_type(user.realm, Realm.PLAN_TYPE_STANDARD, acting_user=None)
user.is_billing_admin = False user.is_billing_admin = False
user.save(update_fields=["is_billing_admin"]) user.save(update_fields=["is_billing_admin"])
with self.settings(CORPORATE_ENABLED=True): with self.settings(CORPORATE_ENABLED=True):
@ -808,7 +808,7 @@ class HomeTest(ZulipTestCase):
# guest, with CustomerPlan and realm plan_type SELF_HOSTED -> neither billing link or plans # guest, with CustomerPlan and realm plan_type SELF_HOSTED -> neither billing link or plans
user.role = UserProfile.ROLE_GUEST user.role = UserProfile.ROLE_GUEST
user.save(update_fields=["role"]) user.save(update_fields=["role"])
do_change_plan_type(user.realm, Realm.PLAN_TYPE_SELF_HOSTED, acting_user=None) do_change_realm_plan_type(user.realm, Realm.PLAN_TYPE_SELF_HOSTED, acting_user=None)
with self.settings(CORPORATE_ENABLED=True): with self.settings(CORPORATE_ENABLED=True):
billing_info = get_billing_info(user) billing_info = get_billing_info(user)
self.assertFalse(billing_info.show_billing) self.assertFalse(billing_info.show_billing)
@ -842,7 +842,7 @@ class HomeTest(ZulipTestCase):
def test_promote_sponsoring_zulip_in_realm(self) -> None: def test_promote_sponsoring_zulip_in_realm(self) -> None:
realm = get_realm("zulip") realm = get_realm("zulip")
do_change_plan_type(realm, Realm.PLAN_TYPE_STANDARD_FREE, acting_user=None) do_change_realm_plan_type(realm, Realm.PLAN_TYPE_STANDARD_FREE, acting_user=None)
promote_zulip = promote_sponsoring_zulip_in_realm(realm) promote_zulip = promote_sponsoring_zulip_in_realm(realm)
self.assertTrue(promote_zulip) self.assertTrue(promote_zulip)
@ -850,15 +850,15 @@ class HomeTest(ZulipTestCase):
promote_zulip = promote_sponsoring_zulip_in_realm(realm) promote_zulip = promote_sponsoring_zulip_in_realm(realm)
self.assertFalse(promote_zulip) self.assertFalse(promote_zulip)
do_change_plan_type(realm, Realm.PLAN_TYPE_STANDARD_FREE, acting_user=None) do_change_realm_plan_type(realm, Realm.PLAN_TYPE_STANDARD_FREE, acting_user=None)
promote_zulip = promote_sponsoring_zulip_in_realm(realm) promote_zulip = promote_sponsoring_zulip_in_realm(realm)
self.assertTrue(promote_zulip) self.assertTrue(promote_zulip)
do_change_plan_type(realm, Realm.PLAN_TYPE_LIMITED, acting_user=None) do_change_realm_plan_type(realm, Realm.PLAN_TYPE_LIMITED, acting_user=None)
promote_zulip = promote_sponsoring_zulip_in_realm(realm) promote_zulip = promote_sponsoring_zulip_in_realm(realm)
self.assertFalse(promote_zulip) self.assertFalse(promote_zulip)
do_change_plan_type(realm, Realm.PLAN_TYPE_STANDARD, acting_user=None) do_change_realm_plan_type(realm, Realm.PLAN_TYPE_STANDARD, acting_user=None)
promote_zulip = promote_sponsoring_zulip_in_realm(realm) promote_zulip = promote_sponsoring_zulip_in_realm(realm)
self.assertFalse(promote_zulip) self.assertFalse(promote_zulip)

View File

@ -14,7 +14,7 @@ from zerver.lib.actions import (
do_add_reaction, do_add_reaction,
do_change_icon_source, do_change_icon_source,
do_change_logo_source, do_change_logo_source,
do_change_plan_type, do_change_realm_plan_type,
do_create_user, do_create_user,
do_deactivate_user, do_deactivate_user,
do_mute_user, do_mute_user,
@ -1313,7 +1313,7 @@ class ImportExportTest(ZulipTestCase):
def test_plan_type(self) -> None: def test_plan_type(self) -> None:
realm = get_realm("zulip") realm = get_realm("zulip")
do_change_plan_type(realm, Realm.PLAN_TYPE_LIMITED, acting_user=None) do_change_realm_plan_type(realm, Realm.PLAN_TYPE_LIMITED, acting_user=None)
self._setup_export_files(realm) self._setup_export_files(realm)
self._export_realm(realm) self._export_realm(realm)

View File

@ -9,7 +9,7 @@ from django.http import HttpResponse
from django.utils.timezone import now as timezone_now from django.utils.timezone import now as timezone_now
from zerver.lib.actions import ( from zerver.lib.actions import (
do_change_plan_type, do_change_realm_plan_type,
do_change_stream_post_policy, do_change_stream_post_policy,
do_change_user_role, do_change_user_role,
do_deactivate_stream, do_deactivate_stream,
@ -366,14 +366,16 @@ class EditMessageTest(EditMessageTestCase):
self.assertEqual(result.json()["raw_content"], "web-public message") self.assertEqual(result.json()["raw_content"], "web-public message")
# Verify LIMITED plan type does not allow web-public access. # Verify LIMITED plan type does not allow web-public access.
do_change_plan_type(user_profile.realm, Realm.PLAN_TYPE_LIMITED, acting_user=None) do_change_realm_plan_type(user_profile.realm, Realm.PLAN_TYPE_LIMITED, acting_user=None)
result = self.client_get("/json/messages/" + str(web_public_stream_msg_id)) result = self.client_get("/json/messages/" + str(web_public_stream_msg_id))
self.assert_json_error( self.assert_json_error(
result, "Not logged in: API authentication or user session required", 401 result, "Not logged in: API authentication or user session required", 401
) )
# Verify works with STANDARD_FREE plan type too. # Verify works with STANDARD_FREE plan type too.
do_change_plan_type(user_profile.realm, Realm.PLAN_TYPE_STANDARD_FREE, acting_user=None) do_change_realm_plan_type(
user_profile.realm, Realm.PLAN_TYPE_STANDARD_FREE, acting_user=None
)
result = self.client_get("/json/messages/" + str(web_public_stream_msg_id)) result = self.client_get("/json/messages/" + str(web_public_stream_msg_id))
self.assert_json_success(result) self.assert_json_success(result)
self.assertEqual(result.json()["raw_content"], "web-public message") self.assertEqual(result.json()["raw_content"], "web-public message")

View File

@ -10,8 +10,8 @@ from django.utils.timezone import now as timezone_now
from confirmation.models import Confirmation, create_confirmation_link from confirmation.models import Confirmation, create_confirmation_link
from zerver.lib.actions import ( from zerver.lib.actions import (
do_add_deactivated_redirect, do_add_deactivated_redirect,
do_change_plan_type,
do_change_realm_org_type, do_change_realm_org_type,
do_change_realm_plan_type,
do_change_realm_subdomain, do_change_realm_subdomain,
do_create_realm, do_create_realm,
do_deactivate_realm, do_deactivate_realm,
@ -671,7 +671,7 @@ class RealmTest(ZulipTestCase):
self.assertEqual(realm_audit_log.acting_user, iago) self.assertEqual(realm_audit_log.acting_user, iago)
self.assertEqual(realm.org_type, Realm.ORG_TYPES["government"]["id"]) self.assertEqual(realm.org_type, Realm.ORG_TYPES["government"]["id"])
def test_change_plan_type(self) -> None: def test_change_realm_plan_type(self) -> None:
realm = get_realm("zulip") realm = get_realm("zulip")
iago = self.example_user("iago") iago = self.example_user("iago")
self.assertEqual(realm.plan_type, Realm.PLAN_TYPE_SELF_HOSTED) self.assertEqual(realm.plan_type, Realm.PLAN_TYPE_SELF_HOSTED)
@ -679,7 +679,7 @@ class RealmTest(ZulipTestCase):
self.assertEqual(realm.message_visibility_limit, None) self.assertEqual(realm.message_visibility_limit, None)
self.assertEqual(realm.upload_quota_gb, None) self.assertEqual(realm.upload_quota_gb, None)
do_change_plan_type(realm, Realm.PLAN_TYPE_STANDARD, acting_user=iago) do_change_realm_plan_type(realm, Realm.PLAN_TYPE_STANDARD, acting_user=iago)
realm = get_realm("zulip") realm = get_realm("zulip")
realm_audit_log = RealmAuditLog.objects.filter( realm_audit_log = RealmAuditLog.objects.filter(
event_type=RealmAuditLog.REALM_PLAN_TYPE_CHANGED event_type=RealmAuditLog.REALM_PLAN_TYPE_CHANGED
@ -696,29 +696,29 @@ class RealmTest(ZulipTestCase):
self.assertEqual(realm.message_visibility_limit, None) self.assertEqual(realm.message_visibility_limit, None)
self.assertEqual(realm.upload_quota_gb, Realm.UPLOAD_QUOTA_STANDARD) self.assertEqual(realm.upload_quota_gb, Realm.UPLOAD_QUOTA_STANDARD)
do_change_plan_type(realm, Realm.PLAN_TYPE_LIMITED, acting_user=iago) do_change_realm_plan_type(realm, Realm.PLAN_TYPE_LIMITED, acting_user=iago)
realm = get_realm("zulip") realm = get_realm("zulip")
self.assertEqual(realm.plan_type, Realm.PLAN_TYPE_LIMITED) self.assertEqual(realm.plan_type, Realm.PLAN_TYPE_LIMITED)
self.assertEqual(realm.max_invites, settings.INVITES_DEFAULT_REALM_DAILY_MAX) self.assertEqual(realm.max_invites, settings.INVITES_DEFAULT_REALM_DAILY_MAX)
self.assertEqual(realm.message_visibility_limit, Realm.MESSAGE_VISIBILITY_LIMITED) self.assertEqual(realm.message_visibility_limit, Realm.MESSAGE_VISIBILITY_LIMITED)
self.assertEqual(realm.upload_quota_gb, Realm.UPLOAD_QUOTA_LIMITED) self.assertEqual(realm.upload_quota_gb, Realm.UPLOAD_QUOTA_LIMITED)
do_change_plan_type(realm, Realm.PLAN_TYPE_STANDARD_FREE, acting_user=iago) do_change_realm_plan_type(realm, Realm.PLAN_TYPE_STANDARD_FREE, acting_user=iago)
realm = get_realm("zulip") realm = get_realm("zulip")
self.assertEqual(realm.plan_type, Realm.PLAN_TYPE_STANDARD_FREE) self.assertEqual(realm.plan_type, Realm.PLAN_TYPE_STANDARD_FREE)
self.assertEqual(realm.max_invites, Realm.INVITES_STANDARD_REALM_DAILY_MAX) self.assertEqual(realm.max_invites, Realm.INVITES_STANDARD_REALM_DAILY_MAX)
self.assertEqual(realm.message_visibility_limit, None) self.assertEqual(realm.message_visibility_limit, None)
self.assertEqual(realm.upload_quota_gb, Realm.UPLOAD_QUOTA_STANDARD) self.assertEqual(realm.upload_quota_gb, Realm.UPLOAD_QUOTA_STANDARD)
do_change_plan_type(realm, Realm.PLAN_TYPE_LIMITED, acting_user=iago) do_change_realm_plan_type(realm, Realm.PLAN_TYPE_LIMITED, acting_user=iago)
do_change_plan_type(realm, Realm.PLAN_TYPE_PLUS, acting_user=iago) do_change_realm_plan_type(realm, Realm.PLAN_TYPE_PLUS, acting_user=iago)
realm = get_realm("zulip") realm = get_realm("zulip")
self.assertEqual(realm.plan_type, Realm.PLAN_TYPE_PLUS) self.assertEqual(realm.plan_type, Realm.PLAN_TYPE_PLUS)
self.assertEqual(realm.max_invites, Realm.INVITES_STANDARD_REALM_DAILY_MAX) self.assertEqual(realm.max_invites, Realm.INVITES_STANDARD_REALM_DAILY_MAX)
self.assertEqual(realm.message_visibility_limit, None) self.assertEqual(realm.message_visibility_limit, None)
self.assertEqual(realm.upload_quota_gb, Realm.UPLOAD_QUOTA_STANDARD) self.assertEqual(realm.upload_quota_gb, Realm.UPLOAD_QUOTA_STANDARD)
do_change_plan_type(realm, Realm.PLAN_TYPE_SELF_HOSTED, acting_user=iago) do_change_realm_plan_type(realm, Realm.PLAN_TYPE_SELF_HOSTED, acting_user=iago)
self.assertEqual(realm.plan_type, Realm.PLAN_TYPE_SELF_HOSTED) self.assertEqual(realm.plan_type, Realm.PLAN_TYPE_SELF_HOSTED)
self.assertEqual(realm.max_invites, settings.INVITES_DEFAULT_REALM_DAILY_MAX) self.assertEqual(realm.max_invites, settings.INVITES_DEFAULT_REALM_DAILY_MAX)
self.assertEqual(realm.message_visibility_limit, None) self.assertEqual(realm.message_visibility_limit, None)
@ -759,12 +759,12 @@ class RealmTest(ZulipTestCase):
result = self.client_patch("/json/realm", req) result = self.client_patch("/json/realm", req)
self.assert_json_success(result) self.assert_json_success(result)
do_change_plan_type(realm, Realm.PLAN_TYPE_LIMITED, acting_user=None) do_change_realm_plan_type(realm, Realm.PLAN_TYPE_LIMITED, acting_user=None)
req = dict(message_retention_days=orjson.dumps(10).decode()) req = dict(message_retention_days=orjson.dumps(10).decode())
result = self.client_patch("/json/realm", req) result = self.client_patch("/json/realm", req)
self.assert_json_error(result, "Available on Zulip Standard. Upgrade to access.") self.assert_json_error(result, "Available on Zulip Standard. Upgrade to access.")
do_change_plan_type(realm, Realm.PLAN_TYPE_STANDARD, acting_user=None) do_change_realm_plan_type(realm, Realm.PLAN_TYPE_STANDARD, acting_user=None)
req = dict(message_retention_days=orjson.dumps(10).decode()) req = dict(message_retention_days=orjson.dumps(10).decode())
result = self.client_patch("/json/realm", req) result = self.client_patch("/json/realm", req)
self.assert_json_success(result) self.assert_json_success(result)

View File

@ -18,7 +18,7 @@ from zerver.lib.actions import (
do_add_streams_to_default_stream_group, do_add_streams_to_default_stream_group,
do_change_default_stream_group_description, do_change_default_stream_group_description,
do_change_default_stream_group_name, do_change_default_stream_group_name,
do_change_plan_type, do_change_realm_plan_type,
do_change_stream_post_policy, do_change_stream_post_policy,
do_change_subscription_property, do_change_subscription_property,
do_change_user_role, do_change_user_role,
@ -1276,7 +1276,7 @@ class StreamAdminTest(ZulipTestCase):
user_profile = self.example_user("desdemona") user_profile = self.example_user("desdemona")
self.login_user(user_profile) self.login_user(user_profile)
realm = user_profile.realm realm = user_profile.realm
do_change_plan_type(realm, Realm.PLAN_TYPE_LIMITED, acting_user=None) do_change_realm_plan_type(realm, Realm.PLAN_TYPE_LIMITED, acting_user=None)
stream = self.subscribe(user_profile, "stream_name1") stream = self.subscribe(user_profile, "stream_name1")
result = self.client_patch( result = self.client_patch(
@ -1284,7 +1284,7 @@ class StreamAdminTest(ZulipTestCase):
) )
self.assert_json_error(result, "Available on Zulip Standard. Upgrade to access.") self.assert_json_error(result, "Available on Zulip Standard. Upgrade to access.")
do_change_plan_type(realm, Realm.PLAN_TYPE_SELF_HOSTED, acting_user=None) do_change_realm_plan_type(realm, Realm.PLAN_TYPE_SELF_HOSTED, acting_user=None)
events: List[Mapping[str, Any]] = [] events: List[Mapping[str, Any]] = []
with self.tornado_redirected_to_list(events, expected_num_events=1): with self.tornado_redirected_to_list(events, expected_num_events=1):
result = self.client_patch( result = self.client_patch(
@ -1450,13 +1450,13 @@ class StreamAdminTest(ZulipTestCase):
}, },
] ]
do_change_plan_type(realm, Realm.PLAN_TYPE_LIMITED, acting_user=admin) do_change_realm_plan_type(realm, Realm.PLAN_TYPE_LIMITED, acting_user=admin)
with self.assertRaisesRegex( with self.assertRaisesRegex(
JsonableError, "Available on Zulip Standard. Upgrade to access." JsonableError, "Available on Zulip Standard. Upgrade to access."
): ):
list_to_streams(streams_raw, owner, autocreate=True) list_to_streams(streams_raw, owner, autocreate=True)
do_change_plan_type(realm, Realm.PLAN_TYPE_SELF_HOSTED, acting_user=admin) do_change_realm_plan_type(realm, Realm.PLAN_TYPE_SELF_HOSTED, acting_user=admin)
result = list_to_streams(streams_raw, owner, autocreate=True) result = list_to_streams(streams_raw, owner, autocreate=True)
self.assert_length(result[0], 0) self.assert_length(result[0], 0)
self.assert_length(result[1], 3) self.assert_length(result[1], 3)

View File

@ -21,7 +21,7 @@ import zerver.lib.upload
from zerver.lib.actions import ( from zerver.lib.actions import (
do_change_icon_source, do_change_icon_source,
do_change_logo_source, do_change_logo_source,
do_change_plan_type, do_change_realm_plan_type,
do_create_realm, do_create_realm,
do_delete_old_unclaimed_attachments, do_delete_old_unclaimed_attachments,
do_set_realm_property, do_set_realm_property,
@ -1544,7 +1544,7 @@ class RealmLogoTest(UploadSerializeMixin, ZulipTestCase):
def test_upload_limited_plan_type(self) -> None: def test_upload_limited_plan_type(self) -> None:
user_profile = self.example_user("iago") user_profile = self.example_user("iago")
do_change_plan_type(user_profile.realm, Realm.PLAN_TYPE_LIMITED, acting_user=None) do_change_realm_plan_type(user_profile.realm, Realm.PLAN_TYPE_LIMITED, acting_user=None)
self.login_user(user_profile) self.login_user(user_profile)
with get_test_image_file(self.correct_files[0][0]) as fp: with get_test_image_file(self.correct_files[0][0]) as fp:
result = self.client_post( result = self.client_post(
@ -1588,7 +1588,7 @@ class RealmLogoTest(UploadSerializeMixin, ZulipTestCase):
f"/user_avatars/{realm.id}/realm/{file_name}?version=2&night={is_night_str}", f"/user_avatars/{realm.id}/realm/{file_name}?version=2&night={is_night_str}",
) )
do_change_plan_type(realm, Realm.PLAN_TYPE_LIMITED, acting_user=user_profile) do_change_realm_plan_type(realm, Realm.PLAN_TYPE_LIMITED, acting_user=user_profile)
if self.night: if self.night:
self.assertEqual(realm.night_logo_source, Realm.LOGO_UPLOADED) self.assertEqual(realm.night_logo_source, Realm.LOGO_UPLOADED)
else: else: