tests: Use function to create realm rather than django ORM.

This commit makes changes in backend tests to use
`do_create_realm` function to create realm.
This commit is contained in:
Ujjawal Modi 2023-07-06 17:57:14 +05:30 committed by Tim Abbott
parent 72b099524d
commit 2e59b1f30e
2 changed files with 7 additions and 4 deletions

View File

@ -3650,7 +3650,11 @@ class StripeTest(StripeTestCase):
num_invoices: Optional[int] = None, num_invoices: Optional[int] = None,
) -> Tuple[Realm, Optional[Customer], Optional[CustomerPlan], List[stripe.Invoice]]: ) -> Tuple[Realm, Optional[Customer], Optional[CustomerPlan], List[stripe.Invoice]]:
realm_string_id = "realm_" + str(random.randrange(1, 1000000)) realm_string_id = "realm_" + str(random.randrange(1, 1000000))
realm = Realm.objects.create(string_id=realm_string_id) realm = do_create_realm(
string_id=realm_string_id,
name=realm_string_id,
plan_type=Realm.PLAN_TYPE_SELF_HOSTED,
)
users = [] users = []
for i in range(users_to_create): for i in range(users_to_create):
user = UserProfile.objects.create( user = UserProfile.objects.create(

View File

@ -11,6 +11,7 @@ from zerver.actions.bots import (
do_change_default_events_register_stream, do_change_default_events_register_stream,
do_change_default_sending_stream, do_change_default_sending_stream,
) )
from zerver.actions.create_realm import do_create_realm
from zerver.actions.create_user import ( from zerver.actions.create_user import (
do_activate_mirror_dummy_user, do_activate_mirror_dummy_user,
do_create_user, do_create_user,
@ -70,7 +71,6 @@ from zerver.lib.streams import create_stream_if_needed
from zerver.lib.test_classes import ZulipTestCase from zerver.lib.test_classes import ZulipTestCase
from zerver.lib.test_helpers import get_test_image_file from zerver.lib.test_helpers import get_test_image_file
from zerver.lib.types import LinkifierDict, RealmPlaygroundDict from zerver.lib.types import LinkifierDict, RealmPlaygroundDict
from zerver.lib.user_groups import create_system_user_groups_for_realm
from zerver.lib.utils import assert_is_not_none from zerver.lib.utils import assert_is_not_none
from zerver.models import ( from zerver.models import (
EmojiInfo, EmojiInfo,
@ -1058,9 +1058,8 @@ class TestRealmAuditLog(ZulipTestCase):
) )
def test_system_user_groups_creation(self) -> None: def test_system_user_groups_creation(self) -> None:
realm = Realm.objects.create(string_id="test", name="foo")
now = timezone_now() now = timezone_now()
create_system_user_groups_for_realm(realm) realm = do_create_realm(string_id="test", name="foo")
# The expected number of system user group is the total number of roles # The expected number of system user group is the total number of roles
# from UserGroup.SYSTEM_USER_GROUP_ROLE_MAP in addition to # from UserGroup.SYSTEM_USER_GROUP_ROLE_MAP in addition to