mirror of https://github.com/zulip/zulip.git
tests: Avoid unchecked casts.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
579f05f3ed
commit
b62c82c3e1
|
@ -5,7 +5,7 @@ import shutil
|
|||
import tempfile
|
||||
import urllib
|
||||
from 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, Union
|
||||
from unittest import mock
|
||||
|
||||
import ujson
|
||||
|
@ -41,6 +41,7 @@ from zerver.lib.streams import (
|
|||
)
|
||||
from zerver.lib.test_helpers import find_key_by_email, instrument_url
|
||||
from zerver.lib.users import get_api_key
|
||||
from zerver.lib.validator import check_string
|
||||
from zerver.lib.webhooks.common import get_fixture_http_headers, standardize_headers
|
||||
from 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:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import urllib.parse
|
||||
from typing import Any, Dict, List, Optional, cast
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
import ujson
|
||||
from 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')
|
||||
|
|
Loading…
Reference in New Issue