Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
test_decorators: Remove tests for conditions already excluded by mypy.
Anders Kaseorg83b6884d8bb3
diff --git a/zerver/lib/request.py b/zerver/lib/request.pyindex 33bcdfd446d..ebb2cdfc8da 100644--- a/zerver/lib/request.py+++ b/zerver/lib/request.py@@ -123,12 +123,8 @@ class _REQ(Generic[ResultT]):self.documentation_pending = documentation_pendingself.path_only = path_only- if converter and (validator or str_validator):- # Not user-facing, so shouldn't be tagged for translation- raise AssertionError('converter and validator are mutually exclusive')- if validator and str_validator:- # Not user-facing, so shouldn't be tagged for translation- raise AssertionError('validator and str_validator are mutually exclusive')+ assert converter is None or (validator is None and str_validator is None), 'converter and validator are mutually exclusive'+ assert validator is None or str_validator is None, 'validator and str_validator are mutually exclusive'# This factory function ensures that mypy can correctly analyze REQ.#@@ -305,9 +301,9 @@ def has_request_variables(view_func: ViewFuncT) -> ViewFuncT:raise InvalidJSONError(_("Malformed JSON"))kwargs[func_var_name] = valcontinue- elif param.argument_type is not None:+ else:# This is a view bug, not a user error, and thus should throw a 500.- raise Exception(_("Invalid argument type"))+ assert param.argument_type is None, "Invalid argument type"post_var_names = [param.post_var_name]post_var_names += param.aliasesdiff --git a/zerver/tests/test_decorators.py b/zerver/tests/test_decorators.pyindex 0302459ac33..be58bf9becb 100644--- a/zerver/tests/test_decorators.py+++ b/zerver/tests/test_decorators.py@@ -181,14 +181,6 @@ class DecoratorTestCase(TestCase):result = get_total(request)self.assertEqual(result, 21)- def test_REQ_converter_and_validator_invalid(self) -> None:- with self.assertRaisesRegex(AssertionError, "converter and validator are mutually exclusive"):- @has_request_variables- def get_total(request: HttpRequest,- numbers: Iterable[int]=REQ(validator=check_list(check_int), # type: ignore[call-overload] # The condition being tested is in fact an error.- converter=lambda x: [])) -> int:- return sum(numbers) # nocoverage -- isn't intended to be run-def test_REQ_validator(self) -> None:@has_request_variables@@ -259,15 +251,6 @@ class DecoratorTestCase(TestCase):request.body = '{"a": "b"}'self.assertEqual(get_payload(request), {'a': 'b'})- # Test we properly handle an invalid argument_type.- with self.assertRaises(Exception) as cm:- @has_request_variables- def test(request: HttpRequest,- payload: Any=REQ(argument_type="invalid")) -> None: # type: ignore[call-overload] # The condition being tested is in fact an error.- # Any is ok; exception should occur in decorator:- pass # nocoverage # this function isn't meant to be called- test(request)-def test_api_key_only_webhook_view(self) -> None:@api_key_only_webhook_view('ClientName')def my_webhook(request: HttpRequest, user_profile: UserProfile) -> str: