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.

lint: Catch mock asserts whose leading "assert_" is missing.

Alex Vandiver1e714d8a0ff1
diff --git a/tools/linter_lib/custom_check.py b/tools/linter_lib/custom_check.py
index 56cab9026e4..4cfac2f88dc 100644
--- a/tools/linter_lib/custom_check.py
+++ b/tools/linter_lib/custom_check.py
@@ -390,6 +390,9 @@ python_rules = RuleList(
'zerver/tests/test_users.py',
},
},
+ {'pattern': '\\.(called(_once|_with|_once_with)?|not_called|has_calls|not_called)[(]',
+ 'description': 'A mock function is missing a leading "assert_"',
+ },
*whitespace_rules,
*comma_whitespace_rule,
],
diff --git a/zerver/tests/test_docs.py b/zerver/tests/test_docs.py
index 23d4b2e74c8..4bb7a935290 100644
--- a/zerver/tests/test_docs.py
+++ b/zerver/tests/test_docs.py
@@ -339,7 +339,7 @@ class AboutPageTest(ZulipTestCase):
result = self.client_get('/team/')
self.assertEqual(result.status_code, 200)
self.assert_in_success_response(['Never ran'], result)
- m.called_once()
+ m.assert_called_once()
with self.settings(ZILENCER_ENABLED=False):
result = self.client_get('/team/')
diff --git a/zerver/tests/test_management_commands.py b/zerver/tests/test_management_commands.py
index 4cc005dfdb1..053ba07e8de 100644
--- a/zerver/tests/test_management_commands.py
+++ b/zerver/tests/test_management_commands.py
@@ -328,7 +328,7 @@ class TestCalculateFirstVisibleMessageID(ZulipTestCase):
with patch(func_name) as m:
call_command(self.COMMAND_NAME, "--lookback-hours=35")
calls = [call(realm, 35) for realm in Realm.objects.all()]
- m.has_calls(calls, any_order=True)
+ m.assert_has_calls(calls, any_order=True)
class TestPasswordRestEmail(ZulipTestCase):
COMMAND_NAME = "send_password_reset_email"