Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
tests: Avoid unchecked casts.
Anders Kaseorgb62c82c3e153
diff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.pyindex 753f3301be9..63b7d294368 100644--- a/zerver/lib/test_classes.py+++ b/zerver/lib/test_classes.py@@ -5,7 +5,7 @@ import shutilimport tempfileimport urllibfrom contextlib import contextmanager-from typing import Any, Dict, Iterable, Iterator, List, Optional, Sequence, Set, Tuple, Union, cast+from typing import Any, Dict, Iterable, Iterator, List, Optional, Sequence, Set, Tuple, Unionfrom unittest import mockimport ujson@@ -41,6 +41,7 @@ from zerver.lib.streams import ()from zerver.lib.test_helpers import find_key_by_email, instrument_urlfrom zerver.lib.users import get_api_key+from zerver.lib.validator import check_stringfrom zerver.lib.webhooks.common import get_fixture_http_headers, standardize_headersfrom zerver.models import (Client,@@ -543,7 +544,10 @@ class ZulipTestCase(TestCase):subs = get_stream_subscriptions_for_user(user_profile).filter(active=True,)- return [cast(str, get_display_recipient(sub.recipient)) for sub in subs]+ return [+ check_string("recipient", get_display_recipient(sub.recipient))+ for sub in subs+ ]def send_personal_message(self, from_user: UserProfile, to_user: UserProfile, content: str="test content",sending_client_name: str="test suite") -> int:diff --git a/zerver/tests/test_tornado.py b/zerver/tests/test_tornado.pyindex bdb519e4b20..38c724422ac 100644--- a/zerver/tests/test_tornado.py+++ b/zerver/tests/test_tornado.py@@ -1,5 +1,5 @@import urllib.parse-from typing import Any, Dict, List, Optional, cast+from typing import Any, Dict, Optionalimport ujsonfrom django.conf import settings@@ -114,8 +114,7 @@ class EventsTestCase(TornadoWebTestCase):self.io_loop.call_later(0.1, process_events)response = self.wait()data = ujson.loads(response.body)- events = data['events']- events = cast(List[Dict[str, Any]], events)- self.assertEqual(len(events), 1)- self.assertEqual(events[0]['data'], 'test data')+ self.assertEqual(data['events'], [+ {'type': 'test', 'data': 'test data', 'id': 0},+ ])self.assertEqual(data['result'], 'success')