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 tempfile
|
||||||
import urllib
|
import urllib
|
||||||
from contextlib import contextmanager
|
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
|
from unittest import mock
|
||||||
|
|
||||||
import ujson
|
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.test_helpers import find_key_by_email, instrument_url
|
||||||
from zerver.lib.users import get_api_key
|
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.lib.webhooks.common import get_fixture_http_headers, standardize_headers
|
||||||
from zerver.models import (
|
from zerver.models import (
|
||||||
Client,
|
Client,
|
||||||
|
@ -543,7 +544,10 @@ class ZulipTestCase(TestCase):
|
||||||
subs = get_stream_subscriptions_for_user(user_profile).filter(
|
subs = get_stream_subscriptions_for_user(user_profile).filter(
|
||||||
active=True,
|
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",
|
def send_personal_message(self, from_user: UserProfile, to_user: UserProfile, content: str="test content",
|
||||||
sending_client_name: str="test suite") -> int:
|
sending_client_name: str="test suite") -> int:
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
from typing import Any, Dict, List, Optional, cast
|
from typing import Any, Dict, Optional
|
||||||
|
|
||||||
import ujson
|
import ujson
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
@ -114,8 +114,7 @@ class EventsTestCase(TornadoWebTestCase):
|
||||||
self.io_loop.call_later(0.1, process_events)
|
self.io_loop.call_later(0.1, process_events)
|
||||||
response = self.wait()
|
response = self.wait()
|
||||||
data = ujson.loads(response.body)
|
data = ujson.loads(response.body)
|
||||||
events = data['events']
|
self.assertEqual(data['events'], [
|
||||||
events = cast(List[Dict[str, Any]], events)
|
{'type': 'test', 'data': 'test data', 'id': 0},
|
||||||
self.assertEqual(len(events), 1)
|
])
|
||||||
self.assertEqual(events[0]['data'], 'test data')
|
|
||||||
self.assertEqual(data['result'], 'success')
|
self.assertEqual(data['result'], 'success')
|
||||||
|
|
Loading…
Reference in New Issue