mirror of https://github.com/zulip/zulip.git
tests: Create default RemoteRealms in populate_db.
This default setup will be more realistic, matching the ordinary conditions for a modern server. Especially needed as we add bouncer code that will expect to have RemoteRealm entries for realm_uuid values for which it receives requests.
This commit is contained in:
parent
a67dd6dc1f
commit
c9b0602320
|
@ -116,6 +116,10 @@ class AnalyticsTestCase(ZulipTestCase):
|
||||||
# used as defaults in self.assert_table_count
|
# used as defaults in self.assert_table_count
|
||||||
self.current_property: Optional[str] = None
|
self.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 messages
|
# Lightweight creation of users, streams, and messages
|
||||||
def create_user(self, **kwargs: Any) -> UserProfile:
|
def create_user(self, **kwargs: Any) -> UserProfile:
|
||||||
self.name_counter += 1
|
self.name_counter += 1
|
||||||
|
|
|
@ -90,6 +90,8 @@ class RemoteBillingAuthenticationTest(BouncerTestCase):
|
||||||
|
|
||||||
@responses.activate
|
@responses.activate
|
||||||
def test_remote_billing_authentication_flow_realm_not_registered(self) -> None:
|
def test_remote_billing_authentication_flow_realm_not_registered(self) -> None:
|
||||||
|
RemoteRealm.objects.all().delete()
|
||||||
|
|
||||||
self.login("desdemona")
|
self.login("desdemona")
|
||||||
desdemona = self.example_user("desdemona")
|
desdemona = self.example_user("desdemona")
|
||||||
realm = desdemona.realm
|
realm = desdemona.realm
|
||||||
|
|
|
@ -52,7 +52,6 @@ not_yet_fully_covered = [
|
||||||
"analytics/views/activity_common.py",
|
"analytics/views/activity_common.py",
|
||||||
"analytics/views/installation_activity.py",
|
"analytics/views/installation_activity.py",
|
||||||
"analytics/views/realm_activity.py",
|
"analytics/views/realm_activity.py",
|
||||||
"analytics/views/remote_activity.py",
|
|
||||||
"analytics/views/stats.py",
|
"analytics/views/stats.py",
|
||||||
"analytics/views/support.py",
|
"analytics/views/support.py",
|
||||||
# TODO: This is a work in progress and therefore without
|
# TODO: This is a work in progress and therefore without
|
||||||
|
|
|
@ -2385,14 +2385,13 @@ def get_topic_messages(user_profile: UserProfile, stream: Stream, topic_name: st
|
||||||
class BouncerTestCase(ZulipTestCase):
|
class BouncerTestCase(ZulipTestCase):
|
||||||
@override
|
@override
|
||||||
def setUp(self) -> None:
|
def setUp(self) -> None:
|
||||||
|
# Set a deterministic uuid for convenience.
|
||||||
self.server_uuid = "6cde5f7a-1f7e-4978-9716-49f69ebfc9fe"
|
self.server_uuid = "6cde5f7a-1f7e-4978-9716-49f69ebfc9fe"
|
||||||
self.server = RemoteZulipServer(
|
self.server = RemoteZulipServer.objects.all().latest("id")
|
||||||
uuid=self.server_uuid,
|
|
||||||
api_key="magic_secret_api_key",
|
self.server.uuid = self.server_uuid
|
||||||
hostname="demo.example.com",
|
|
||||||
last_updated=timezone_now(),
|
|
||||||
)
|
|
||||||
self.server.save()
|
self.server.save()
|
||||||
|
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -1287,6 +1287,9 @@ class AnalyticsBouncerTest(BouncerTestCase):
|
||||||
handling for this edge case nonetheless.
|
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(
|
second_server = RemoteZulipServer.objects.create(
|
||||||
uuid=uuid.uuid4(),
|
uuid=uuid.uuid4(),
|
||||||
api_key="magic_secret_api_key2",
|
api_key="magic_secret_api_key2",
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import itertools
|
import itertools
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
|
import uuid
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from typing import Any, Dict, List, Mapping, Sequence, Tuple
|
from typing import Any, Dict, List, Mapping, Sequence, Tuple
|
||||||
|
@ -37,6 +38,7 @@ from zerver.lib.bulk_create import bulk_create_streams
|
||||||
from zerver.lib.generate_test_data import create_test_data, generate_topics
|
from zerver.lib.generate_test_data import create_test_data, generate_topics
|
||||||
from zerver.lib.onboarding import create_if_missing_realm_internal_bots
|
from zerver.lib.onboarding import create_if_missing_realm_internal_bots
|
||||||
from zerver.lib.push_notifications import logger as push_notifications_logger
|
from zerver.lib.push_notifications import logger as push_notifications_logger
|
||||||
|
from zerver.lib.remote_server import get_realms_info_for_push_bouncer
|
||||||
from zerver.lib.server_initialization import create_internal_realm, create_users
|
from zerver.lib.server_initialization import create_internal_realm, create_users
|
||||||
from zerver.lib.storage import static_path
|
from zerver.lib.storage import static_path
|
||||||
from zerver.lib.stream_color import STREAM_ASSIGNMENT_COLORS
|
from zerver.lib.stream_color import STREAM_ASSIGNMENT_COLORS
|
||||||
|
@ -72,6 +74,8 @@ from zerver.models import (
|
||||||
get_user_by_delivery_email,
|
get_user_by_delivery_email,
|
||||||
get_user_profile_by_id,
|
get_user_profile_by_id,
|
||||||
)
|
)
|
||||||
|
from zilencer.models import RemoteZulipServer
|
||||||
|
from zilencer.views import update_remote_realm_data_for_server
|
||||||
|
|
||||||
settings.USING_TORNADO = False
|
settings.USING_TORNADO = False
|
||||||
# Disable using memcached caches to avoid 'unsupported pickle
|
# Disable using memcached caches to avoid 'unsupported pickle
|
||||||
|
@ -373,6 +377,18 @@ class Command(BaseCommand):
|
||||||
zulip_realm.wildcard_mention_policy = Realm.WILDCARD_MENTION_POLICY_MEMBERS
|
zulip_realm.wildcard_mention_policy = Realm.WILDCARD_MENTION_POLICY_MEMBERS
|
||||||
zulip_realm.save(update_fields=["wildcard_mention_policy"])
|
zulip_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,
|
# Create test Users (UserProfiles are automatically created,
|
||||||
# as are subscriptions to the ability to receive personals).
|
# as are subscriptions to the ability to receive personals).
|
||||||
names = [
|
names = [
|
||||||
|
|
Loading…
Reference in New Issue