refactor: Use `assert_length` helper instead of `assertTrue/assertEqual`.

This commit is contained in:
akshatdalton 2021-07-13 17:39:37 +00:00 committed by Tim Abbott
parent 77169408f4
commit e203112fd4
7 changed files with 17 additions and 17 deletions

View File

@ -220,7 +220,7 @@ class AnalyticsTestCase(ZulipTestCase):
else:
kwargs["realm"] = self.default_realm
self.assertEqual(table.objects.filter(**kwargs).count(), 1)
self.assertEqual(table.objects.count(), len(arg_values))
self.assert_length(arg_values, table.objects.count())
class TestProcessCountStat(AnalyticsTestCase):

View File

@ -56,7 +56,7 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):
def assert_num_bots_equal(self, count: int) -> None:
result = self.client_get("/json/bots")
self.assert_json_success(result)
self.assertEqual(count, len(result.json()["bots"]))
self.assert_length(result.json()["bots"], count)
def create_bot(self, **extras: Any) -> Dict[str, Any]:
bot_info = {

View File

@ -184,7 +184,7 @@ class TestDigestEmailMessages(ZulipTestCase):
self.assert_length(queries, 12)
self.assert_length(cache_tries, 0)
self.assertEqual(mock_send_future_email.call_count, len(digest_users))
self.assert_length(digest_users, mock_send_future_email.call_count)
for i, digest_user in enumerate(digest_users):
kwargs = mock_send_future_email.call_args_list[i][1]
@ -286,7 +286,7 @@ class TestDigestEmailMessages(ZulipTestCase):
users = self.active_human_users(realm)
num_queued_users = len(queue_mock.call_args[0][0])
self.assertEqual(num_queued_users, len(users))
self.assert_length(users, num_queued_users)
# Simulate that we have sent digests for all our users.
bulk_write_realm_audit_logs(users)
@ -315,7 +315,7 @@ class TestDigestEmailMessages(ZulipTestCase):
_enqueue_emails_for_realm(realm, cutoff)
num_queued_users = len(queue_mock.call_args[0][0])
self.assertEqual(num_queued_users, len(users))
self.assert_length(users, num_queued_users)
for user in users:
last_visit = timezone_now() - datetime.timedelta(days=1)
@ -339,7 +339,7 @@ class TestDigestEmailMessages(ZulipTestCase):
_enqueue_emails_for_realm(realm, cutoff)
num_queued_users = len(queue_mock.call_args[0][0])
self.assertEqual(num_queued_users, len(users))
self.assert_length(users, num_queued_users)
def tuesday(self) -> datetime.datetime:
return datetime.datetime(year=2016, month=1, day=5, tzinfo=datetime.timezone.utc)

View File

@ -289,7 +289,7 @@ class TestFollowupEmails(ZulipTestCase):
scheduled_emails = ScheduledEmail.objects.filter(users=hamlet).order_by(
"scheduled_timestamp"
)
self.assertEqual(2, len(scheduled_emails))
self.assert_length(scheduled_emails, 2)
self.assertEqual(
orjson.loads(scheduled_emails[1].data)["template_prefix"], "zerver/emails/followup_day2"
)

View File

@ -527,7 +527,7 @@ class NarrowLibraryTest(ZulipTestCase):
fixtures_path = os.path.join(os.path.dirname(__file__), "fixtures/narrow.json")
with open(fixtures_path, "rb") as f:
scenarios = orjson.loads(f.read())
self.assertTrue(len(scenarios) == 9)
self.assert_length(scenarios, 9)
for scenario in scenarios:
narrow = scenario["narrow"]
accept_events = scenario["accept_events"]

View File

@ -245,7 +245,7 @@ class UnreadCountTests(ZulipTestCase):
)
differences = [key for key in expected if expected[key] != event[key]]
self.assertTrue(len(differences) == 0)
self.assert_length(differences, 0)
hamlet = self.example_user("hamlet")
um = list(UserMessage.objects.filter(message=message_id))
@ -316,7 +316,7 @@ class UnreadCountTests(ZulipTestCase):
)
differences = [key for key in expected if expected[key] != event[key]]
self.assertTrue(len(differences) == 0)
self.assert_length(differences, 0)
um = list(UserMessage.objects.filter(message=message_id))
for msg in um:

View File

@ -4654,11 +4654,11 @@ class GetSubscribersTest(ZulipTestCase):
subscribed_streams, _ = gather_subscriptions(
self.user_profile, include_subscribers=True
)
self.assertTrue(len(subscribed_streams) >= 11)
self.assertGreaterEqual(len(subscribed_streams), 11)
for sub in subscribed_streams:
if not sub["name"].startswith("stream_"):
continue
self.assertTrue(len(sub["subscribers"]) == len(users_to_subscribe))
self.assert_length(sub["subscribers"], len(users_to_subscribe))
self.assert_length(queries, 5)
def test_never_subscribed_streams(self) -> None:
@ -4742,7 +4742,7 @@ class GetSubscribersTest(ZulipTestCase):
for stream_dict in never_subscribed:
name = stream_dict["name"]
self.assertFalse("invite_only" in name)
self.assertTrue(len(stream_dict["subscribers"]) == len(users_to_subscribe))
self.assert_length(stream_dict["subscribers"], len(users_to_subscribe))
# Send private stream subscribers to all realm admins.
def test_admin_case() -> None:
@ -4755,7 +4755,7 @@ class GetSubscribersTest(ZulipTestCase):
len(public_streams) + len(private_streams) + len(web_public_streams),
)
for stream_dict in never_subscribed:
self.assertTrue(len(stream_dict["subscribers"]) == len(users_to_subscribe))
self.assert_length(stream_dict["subscribers"], len(users_to_subscribe))
test_admin_case()
@ -4885,9 +4885,9 @@ class GetSubscribersTest(ZulipTestCase):
if not sub["name"].startswith("mit_"):
raise AssertionError("Unexpected stream!")
if sub["name"] == "mit_invite_only":
self.assertTrue(len(sub["subscribers"]) == len(users_to_subscribe))
self.assert_length(sub["subscribers"], len(users_to_subscribe))
else:
self.assertTrue(len(sub["subscribers"]) == 0)
self.assert_length(sub["subscribers"], 0)
self.assert_length(queries, 5)
def test_nonsubscriber(self) -> None:
@ -4963,7 +4963,7 @@ class GetSubscribersTest(ZulipTestCase):
# A guest user can only see never subscribed streams that are web-public.
# For Polonius, the only web public stream that he is not subscribed at
# this point is Rome.
self.assertTrue(len(never_subscribed) == 1)
self.assert_length(never_subscribed, 1)
web_public_stream_id = never_subscribed[0]["stream_id"]
result = self.client_get(f"/json/streams/{web_public_stream_id}/members")