Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
tests: Create default RemoteRealms in populate_db.
Mateusz Manderac9b060232005
diff --git a/analytics/tests/test_counts.py b/analytics/tests/test_counts.pyindex a1fcde8255b..2a947a32d8a 100644--- a/analytics/tests/test_counts.py+++ b/analytics/tests/test_counts.py@@ -116,6 +116,10 @@ class AnalyticsTestCase(ZulipTestCase):# used as defaults in self.assert_table_countself.current_property: Optional[str] = None+ # Delete RemoteRealm registrations to have a clean slate - the relevant+ # tests want to construct this from scratch.+ RemoteRealm.objects.all().delete()+# Lightweight creation of users, streams, and messagesdef create_user(self, **kwargs: Any) -> UserProfile:self.name_counter += 1diff --git a/corporate/tests/test_remote_billing.py b/corporate/tests/test_remote_billing.pyindex ec7e7c18c92..7c6e18c2cee 100644--- a/corporate/tests/test_remote_billing.py+++ b/corporate/tests/test_remote_billing.py@@ -90,6 +90,8 @@ class RemoteBillingAuthenticationTest(BouncerTestCase):@responses.activatedef test_remote_billing_authentication_flow_realm_not_registered(self) -> None:+ RemoteRealm.objects.all().delete()+self.login("desdemona")desdemona = self.example_user("desdemona")realm = desdemona.realmdiff --git a/tools/test-backend b/tools/test-backendindex e802f631c44..20537efadc3 100755--- a/tools/test-backend+++ b/tools/test-backend@@ -52,7 +52,6 @@ not_yet_fully_covered = ["analytics/views/activity_common.py","analytics/views/installation_activity.py","analytics/views/realm_activity.py",- "analytics/views/remote_activity.py","analytics/views/stats.py","analytics/views/support.py",# TODO: This is a work in progress and therefore withoutdiff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.pyindex bb585114198..77479fbe529 100644--- a/zerver/lib/test_classes.py+++ b/zerver/lib/test_classes.py@@ -2385,14 +2385,13 @@ def get_topic_messages(user_profile: UserProfile, stream: Stream, topic_name: stclass BouncerTestCase(ZulipTestCase):@overridedef setUp(self) -> None:+ # Set a deterministic uuid for convenience.self.server_uuid = "6cde5f7a-1f7e-4978-9716-49f69ebfc9fe"- self.server = RemoteZulipServer(- uuid=self.server_uuid,- api_key="magic_secret_api_key",- hostname="demo.example.com",- last_updated=timezone_now(),- )+ self.server = RemoteZulipServer.objects.all().latest("id")++ self.server.uuid = self.server_uuidself.server.save()+super().setUp()@overridediff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.pyindex 0ff62818520..7703117873f 100644--- a/zerver/tests/test_push_notifications.py+++ b/zerver/tests/test_push_notifications.py@@ -1287,6 +1287,9 @@ class AnalyticsBouncerTest(BouncerTestCase):handling for this edge case nonetheless."""+ # Start by deleting existing registration, to have a clean slate.+ RemoteRealm.objects.all().delete()+second_server = RemoteZulipServer.objects.create(uuid=uuid.uuid4(),api_key="magic_secret_api_key2",diff --git a/zilencer/management/commands/populate_db.py b/zilencer/management/commands/populate_db.pyindex 227c6dba114..b4b713a45f2 100644--- a/zilencer/management/commands/populate_db.py+++ b/zilencer/management/commands/populate_db.py@@ -1,6 +1,7 @@import itertoolsimport osimport random+import uuidfrom collections import defaultdictfrom datetime import datetime, timedeltafrom typing import Any, Dict, List, Mapping, Sequence, Tuple@@ -37,6 +38,7 @@ from zerver.lib.bulk_create import bulk_create_streamsfrom zerver.lib.generate_test_data import create_test_data, generate_topicsfrom zerver.lib.onboarding import create_if_missing_realm_internal_botsfrom zerver.lib.push_notifications import logger as push_notifications_logger+from zerver.lib.remote_server import get_realms_info_for_push_bouncerfrom zerver.lib.server_initialization import create_internal_realm, create_usersfrom zerver.lib.storage import static_pathfrom zerver.lib.stream_color import STREAM_ASSIGNMENT_COLORS@@ -72,6 +74,8 @@ from zerver.models import (get_user_by_delivery_email,get_user_profile_by_id,)+from zilencer.models import RemoteZulipServer+from zilencer.views import update_remote_realm_data_for_serversettings.USING_TORNADO = False# Disable using memcached caches to avoid 'unsupported pickle@@ -373,6 +377,18 @@ class Command(BaseCommand):zulip_realm.wildcard_mention_policy = Realm.WILDCARD_MENTION_POLICY_MEMBERSzulip_realm.save(update_fields=["wildcard_mention_policy"])+ # Realms should have matching RemoteRealm entries - simulating having realms registered+ # with the bouncer, which is going to be the primary case for modern servers. Tests+ # wanting to have missing registrations, or simulating legacy server scenarios,+ # should delete RemoteRealms to explicit set things up.+ server = RemoteZulipServer.objects.create(+ uuid=uuid.uuid4(),+ api_key="magic_secret_api_key",+ hostname="demo.example.com",+ last_updated=timezone_now(),+ )+ update_remote_realm_data_for_server(server, get_realms_info_for_push_bouncer())+# Create test Users (UserProfiles are automatically created,# as are subscriptions to the ability to receive personals).names = [