populate_db: Create RemoteZulipServer with proper details from settings.

This creates a valid registration, for two reasons:
1. Avoid the need to run "manage.py register_server" in dev env to
   register, when wanting to to test stuff with
   `PUSH_NOTIFICATION_BOUNCER_URL = "http://localhost:9991"`.
2. Avoid breaking RemoteRealm syncing, due to duplicate registrations
   (first set of registrations that gets set up with the dummy
   RemoteZulipServer in populate_db, and the second that gets set up via
   the regular syncing mechanism with the new RemoteZulipServer created
   during register_server).
This commit is contained in:
Mateusz Mandera 2023-12-04 19:42:14 +01:00 committed by Tim Abbott
parent c23339f295
commit 8b55d60f9e
2 changed files with 8 additions and 5 deletions

View File

@ -2385,11 +2385,12 @@ def get_topic_messages(user_profile: UserProfile, stream: Stream, topic_name: st
class BouncerTestCase(ZulipTestCase):
@override
def setUp(self) -> None:
# Set a deterministic uuid for convenience.
# Set a deterministic uuid and a nice hostname for convenience.
self.server_uuid = "6cde5f7a-1f7e-4978-9716-49f69ebfc9fe"
self.server = RemoteZulipServer.objects.all().latest("id")
self.server.uuid = self.server_uuid
self.server.hostname = "demo.example.com"
self.server.save()
super().setUp()

View File

@ -1,7 +1,6 @@
import itertools
import os
import random
import uuid
from collections import defaultdict
from datetime import datetime, timedelta
from typing import Any, Dict, List, Mapping, Sequence, Tuple
@ -381,10 +380,13 @@ class Command(BaseCommand):
# 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.
assert isinstance(settings.ZULIP_ORG_ID, str)
assert isinstance(settings.ZULIP_ORG_KEY, str)
server = RemoteZulipServer.objects.create(
uuid=uuid.uuid4(),
api_key="magic_secret_api_key",
hostname="demo.example.com",
uuid=settings.ZULIP_ORG_ID,
api_key=settings.ZULIP_ORG_KEY,
hostname=settings.EXTERNAL_HOST,
last_updated=timezone_now(),
)
update_remote_realm_data_for_server(server, get_realms_info_for_push_bouncer())