mirror of https://github.com/zulip/zulip.git
mypy: Clean test_subs.py of mypy strict-optional errors.
Most of this is just asserting that the sub_dict return value from access_stream_by_id is not None in the cases where it shouldn't be, but additionally, we also need to pass a function into validate_user_access_to_subscribers_helper (in this case, just `lambda: True` works fine)
This commit is contained in:
parent
a781b89ec2
commit
495104bd56
2
mypy.ini
2
mypy.ini
|
@ -371,8 +371,6 @@ strict_optional = False
|
|||
strict_optional = False
|
||||
[mypy-zerver/tests/test_auth_backends] #2079: error: Incompatible types in assignment (expression has type "Optional[UserProfile]", variable has type "UserProfile")
|
||||
strict_optional = False
|
||||
[mypy-zerver/tests/test_subs] #2916: error: Item "None" of "Optional[Subscription]" has no attribute "recipient"
|
||||
strict_optional = False
|
||||
[mypy-zerver/tests/test_signup] #1954: error: Item "None" of "Optional[Match[Any]]" has no attribute "groups"
|
||||
strict_optional = False
|
||||
[mypy-zerver/tests/test_realm] #191: error: Item "None" of "Optional[Stream]" has no attribute "id"
|
||||
|
|
|
@ -807,7 +807,7 @@ class StreamAdminTest(ZulipTestCase):
|
|||
def attempt_unsubscribe_of_principal(self, query_count: int, is_admin: bool=False,
|
||||
is_subbed: bool=True, invite_only: bool=False,
|
||||
other_user_subbed: bool=True,
|
||||
other_sub_users: List[UserProfile]=None) -> HttpResponse:
|
||||
other_sub_users: Optional[List[UserProfile]]=None) -> HttpResponse:
|
||||
|
||||
# Set up the main user, who is in most cases an admin.
|
||||
if is_admin:
|
||||
|
@ -2659,11 +2659,11 @@ class SubscriptionAPITest(ZulipTestCase):
|
|||
|
||||
# This should result in missing user
|
||||
with self.assertRaises(ValidationError):
|
||||
validate_user_access_to_subscribers_helper(None, stream_dict, None)
|
||||
validate_user_access_to_subscribers_helper(None, stream_dict, lambda: True)
|
||||
|
||||
# This should result in user not in realm
|
||||
with self.assertRaises(ValidationError):
|
||||
validate_user_access_to_subscribers_helper(user_profile, stream_dict, None)
|
||||
validate_user_access_to_subscribers_helper(user_profile, stream_dict, lambda: True)
|
||||
|
||||
class GetPublicStreamsTest(ZulipTestCase):
|
||||
|
||||
|
@ -3190,6 +3190,7 @@ class AccessStreamTest(ZulipTestCase):
|
|||
# Hamlet can access the private stream
|
||||
(stream_ret, rec_ret, sub_ret) = access_stream_by_id(hamlet, stream.id)
|
||||
self.assertEqual(stream.id, stream_ret.id)
|
||||
assert sub_ret is not None
|
||||
self.assertEqual(sub_ret.recipient, rec_ret)
|
||||
self.assertEqual(sub_ret.recipient.type_id, stream.id)
|
||||
(stream_ret2, rec_ret2, sub_ret2) = access_stream_by_name(hamlet, stream.name)
|
||||
|
@ -3251,6 +3252,7 @@ class AccessStreamTest(ZulipTestCase):
|
|||
# Guest user have access to subscribed public streams
|
||||
self.subscribe(guest_user_profile, stream_name)
|
||||
(stream_ret, rec_ret, sub_ret) = access_stream_by_id(guest_user_profile, stream.id)
|
||||
assert sub_ret is not None
|
||||
self.assertEqual(stream.id, stream_ret.id)
|
||||
self.assertEqual(sub_ret.recipient, rec_ret)
|
||||
self.assertEqual(sub_ret.recipient.type_id, stream.id)
|
||||
|
@ -3264,6 +3266,7 @@ class AccessStreamTest(ZulipTestCase):
|
|||
# Guest user have access to subscribed private streams
|
||||
self.subscribe(guest_user_profile, stream_name)
|
||||
(stream_ret, rec_ret, sub_ret) = access_stream_by_id(guest_user_profile, stream.id)
|
||||
assert sub_ret is not None
|
||||
self.assertEqual(stream.id, stream_ret.id)
|
||||
self.assertEqual(sub_ret.recipient, rec_ret)
|
||||
self.assertEqual(sub_ret.recipient.type_id, stream.id)
|
||||
|
|
Loading…
Reference in New Issue