Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

tests: Make tests pass with zilencer disabled.

Anders Kaseorg468c5b9a58b6
diff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.py
index 8a6172ea5d0..7c74dfdbd87 100644
--- a/zerver/lib/test_classes.py
+++ b/zerver/lib/test_classes.py
@@ -72,7 +72,9 @@ from zerver.models import (
)
from zerver.openapi.openapi import validate_against_openapi_schema, validate_request
from zerver.tornado.event_queue import clear_client_event_queues_for_testing
-from zilencer.models import get_remote_server_by_uuid
+
+if settings.ZILENCER_ENABLED:
+ from zilencer.models import get_remote_server_by_uuid
class UploadSerializeMixin(SerializeMixin):
diff --git a/zerver/tests/test_decorators.py b/zerver/tests/test_decorators.py
index 0a8ebc183d4..b1d7f459eeb 100644
--- a/zerver/tests/test_decorators.py
+++ b/zerver/tests/test_decorators.py
@@ -3,7 +3,7 @@ import os
import re
from collections import defaultdict
from typing import Any, Dict, Iterable, List, Tuple
-from unittest import mock
+from unittest import mock, skipUnless
import orjson
from django.conf import settings
@@ -78,7 +78,9 @@ from zerver.lib.validator import (
)
from zerver.lib.webhooks.common import UnexpectedWebhookEventType
from zerver.models import Realm, UserProfile, get_realm, get_user
-from zilencer.models import RemoteZulipServer
+
+if settings.ZILENCER_ENABLED:
+ from zilencer.models import RemoteZulipServer
class DecoratorTestCase(ZulipTestCase):
@@ -708,6 +710,7 @@ class RateLimitTestCase(ZulipTestCase):
self.assertTrue(rate_limit_mock.called)
+ @skipUnless(settings.ZILENCER_ENABLED, "requires zilencer")
def test_rate_limiting_skipped_if_remote_server(self) -> None:
server_uuid = "1234-abcd"
server = RemoteZulipServer(uuid=server_uuid,
diff --git a/zerver/tests/test_docs.py b/zerver/tests/test_docs.py
index 3d9ba3586de..23d4b2e74c8 100644
--- a/zerver/tests/test_docs.py
+++ b/zerver/tests/test_docs.py
@@ -1,6 +1,6 @@
import os
from typing import Any, Dict, Sequence
-from unittest import mock
+from unittest import mock, skipUnless
from urllib.parse import urlsplit
import orjson
@@ -123,11 +123,13 @@ class DocPageTest(ZulipTestCase):
self._test('/api/subscribe', 'authorization_errors_fatal')
self._test('/api/create-user', 'zuliprc-admin')
self._test('/api/unsubscribe', 'not_removed')
- self._test('/team/', 'industry veterans')
+ if settings.ZILENCER_ENABLED:
+ self._test('/team/', 'industry veterans')
self._test('/history/', 'Cambridge, Massachusetts')
# Test the i18n version of one of these pages.
self._test('/en/history/', 'Cambridge, Massachusetts')
- self._test('/apps/', 'Apps for every platform.')
+ if settings.ZILENCER_ENABLED:
+ self._test('/apps/', 'Apps for every platform.')
self._test('/features/', 'Beautiful messaging')
self._test('/hello/', 'Chat for distributed teams', landing_missing_strings=["Login"])
self._test('/why-zulip/', 'Why Zulip?')
@@ -325,6 +327,7 @@ class IntegrationTest(ZulipTestCase):
'<a target="_blank" href="/#streams">streams page</a>')
class AboutPageTest(ZulipTestCase):
+ @skipUnless(settings.ZILENCER_ENABLED, "requires zilencer")
def test_endpoint(self) -> None:
with self.settings(CONTRIBUTOR_DATA_FILE_PATH="zerver/tests/fixtures/authors.json"):
result = self.client_get('/team/')
diff --git a/zerver/tests/test_management_commands.py b/zerver/tests/test_management_commands.py
index ac7c71c42d6..4cc005dfdb1 100644
--- a/zerver/tests/test_management_commands.py
+++ b/zerver/tests/test_management_commands.py
@@ -1,13 +1,13 @@
-import glob
import os
import re
from datetime import timedelta
from typing import Any, Dict, List, Optional
-from unittest import mock
+from unittest import mock, skipUnless
from unittest.mock import MagicMock, call, patch
+from django.apps import apps
from django.conf import settings
-from django.core.management import call_command
+from django.core.management import call_command, find_commands
from django.test import override_settings
from django.utils.timezone import now as timezone_now
@@ -182,10 +182,11 @@ class TestCommandsCanStart(ZulipTestCase):
super().setUp()
self.commands = [
command
- for filename in glob.iglob('*/management/commands/*.py')
- for command in [os.path.basename(filename).replace('.py', '')]
- if command != '__init__'
+ for app_config in apps.get_app_configs()
+ if os.path.dirname(app_config.path) == settings.DEPLOY_ROOT
+ for command in find_commands(os.path.join(app_config.path, "management"))
]
+ assert self.commands
def test_management_commands_show_help(self) -> None:
with stdout_suppressed():
@@ -314,6 +315,7 @@ class TestGenerateRealmCreationLink(ZulipTestCase):
result = self.client_get(generated_link)
self.assert_in_success_response(["The organization creation link has expired or is not valid."], result)
+@skipUnless(settings.ZILENCER_ENABLED, "requires zilencer")
class TestCalculateFirstVisibleMessageID(ZulipTestCase):
COMMAND_NAME = 'calculate_first_visible_message_id'
@@ -422,6 +424,7 @@ class TestConvertMattermostData(ZulipTestCase):
call('Converting Data ...')
])
+@skipUnless(settings.ZILENCER_ENABLED, "requires zilencer")
class TestInvoicePlans(ZulipTestCase):
COMMAND_NAME = 'invoice_plans'
diff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.py
index 04940e1287a..9157827a0fa 100644
--- a/zerver/tests/test_push_notifications.py
+++ b/zerver/tests/test_push_notifications.py
@@ -5,7 +5,7 @@ import os
import uuid
from contextlib import contextmanager
from typing import Any, Dict, Iterator, List, Optional
-from unittest import mock
+from unittest import mock, skipUnless
from unittest.mock import call
import orjson
@@ -74,16 +74,19 @@ from zerver.models import (
receives_online_notifications,
receives_stream_notifications,
)
-from zilencer.models import (
- RemoteInstallationCount,
- RemotePushDeviceToken,
- RemoteRealmAuditLog,
- RemoteRealmCount,
- RemoteZulipServer,
-)
+
+if settings.ZILENCER_ENABLED:
+ from zilencer.models import (
+ RemoteInstallationCount,
+ RemotePushDeviceToken,
+ RemoteRealmAuditLog,
+ RemoteRealmCount,
+ RemoteZulipServer,
+ )
ZERVER_DIR = os.path.dirname(os.path.dirname(__file__))
+@skipUnless(settings.ZILENCER_ENABLED, "requires zilencer")
class BouncerTestCase(ZulipTestCase):
def setUp(self) -> None:
self.server_uuid = "1234-abcd"
@@ -2123,6 +2126,7 @@ class TestPushNotificationsContent(ZulipTestCase):
actual_output = get_mobile_push_content(test["rendered_content"])
self.assertEqual(actual_output, test["expected_output"])
+@skipUnless(settings.ZILENCER_ENABLED, "requires zilencer")
class PushBouncerSignupTest(ZulipTestCase):
def test_push_signup_invalid_host(self) -> None:
zulip_org_id = str(uuid.uuid4())