Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

test_realm: Fix strict_optional errors.

Anders Kaseorg98cc4073ee99
diff --git a/mypy.ini b/mypy.ini
index 6e438fe91e2..4731a29c191 100644
--- a/mypy.ini
+++ b/mypy.ini
@@ -40,8 +40,6 @@ strict_optional = True
# Tests (may be many issues in file; comment is just one error noted)
-[mypy-zerver/tests/test_realm] #191: error: Item "None" of "Optional[Stream]" has no attribute "id"
-strict_optional = False
[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"
diff --git a/zerver/tests/test_realm.py b/zerver/tests/test_realm.py
index 021cbbb5c72..0b11214da2d 100644
--- a/zerver/tests/test_realm.py
+++ b/zerver/tests/test_realm.py
@@ -276,6 +276,7 @@ class RealmTest(ZulipTestCase):
result = self.client_patch('/json/realm', req)
self.assert_json_success(result)
realm = get_realm('zulip')
+ assert realm.notifications_stream is not None
self.assertEqual(realm.notifications_stream.id, new_notif_stream_id)
invalid_notif_stream_id = 1234
@@ -283,6 +284,7 @@ class RealmTest(ZulipTestCase):
result = self.client_patch('/json/realm', req)
self.assert_json_error(result, 'Invalid stream id')
realm = get_realm('zulip')
+ assert realm.notifications_stream is not None
self.assertNotEqual(realm.notifications_stream.id, invalid_notif_stream_id)
def test_get_default_notifications_stream(self) -> None:
@@ -292,6 +294,7 @@ class RealmTest(ZulipTestCase):
realm.save(update_fields=["notifications_stream"])
notifications_stream = realm.get_notifications_stream()
+ assert notifications_stream is not None
self.assertEqual(notifications_stream.id, verona.id)
do_deactivate_stream(notifications_stream)
self.assertIsNone(realm.get_notifications_stream())
@@ -313,6 +316,7 @@ class RealmTest(ZulipTestCase):
result = self.client_patch('/json/realm', req)
self.assert_json_success(result)
realm = get_realm('zulip')
+ assert realm.signup_notifications_stream is not None
self.assertEqual(realm.signup_notifications_stream.id, new_signup_notifications_stream_id)
invalid_signup_notifications_stream_id = 1234
@@ -320,6 +324,7 @@ class RealmTest(ZulipTestCase):
result = self.client_patch('/json/realm', req)
self.assert_json_error(result, 'Invalid stream id')
realm = get_realm('zulip')
+ assert realm.signup_notifications_stream is not None
self.assertNotEqual(realm.signup_notifications_stream.id, invalid_signup_notifications_stream_id)
def test_get_default_signup_notifications_stream(self) -> None:
@@ -329,6 +334,7 @@ class RealmTest(ZulipTestCase):
realm.save(update_fields=["signup_notifications_stream"])
signup_notifications_stream = realm.get_signup_notifications_stream()
+ assert signup_notifications_stream is not None
self.assertEqual(signup_notifications_stream, verona)
do_deactivate_stream(signup_notifications_stream)
self.assertIsNone(realm.get_signup_notifications_stream())