Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
tests: Make all tests inherit ZulipTestCase.
Anders Kaseorg768e8ccc55e7
diff --git a/zerver/tests/test_decorators.py b/zerver/tests/test_decorators.pyindex 13e153aafa3..81aada89bd4 100644--- a/zerver/tests/test_decorators.py+++ b/zerver/tests/test_decorators.py@@ -9,7 +9,6 @@ import ujsonfrom django.conf import settingsfrom django.core.exceptions import ValidationErrorfrom django.http import HttpRequest, HttpResponse-from django.test import TestCasefrom zerver.decorator import (api_key_only_webhook_view,@@ -79,7 +78,7 @@ from zerver.lib.webhooks.common import UnexpectedWebhookEventTypefrom zerver.models import Realm, UserProfile, get_realm, get_user-class DecoratorTestCase(TestCase):+class DecoratorTestCase(ZulipTestCase):def test_get_client_name(self) -> None:req = HostRequestMock()self.assertEqual(get_client_name(req), 'Unspecified')@@ -602,7 +601,7 @@ body:self.assert_json_error(result, "Missing authorization header for basic auth",status_code=401)-class RateLimitTestCase(TestCase):+class RateLimitTestCase(ZulipTestCase):def errors_disallowed(self) -> Any:# Due to what is probably a hack in rate_limit(),# some tests will give a false positive (or succeed@@ -704,7 +703,7 @@ class RateLimitTestCase(TestCase):self.assertTrue(rate_limit_mock.called)-class ValidatorTestCase(TestCase):+class ValidatorTestCase(ZulipTestCase):def test_check_string(self) -> None:x: Any = "hello"check_string('x', x)@@ -1387,7 +1386,7 @@ class TestValidateApiKey(ZulipTestCase):profile.is_active = valueprofile.save()-class TestInternalNotifyView(TestCase):+class TestInternalNotifyView(ZulipTestCase):BORING_RESULT = 'boring'class Request:diff --git a/zerver/tests/test_docs.py b/zerver/tests/test_docs.pyindex 54ff26505f3..18f98bd4e4e 100644--- a/zerver/tests/test_docs.py+++ b/zerver/tests/test_docs.py@@ -6,7 +6,7 @@ from urllib.parse import urlsplitimport ujsonfrom django.conf import settingsfrom django.http import HttpResponse-from django.test import TestCase, override_settings+from django.test import override_settingsfrom zerver.lib.integrations import INTEGRATIONSfrom zerver.lib.test_classes import ZulipTestCase@@ -263,7 +263,7 @@ class HelpTest(ZulipTestCase):self.assertIn('<strong>Manage streams</strong>', str(result.content))self.assertNotIn('/#streams', str(result.content))-class IntegrationTest(TestCase):+class IntegrationTest(ZulipTestCase):def test_check_if_every_integration_has_logo_that_exists(self) -> None:for integration in INTEGRATIONS.values():path = urlsplit(integration.logo_url).pathdiff --git a/zerver/tests/test_i18n.py b/zerver/tests/test_i18n.pyindex a49f605c9d0..ea61a499302 100644--- a/zerver/tests/test_i18n.py+++ b/zerver/tests/test_i18n.py@@ -6,7 +6,6 @@ import ujsonfrom django.conf import settingsfrom django.core import mailfrom django.http import HttpResponse-from django.test import TestCasefrom django.utils import translationfrom zerver.lib.email_notifications import enqueue_welcome_emails@@ -139,7 +138,7 @@ class JsonTranslationTestCase(ZulipTestCase):status_code=400)-class FrontendRegexTestCase(TestCase):+class FrontendRegexTestCase(ZulipTestCase):def test_regexes(self) -> None:command = makemessages.Command()diff --git a/zerver/tests/test_logging_handlers.py b/zerver/tests/test_logging_handlers.pyindex b876c9178a9..b73b1f5d083 100644--- a/zerver/tests/test_logging_handlers.py+++ b/zerver/tests/test_logging_handlers.py@@ -8,7 +8,6 @@ from unittest.mock import MagicMock, patchfrom django.conf import settingsfrom django.contrib.auth.models import AnonymousUserfrom django.http import HttpRequest-from django.test import TestCasefrom django.utils.log import AdminEmailHandlerfrom zerver.lib.test_classes import ZulipTestCase@@ -189,7 +188,7 @@ class AdminNotifyHandlerTest(ZulipTestCase):self.assertIn("message", report)self.assertIn("stack_trace", report)-class LoggingConfigTest(TestCase):+class LoggingConfigTest(ZulipTestCase):@staticmethoddef all_loggers() -> Iterator[logging.Logger]:# There is no documented API for enumerating the loggers; but the@@ -207,7 +206,7 @@ class LoggingConfigTest(TestCase):for handler in logger.handlers:assert not isinstance(handler, AdminEmailHandler)-class ErrorFiltersTest(TestCase):+class ErrorFiltersTest(ZulipTestCase):def test_clean_data_from_query_parameters(self) -> None:from zerver.filters import clean_data_from_query_parametersself.assertEqual(clean_data_from_query_parameters("api_key=abcdz&stream=1"),diff --git a/zerver/tests/test_management_commands.py b/zerver/tests/test_management_commands.pyindex 49846dee753..3d9e2452458 100644--- a/zerver/tests/test_management_commands.py+++ b/zerver/tests/test_management_commands.py@@ -8,7 +8,7 @@ from unittest.mock import MagicMock, call, patchfrom django.conf import settingsfrom django.core.management import call_command-from django.test import TestCase, override_settings+from django.test import override_settingsfrom django.utils.timezone import now as timezone_nowfrom confirmation.models import RealmCreationKey, generate_realm_creation_url@@ -176,7 +176,7 @@ class TestZulipBaseCommand(ZulipTestCase):is_bot=False)self.assertEqual(user_profiles, expected_user_profiles)-class TestCommandsCanStart(TestCase):+class TestCommandsCanStart(ZulipTestCase):def setUp(self) -> None:super().setUp()@@ -197,7 +197,7 @@ class TestCommandsCanStart(TestCase):# we need to reset it here. See #3685 for details.settings.RUNNING_INSIDE_TORNADO = False-class TestSendWebhookFixtureMessage(TestCase):+class TestSendWebhookFixtureMessage(ZulipTestCase):COMMAND_NAME = 'send_webhook_fixture_message'def setUp(self) -> None:diff --git a/zerver/tests/test_markdown.py b/zerver/tests/test_markdown.pyindex 9c7ca597383..9b9c73eb7fd 100644--- a/zerver/tests/test_markdown.py+++ b/zerver/tests/test_markdown.py@@ -7,7 +7,7 @@ from unittest import mockimport ujsonfrom django.conf import settings-from django.test import TestCase, override_settings+from django.test import override_settingsfrom zerver.lib.actions import (do_add_alert_words,@@ -74,7 +74,7 @@ class SimulatedFencedBlockPreprocessor(FencedBlockPreprocessor):return '**' + s.strip('\n') + '**'-class FencedBlockPreprocessorTest(TestCase):+class FencedBlockPreprocessorTest(ZulipTestCase):def test_simple_quoting(self) -> None:processor = FencedBlockPreprocessor(None)markdown_input = [diff --git a/zerver/tests/test_messages.py b/zerver/tests/test_messages.pyindex f3063e5255d..9f607494690 100644--- a/zerver/tests/test_messages.py+++ b/zerver/tests/test_messages.py@@ -10,7 +10,7 @@ from django.conf import settingsfrom django.db import IntegrityErrorfrom django.db.models import Qfrom django.http import HttpResponse-from django.test import TestCase, override_settings+from django.test import override_settingsfrom django.utils.timezone import now as timezone_nowfrom analytics.lib.counts import COUNT_STATS@@ -642,7 +642,7 @@ class InternalPrepTest(ZulipTestCase):# wasn't automatically created.Stream.objects.get(name=stream_name, realm_id=realm.id)-class ExtractTest(TestCase):+class ExtractTest(ZulipTestCase):def test_extract_stream_indicator(self) -> None:self.assertEqual(extract_stream_indicator('development'),diff --git a/zerver/tests/test_narrow.py b/zerver/tests/test_narrow.pyindex 478c1d27646..8bc4f2084c9 100644--- a/zerver/tests/test_narrow.py+++ b/zerver/tests/test_narrow.py@@ -4,7 +4,7 @@ from unittest import mockimport ujsonfrom django.db import connection-from django.test import TestCase, override_settings+from django.test import override_settingsfrom sqlalchemy.sql import and_, column, select, tablefrom sqlalchemy.sql.elements import ClauseElement@@ -440,7 +440,7 @@ class NarrowBuilderTest(ZulipTestCase):def _build_query(self, term: Dict[str, Any]) -> Query:return self.builder.add_term(self.raw_query, term)-class NarrowLibraryTest(TestCase):+class NarrowLibraryTest(ZulipTestCase):def test_build_narrow_filter(self) -> None:fixtures_path = os.path.join(os.path.dirname(__file__),'fixtures/narrow.json')diff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.pyindex a973198b2ec..3b4e755a49b 100644--- a/zerver/tests/test_push_notifications.py+++ b/zerver/tests/test_push_notifications.py@@ -56,7 +56,7 @@ from zerver.lib.remote_server import ()from zerver.lib.request import JsonableErrorfrom zerver.lib.soft_deactivation import do_soft_deactivate_users-from zerver.lib.test_classes import TestCase, ZulipTestCase+from zerver.lib.test_classes import ZulipTestCasefrom zerver.models import (Message,PushDeviceToken,@@ -1733,7 +1733,7 @@ class TestPushApi(BouncerTestCase):self.assertEqual(RemotePushDeviceToken.objects.all().count(), 0)self.assertEqual(PushDeviceToken.objects.all().count(), 0)-class GCMParseOptionsTest(TestCase):+class GCMParseOptionsTest(ZulipTestCase):def test_invalid_option(self) -> None:with self.assertRaises(JsonableError):parse_gcm_options({"invalid": True}, {})diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.pyindex 6310056eecb..abae18585f1 100644--- a/zerver/tests/test_signup.py+++ b/zerver/tests/test_signup.py@@ -12,7 +12,7 @@ from django.contrib.auth.views import INTERNAL_RESET_URL_TOKENfrom django.contrib.contenttypes.models import ContentTypefrom django.core.exceptions import ValidationErrorfrom django.http import HttpResponse-from django.test import TestCase, override_settings+from django.test import override_settingsfrom django.urls import reversefrom django.utils.timezone import now as timezone_now@@ -1955,7 +1955,7 @@ class InvitationsTestCase(InviteUserBase):self.assertIsNotNone(user)self.assertEqual(user.delivery_email, email)-class InviteeEmailsParserTests(TestCase):+class InviteeEmailsParserTests(ZulipTestCase):def setUp(self) -> None:super().setUp()self.email1 = "[email protected]"diff --git a/zerver/tests/test_subdomains.py b/zerver/tests/test_subdomains.pyindex ea557fcb820..954f9f6dc10 100644--- a/zerver/tests/test_subdomains.py+++ b/zerver/tests/test_subdomains.py@@ -1,13 +1,12 @@from typing import Any, Mapping, Sequencefrom unittest import mock-from django.test import TestCase-from zerver.lib.subdomains import get_subdomain+from zerver.lib.test_classes import ZulipTestCasefrom zerver.models import Realm-class SubdomainsTest(TestCase):+class SubdomainsTest(ZulipTestCase):def test_get_subdomain(self) -> None:def request_mock(host: str) -> Any:diff --git a/zerver/tests/test_type_debug.py b/zerver/tests/test_type_debug.pyindex 9bc9fbd6e21..9e804a379aa 100644--- a/zerver/tests/test_type_debug.py+++ b/zerver/tests/test_type_debug.py@@ -1,8 +1,8 @@import sysfrom io import StringIOfrom typing import Any, Callable, Dict, Iterable, List, Tuple, TypeVar-from unittest import TestCase+from zerver.lib.test_classes import ZulipTestCasefrom zerver.lib.type_debug import print_typesT = TypeVar('T')@@ -13,7 +13,7 @@ def add(x: Any=0, y: Any=0) -> Any:def to_dict(v: Iterable[Tuple[Any, Any]]=[]) -> Dict[Any, Any]:return dict(v)-class TypesPrintTest(TestCase):+class TypesPrintTest(ZulipTestCase):# These 2 methods are needed to run tests with our custom test-runnerdef _pre_setup(self) -> None:diff --git a/zerver/tests/test_upload.py b/zerver/tests/test_upload.pyindex b0fc2075a41..24a60249e0c 100644--- a/zerver/tests/test_upload.py+++ b/zerver/tests/test_upload.py@@ -12,7 +12,6 @@ from unittest.mock import patchimport botocore.exceptionsimport ujsonfrom django.conf import settings-from django.test import TestCasefrom django.utils.timezone import now as timezone_nowfrom django_sendfile.utils import _get_sendfilefrom PIL import Image@@ -1880,7 +1879,7 @@ class S3Test(ZulipTestCase):path_id = urllib.parse.urlparse(uri).pathself.assertEqual(delete_export_tarball(path_id), path_id)-class SanitizeNameTests(TestCase):+class SanitizeNameTests(ZulipTestCase):def test_file_name(self) -> None:self.assertEqual(sanitize_name('test.txt'), 'test.txt')self.assertEqual(sanitize_name('.hidden'), '.hidden')@@ -1927,7 +1926,7 @@ class UploadSpaceTests(UploadSerializeMixin, ZulipTestCase):self.assertEqual(None, cache_get(get_realm_used_upload_space_cache_key(self.realm)))self.assertEqual(len(data2), self.realm.currently_used_upload_space_bytes())-class ExifRotateTests(TestCase):+class ExifRotateTests(ZulipTestCase):def test_image_do_not_rotate(self) -> None:# Image does not have _getexif method.img_data = get_test_image_file('img.png').read()diff --git a/zerver/tests/test_urls.py b/zerver/tests/test_urls.pyindex 8e459c46cf2..8523a54f205 100644--- a/zerver/tests/test_urls.py+++ b/zerver/tests/test_urls.py@@ -4,7 +4,7 @@ from typing import List, Optionalimport django.urls.resolversimport ujson-from django.test import Client, TestCase+from django.test import Clientfrom zerver.lib.test_classes import ZulipTestCasefrom zerver.models import Stream@@ -97,7 +97,7 @@ class PublicURLTest(ZulipTestCase):self.assertEqual('success', data['result'])self.assertEqual('ABCD', data['google_client_id'])-class URLResolutionTest(TestCase):+class URLResolutionTest(ZulipTestCase):def get_callback_string(self, pattern: django.urls.resolvers.URLPattern) -> Optional[str]:callback_str = hasattr(pattern, 'lookup_str') and 'lookup_str'callback_str = callback_str or '_callback_str'@@ -128,7 +128,7 @@ class URLResolutionTest(TestCase):(module_name, base_view) = callback_str.rsplit(".", 1)self.check_function_exists(module_name, base_view)-class ErrorPageTest(TestCase):+class ErrorPageTest(ZulipTestCase):def test_bogus_http_host(self) -> None:# This tests that we've successfully worked around a certain bug in# Django's exception handling. The enforce_csrf_checks=True,diff --git a/zerver/webhooks/appfollow/tests.py b/zerver/webhooks/appfollow/tests.pyindex 5c43fb8b90e..38742bad0af 100644--- a/zerver/webhooks/appfollow/tests.py+++ b/zerver/webhooks/appfollow/tests.py@@ -1,6 +1,4 @@-from django.test import TestCase--from zerver.lib.test_classes import WebhookTestCase+from zerver.lib.test_classes import WebhookTestCase, ZulipTestCasefrom zerver.webhooks.appfollow.view import convert_markdown@@ -48,7 +46,7 @@ Acme enables me to manage the flow of information quite well. I only wish I couldef get_body(self, fixture_name: str) -> str:return self.webhook_fixture_data("appfollow", fixture_name, file_type="json")-class ConvertMarkdownTest(TestCase):+class ConvertMarkdownTest(ZulipTestCase):def test_convert_bold(self) -> None:self.assertEqual(convert_markdown("*test message*"), "**test message**")