From c0bbdbcadf9e2e4a25d89e7c1cbce401ad7efca2 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Sat, 4 Jul 2020 16:50:02 -0700 Subject: [PATCH] test_messages: Fix strict_optional errors. Signed-off-by: Anders Kaseorg --- mypy.ini | 2 -- zerver/lib/actions.py | 3 --- zerver/tests/test_messages.py | 13 ++++--------- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/mypy.ini b/mypy.ini index 4731a29c19..b06e86a9cf 100644 --- a/mypy.ini +++ b/mypy.ini @@ -40,8 +40,6 @@ strict_optional = True # Tests (may be many issues in file; comment is just one error noted) -[mypy-zerver/tests/test_messages] #3070: error: Incompatible types in assignment (expression has type "None", variable has type "int") -strict_optional = False [mypy-zerver/tests/test_events] #1365: error: Argument 2 to "do_set_realm_notifications_stream" has incompatible type "Optional[Stream]"; expected "Stream" strict_optional = False diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index d13107a39c..7d23a88881 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -2392,9 +2392,6 @@ def _internal_prep_message(realm: Realm, if len(content) > MAX_MESSAGE_LENGTH: content = content[0:3900] + "\n\n[message was too long and has been truncated]" - if realm is None: - raise RuntimeError("None is not a valid realm for internal_prep_message!") - # If we have a stream name, and the stream doesn't exist, we # create it here (though this code path should probably be removed # eventually, moving that responsibility to the caller). If diff --git a/zerver/tests/test_messages.py b/zerver/tests/test_messages.py index 6790f3e0a8..774e096f01 100644 --- a/zerver/tests/test_messages.py +++ b/zerver/tests/test_messages.py @@ -2,7 +2,7 @@ import datetime import time from collections import namedtuple from operator import itemgetter -from typing import Any, Dict, List, Set, Tuple, Union +from typing import Any, Dict, List, Optional, Set, Tuple, Union from unittest import mock import ujson @@ -599,16 +599,10 @@ class InternalPrepTest(ZulipTestCase): sender=sender, recipient_user=recipient_user, content=content) + assert result is not None message = result['message'] self.assertIn('message was too long', message.content) - with self.assertRaises(RuntimeError): - internal_prep_private_message( - realm=None, # should cause error - sender=sender, - recipient_user=recipient_user, - content=content) - # Simulate sending a message to somebody not in the # realm of the sender. recipient_user = self.mit_user('starnine') @@ -1597,7 +1591,7 @@ class SewMessageAndReactionTest(ZulipTestCase): class MessagePOSTTest(ZulipTestCase): - def _send_and_verify_message(self, user: UserProfile, stream_name: str, error_msg: str=None) -> None: + def _send_and_verify_message(self, user: UserProfile, stream_name: str, error_msg: Optional[str]=None) -> None: if error_msg is None: msg_id = self.send_stream_message(user, stream_name) result = self.api_get(user, '/json/messages/' + str(msg_id)) @@ -2397,6 +2391,7 @@ class MessagePOSTTest(ZulipTestCase): self.assert_json_error_contains(result, 'Not authorized to send') # We subscribe the bot owner! (aka cordelia) + assert bot.bot_owner is not None self.subscribe(bot.bot_owner, stream_name) result = self.api_post(bot, "/api/v1/messages", payload)