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)
[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

View File

@ -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

View File

@ -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)