test_messages: Fix strict_optional errors.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2020-07-04 16:50:02 -07:00 committed by Tim Abbott
parent 98cc4073ee
commit c0bbdbcadf
3 changed files with 4 additions and 14 deletions

View File

@ -40,8 +40,6 @@ strict_optional = True
# Tests (may be many issues in file; comment is just one error noted) # 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" [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 strict_optional = False

View File

@ -2392,9 +2392,6 @@ def _internal_prep_message(realm: Realm,
if len(content) > MAX_MESSAGE_LENGTH: if len(content) > MAX_MESSAGE_LENGTH:
content = content[0:3900] + "\n\n[message was too long and has been truncated]" 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 # If we have a stream name, and the stream doesn't exist, we
# create it here (though this code path should probably be removed # create it here (though this code path should probably be removed
# eventually, moving that responsibility to the caller). If # eventually, moving that responsibility to the caller). If

View File

@ -2,7 +2,7 @@ import datetime
import time import time
from collections import namedtuple from collections import namedtuple
from operator import itemgetter 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 from unittest import mock
import ujson import ujson
@ -599,16 +599,10 @@ class InternalPrepTest(ZulipTestCase):
sender=sender, sender=sender,
recipient_user=recipient_user, recipient_user=recipient_user,
content=content) content=content)
assert result is not None
message = result['message'] message = result['message']
self.assertIn('message was too long', message.content) 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 # Simulate sending a message to somebody not in the
# realm of the sender. # realm of the sender.
recipient_user = self.mit_user('starnine') recipient_user = self.mit_user('starnine')
@ -1597,7 +1591,7 @@ class SewMessageAndReactionTest(ZulipTestCase):
class MessagePOSTTest(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: if error_msg is None:
msg_id = self.send_stream_message(user, stream_name) msg_id = self.send_stream_message(user, stream_name)
result = self.api_get(user, '/json/messages/' + str(msg_id)) 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') self.assert_json_error_contains(result, 'Not authorized to send')
# We subscribe the bot owner! (aka cordelia) # We subscribe the bot owner! (aka cordelia)
assert bot.bot_owner is not None
self.subscribe(bot.bot_owner, stream_name) self.subscribe(bot.bot_owner, stream_name)
result = self.api_post(bot, "/api/v1/messages", payload) result = self.api_post(bot, "/api/v1/messages", payload)