From 7c62af0d738c8d07492e2d5257c620850ff12ff4 Mon Sep 17 00:00:00 2001 From: Zixuan James Li Date: Wed, 6 Jul 2022 00:58:43 -0400 Subject: [PATCH] typing: Add assertions before accessing settings. Signed-off-by: Zixuan James Li --- zerver/lib/dev_ldap_directory.py | 1 + zerver/management/commands/register_server.py | 1 + zerver/migrations/0032_verify_all_medium_avatar_images.py | 1 + zerver/tests/test_event_system.py | 1 + zerver/tests/test_import_export.py | 1 + 5 files changed, 5 insertions(+) diff --git a/zerver/lib/dev_ldap_directory.py b/zerver/lib/dev_ldap_directory.py index cf5bbcbcd8..ee6732bfa0 100644 --- a/zerver/lib/dev_ldap_directory.py +++ b/zerver/lib/dev_ldap_directory.py @@ -83,6 +83,7 @@ def init_fakeldap( mock_ldap = MockLDAP() mock_initialize.return_value = mock_ldap + assert settings.FAKE_LDAP_MODE is not None mock_ldap.directory = directory or generate_dev_ldap_dir( settings.FAKE_LDAP_MODE, settings.FAKE_LDAP_NUM_USERS ) diff --git a/zerver/management/commands/register_server.py b/zerver/management/commands/register_server.py index c4e8eed9b2..fee97563ba 100644 --- a/zerver/management/commands/register_server.py +++ b/zerver/management/commands/register_server.py @@ -107,6 +107,7 @@ class Command(ZulipBaseCommand): print("Mobile Push Notification Service registration successfully updated!") def _request_push_notification_bouncer_url(self, url: str, params: Dict[str, Any]) -> Response: + assert settings.PUSH_NOTIFICATION_BOUNCER_URL is not None registration_url = settings.PUSH_NOTIFICATION_BOUNCER_URL + url session = PushBouncerSession() try: diff --git a/zerver/migrations/0032_verify_all_medium_avatar_images.py b/zerver/migrations/0032_verify_all_medium_avatar_images.py index df10daf86c..088fe2f9f4 100644 --- a/zerver/migrations/0032_verify_all_medium_avatar_images.py +++ b/zerver/migrations/0032_verify_all_medium_avatar_images.py @@ -19,6 +19,7 @@ from zerver.models import UserProfile # since we rearranged the avatars in Zulip 1.6. def patched_user_avatar_path(user_profile: UserProfile) -> str: email = user_profile.email + assert settings.AVATAR_SALT is not None user_key = email.lower() + settings.AVATAR_SALT return make_safe_digest(user_key, hashlib.sha1) diff --git a/zerver/tests/test_event_system.py b/zerver/tests/test_event_system.py index 314f671bf3..645e69dd10 100644 --- a/zerver/tests/test_event_system.py +++ b/zerver/tests/test_event_system.py @@ -220,6 +220,7 @@ class EventsEndpointTest(ZulipTestCase): self.assertEqual(str(context.exception), "Access denied") self.assertEqual(context.exception.http_status_code, 403) + assert settings.SHARED_SECRET is not None post_data["secret"] = settings.SHARED_SECRET req = HostRequestMock(post_data, tornado_handler=dummy_handler) req.META["REMOTE_ADDR"] = "127.0.0.1" diff --git a/zerver/tests/test_import_export.py b/zerver/tests/test_import_export.py index ff27e551c8..f83757b8fd 100644 --- a/zerver/tests/test_import_export.py +++ b/zerver/tests/test_import_export.py @@ -131,6 +131,7 @@ class ExportFile(ZulipTestCase): def setUp(self) -> None: super().setUp() + assert settings.LOCAL_UPLOADS_DIR is not None self.rm_tree(settings.LOCAL_UPLOADS_DIR) # Deleting LOCAL_UPLOADS_DIR results in the test database