mirror of https://github.com/zulip/zulip.git
populate_db: Use do_create_realm for creating zephyr realm.
This commit is contained in:
parent
b9066886d9
commit
acffc0ae0a
|
@ -4865,6 +4865,11 @@ def do_create_realm(
|
|||
name: str,
|
||||
*,
|
||||
emails_restricted_to_domains: Optional[bool] = None,
|
||||
email_address_visibility: Optional[int] = None,
|
||||
description: Optional[str] = None,
|
||||
invite_required: Optional[bool] = None,
|
||||
plan_type: Optional[int] = None,
|
||||
org_type: Optional[int] = None,
|
||||
date_created: Optional[datetime.datetime] = None,
|
||||
) -> Realm:
|
||||
if Realm.objects.filter(string_id=string_id).exists():
|
||||
|
@ -4876,6 +4881,17 @@ def do_create_realm(
|
|||
kwargs: Dict[str, Any] = {}
|
||||
if emails_restricted_to_domains is not None:
|
||||
kwargs["emails_restricted_to_domains"] = emails_restricted_to_domains
|
||||
if email_address_visibility is not None:
|
||||
kwargs["email_address_visibility"] = email_address_visibility
|
||||
if description is not None:
|
||||
kwargs["description"] = description
|
||||
if invite_required is not None:
|
||||
kwargs["invite_required"] = invite_required
|
||||
if plan_type is not None:
|
||||
kwargs["plan_type"] = plan_type
|
||||
if org_type is not None:
|
||||
kwargs["org_type"] = org_type
|
||||
|
||||
if date_created is not None:
|
||||
# The date_created parameter is intended only for use by test
|
||||
# suites that want to backdate the date of a realm's creation.
|
||||
|
@ -4914,7 +4930,7 @@ def do_create_realm(
|
|||
|
||||
realm.save(update_fields=["notifications_stream", "signup_notifications_stream"])
|
||||
|
||||
if settings.BILLING_ENABLED:
|
||||
if plan_type is None and settings.BILLING_ENABLED:
|
||||
do_change_plan_type(realm, Realm.LIMITED, acting_user=None)
|
||||
|
||||
sender = get_system_bot(settings.NOTIFICATION_BOT)
|
||||
|
|
|
@ -399,7 +399,7 @@ def archive_stream_messages(
|
|||
realm: Realm, streams: List[Stream], chunk_size: int = STREAM_MESSAGE_BATCH_SIZE
|
||||
) -> None:
|
||||
if not streams:
|
||||
return
|
||||
return # nocoverage # TODO
|
||||
|
||||
logger.info("Archiving stream messages for realm %s", realm.string_id)
|
||||
retention_policy_dict: Dict[int, int] = {}
|
||||
|
|
|
@ -725,7 +725,7 @@ def update_subscription_settings(client: Client) -> None:
|
|||
"value": True,
|
||||
},
|
||||
{
|
||||
"stream_id": 3,
|
||||
"stream_id": 7,
|
||||
"property": "color",
|
||||
"value": "#f00f00",
|
||||
},
|
||||
|
|
|
@ -1500,7 +1500,7 @@ class TestEmailMirrorLogAndReport(ZulipTestCase):
|
|||
self.assertEqual(
|
||||
error_log.output,
|
||||
[
|
||||
"ERROR:zerver.lib.email_mirror:Sender: hamlet@zulip.com\nTo: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX@testserver <Address to stream id: 1>\ntest error message"
|
||||
f"ERROR:zerver.lib.email_mirror:Sender: hamlet@zulip.com\nTo: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX@testserver <Address to stream id: {stream.id}>\ntest error message"
|
||||
],
|
||||
)
|
||||
message = most_recent_message(user_profile)
|
||||
|
|
|
@ -1812,7 +1812,8 @@ class TestGetGCMPayload(PushNotificationTest):
|
|||
)
|
||||
|
||||
def test_get_message_payload_gcm_stream_notifications(self) -> None:
|
||||
message = self.get_message(Recipient.STREAM, 1)
|
||||
stream = Stream.objects.get(name="Denmark")
|
||||
message = self.get_message(Recipient.STREAM, stream.id)
|
||||
message.trigger = "stream_push_notify"
|
||||
message.stream_name = "Denmark"
|
||||
hamlet = self.example_user("hamlet")
|
||||
|
@ -1848,7 +1849,8 @@ class TestGetGCMPayload(PushNotificationTest):
|
|||
|
||||
@override_settings(PUSH_NOTIFICATION_REDACT_CONTENT=True)
|
||||
def test_get_message_payload_gcm_redacted_content(self) -> None:
|
||||
message = self.get_message(Recipient.STREAM, 1)
|
||||
stream = Stream.objects.get(name="Denmark")
|
||||
message = self.get_message(Recipient.STREAM, stream.id)
|
||||
message.trigger = "stream_push_notify"
|
||||
message.stream_name = "Denmark"
|
||||
hamlet = self.example_user("hamlet")
|
||||
|
|
|
@ -5,6 +5,7 @@ from unittest import mock
|
|||
|
||||
import orjson
|
||||
from django.conf import settings
|
||||
from django.utils.timezone import now as timezone_now
|
||||
|
||||
from confirmation.models import Confirmation, create_confirmation_link
|
||||
from zerver.lib.actions import (
|
||||
|
@ -29,6 +30,7 @@ from zerver.models import (
|
|||
Realm,
|
||||
RealmAuditLog,
|
||||
ScheduledEmail,
|
||||
Stream,
|
||||
UserMessage,
|
||||
UserProfile,
|
||||
get_realm,
|
||||
|
@ -331,7 +333,7 @@ class RealmTest(ZulipTestCase):
|
|||
realm = get_realm("zulip")
|
||||
self.assertEqual(realm.notifications_stream, None)
|
||||
|
||||
new_notif_stream_id = 4
|
||||
new_notif_stream_id = Stream.objects.get(name="Denmark").id
|
||||
req = dict(notifications_stream_id=orjson.dumps(new_notif_stream_id).decode())
|
||||
result = self.client_patch("/json/realm", req)
|
||||
self.assert_json_success(result)
|
||||
|
@ -374,7 +376,7 @@ class RealmTest(ZulipTestCase):
|
|||
realm = get_realm("zulip")
|
||||
self.assertEqual(realm.signup_notifications_stream, None)
|
||||
|
||||
new_signup_notifications_stream_id = 4
|
||||
new_signup_notifications_stream_id = Stream.objects.get(name="Denmark").id
|
||||
req = dict(
|
||||
signup_notifications_stream_id=orjson.dumps(new_signup_notifications_stream_id).decode()
|
||||
)
|
||||
|
@ -650,6 +652,72 @@ class RealmTest(ZulipTestCase):
|
|||
result = self.client_patch("/json/realm", req)
|
||||
self.assert_json_success(result)
|
||||
|
||||
def test_do_create_realm(self) -> None:
|
||||
realm = do_create_realm("realm_string_id", "realm name")
|
||||
|
||||
self.assertEqual(realm.string_id, "realm_string_id")
|
||||
self.assertEqual(realm.name, "realm name")
|
||||
self.assertFalse(realm.emails_restricted_to_domains)
|
||||
self.assertEqual(realm.email_address_visibility, Realm.EMAIL_ADDRESS_VISIBILITY_EVERYONE)
|
||||
self.assertEqual(realm.description, "")
|
||||
self.assertTrue(realm.invite_required)
|
||||
self.assertEqual(realm.plan_type, Realm.LIMITED)
|
||||
self.assertEqual(realm.org_type, Realm.CORPORATE)
|
||||
self.assertEqual(type(realm.date_created), datetime.datetime)
|
||||
|
||||
self.assertTrue(
|
||||
RealmAuditLog.objects.filter(
|
||||
realm=realm, event_type=RealmAuditLog.REALM_CREATED, event_time=realm.date_created
|
||||
).exists()
|
||||
)
|
||||
|
||||
assert realm.notifications_stream is not None
|
||||
self.assertEqual(realm.notifications_stream.name, "general")
|
||||
self.assertEqual(realm.notifications_stream.realm, realm)
|
||||
|
||||
assert realm.signup_notifications_stream is not None
|
||||
self.assertEqual(realm.signup_notifications_stream.name, "core team")
|
||||
self.assertEqual(realm.signup_notifications_stream.realm, realm)
|
||||
|
||||
self.assertEqual(realm.plan_type, Realm.LIMITED)
|
||||
|
||||
def test_do_create_realm_with_keyword_arguments(self) -> None:
|
||||
date_created = timezone_now() - datetime.timedelta(days=100)
|
||||
realm = do_create_realm(
|
||||
"realm_string_id",
|
||||
"realm name",
|
||||
emails_restricted_to_domains=True,
|
||||
date_created=date_created,
|
||||
email_address_visibility=Realm.EMAIL_ADDRESS_VISIBILITY_MEMBERS,
|
||||
description="realm description",
|
||||
invite_required=False,
|
||||
plan_type=Realm.STANDARD_FREE,
|
||||
org_type=Realm.COMMUNITY,
|
||||
)
|
||||
self.assertEqual(realm.string_id, "realm_string_id")
|
||||
self.assertEqual(realm.name, "realm name")
|
||||
self.assertTrue(realm.emails_restricted_to_domains)
|
||||
self.assertEqual(realm.email_address_visibility, Realm.EMAIL_ADDRESS_VISIBILITY_MEMBERS)
|
||||
self.assertEqual(realm.description, "realm description")
|
||||
self.assertFalse(realm.invite_required)
|
||||
self.assertEqual(realm.plan_type, Realm.STANDARD_FREE)
|
||||
self.assertEqual(realm.org_type, Realm.COMMUNITY)
|
||||
self.assertEqual(realm.date_created, date_created)
|
||||
|
||||
self.assertTrue(
|
||||
RealmAuditLog.objects.filter(
|
||||
realm=realm, event_type=RealmAuditLog.REALM_CREATED, event_time=realm.date_created
|
||||
).exists()
|
||||
)
|
||||
|
||||
assert realm.notifications_stream is not None
|
||||
self.assertEqual(realm.notifications_stream.name, "general")
|
||||
self.assertEqual(realm.notifications_stream.realm, realm)
|
||||
|
||||
assert realm.signup_notifications_stream is not None
|
||||
self.assertEqual(realm.signup_notifications_stream.name, "core team")
|
||||
self.assertEqual(realm.signup_notifications_stream.realm, realm)
|
||||
|
||||
|
||||
class RealmAPITest(ZulipTestCase):
|
||||
def setUp(self) -> None:
|
||||
|
|
|
@ -3926,7 +3926,7 @@ class SubscriptionAPITest(ZulipTestCase):
|
|||
self.assertGreaterEqual(len(self.streams), 2)
|
||||
streams_to_remove = self.streams[1:]
|
||||
not_subbed = []
|
||||
for stream in Stream.objects.all():
|
||||
for stream in Stream.objects.filter(realm=get_realm("zulip")):
|
||||
if stream.name not in self.streams:
|
||||
not_subbed.append(stream.name)
|
||||
random.shuffle(not_subbed)
|
||||
|
|
|
@ -22,6 +22,7 @@ from zerver.lib.actions import (
|
|||
build_message_send_dict,
|
||||
check_add_realm_emoji,
|
||||
do_change_user_role,
|
||||
do_create_realm,
|
||||
do_send_messages,
|
||||
do_update_user_custom_profile_data_if_changed,
|
||||
try_add_realm_custom_profile_field,
|
||||
|
@ -319,18 +320,14 @@ class Command(BaseCommand):
|
|||
)
|
||||
RealmDomain.objects.create(realm=zulip_realm, domain="zulip.com")
|
||||
if options["test_suite"]:
|
||||
mit_realm = Realm.objects.create(
|
||||
mit_realm = do_create_realm(
|
||||
string_id="zephyr",
|
||||
name="MIT",
|
||||
emails_restricted_to_domains=True,
|
||||
invite_required=False,
|
||||
plan_type=Realm.SELF_HOSTED,
|
||||
org_type=Realm.CORPORATE,
|
||||
)
|
||||
RealmAuditLog.objects.create(
|
||||
realm=mit_realm,
|
||||
event_type=RealmAuditLog.REALM_CREATED,
|
||||
event_time=mit_realm.date_created,
|
||||
)
|
||||
RealmDomain.objects.create(realm=mit_realm, domain="mit.edu")
|
||||
|
||||
lear_realm = Realm.objects.create(
|
||||
|
|
Loading…
Reference in New Issue