Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
refactor: Rename check_variable_type.
Steve Howellcc3d87b0789b
diff --git a/zerver/lib/validator.py b/zerver/lib/validator.pyindex 985b40ac7b5..92c07a565e3 100644--- a/zerver/lib/validator.py+++ b/zerver/lib/validator.py@@ -263,7 +263,7 @@ def check_dict_only(required_keys: Iterable[Tuple[str, Validator]],optional_keys: Iterable[Tuple[str, Validator]]=[]) -> Validator:return check_dict(required_keys, optional_keys, _allow_only_listed_keys=True)-def check_variable_type(allowed_type_funcs: Iterable[Validator]) -> Validator:+def check_union(allowed_type_funcs: Iterable[Validator]) -> Validator:"""Use this validator if an argument is of a variable type (e.g. processingproperties that might be strings or booleans).diff --git a/zerver/tests/test_decorators.py b/zerver/tests/test_decorators.pyindex e91a3084340..221a55dcea4 100644--- a/zerver/tests/test_decorators.py+++ b/zerver/tests/test_decorators.py@@ -67,8 +67,8 @@ from zerver.lib.validator import (check_string_in,check_string_or_int,check_string_or_int_list,+ check_union,check_url,- check_variable_type,equals,to_non_negative_int,to_positive_or_allowed_int,@@ -960,15 +960,15 @@ class ValidatorTestCase(TestCase):nonperson = 'misconfigured data'self.assertEqual(check_person(nonperson), 'This is not a valid person')- def test_check_variable_type(self) -> None:+ def test_check_union(self) -> None:x: Any = 5- self.assertEqual(check_variable_type([check_string, check_int])('x', x), None)+ self.assertEqual(check_union([check_string, check_int])('x', x), None)x = 'x'- self.assertEqual(check_variable_type([check_string, check_int])('x', x), None)+ self.assertEqual(check_union([check_string, check_int])('x', x), None)x = [{}]- self.assertEqual(check_variable_type([check_string, check_int])('x', x), 'x is not an allowed_type')+ self.assertEqual(check_union([check_string, check_int])('x', x), 'x is not an allowed_type')def test_equals(self) -> None:x: Any = 5diff --git a/zerver/tests/test_import_export.py b/zerver/tests/test_import_export.pyindex a51bf9218da..1263d19913b 100644--- a/zerver/tests/test_import_export.py+++ b/zerver/tests/test_import_export.py@@ -370,7 +370,7 @@ class ImportExportTest(ZulipTestCase):record = data['zerver_attachment'][0]self.assertEqual(record['path_id'], attachment_path_id)- def check_variable_type(user_profile_id: int, realm_id: int) -> None:+ def check_types(user_profile_id: int, realm_id: int) -> None:self.assertEqual(type(user_profile_id), int)self.assertEqual(type(realm_id), int)@@ -382,7 +382,7 @@ class ImportExportTest(ZulipTestCase):records = full_data['uploads_dir_records']self.assertEqual(records[0]['path'], os.path.join(fields[0], fields[1], fields[2]))self.assertEqual(records[0]['s3_path'], attachment_path_id)- check_variable_type(records[0]['user_profile_id'], records[0]['realm_id'])+ check_types(records[0]['user_profile_id'], records[0]['realm_id'])# Test emojisfn = os.path.join(full_data['emoji_dir'], emoji_path)@@ -393,7 +393,7 @@ class ImportExportTest(ZulipTestCase):self.assertTrue('last_modified' in records[0])self.assertEqual(records[0]['path'], '2/emoji/images/1.png')self.assertEqual(records[0]['s3_path'], '2/emoji/images/1.png')- check_variable_type(records[0]['user_profile_id'], records[0]['realm_id'])+ check_types(records[0]['user_profile_id'], records[0]['realm_id'])# Test realm logo and iconrecords = full_data['realm_icons_dir_records']@@ -420,7 +420,7 @@ class ImportExportTest(ZulipTestCase):record_s3_path = [record['s3_path'] for record in records]self.assertIn(original_avatar_path_id, record_path)self.assertIn(original_avatar_path_id, record_s3_path)- check_variable_type(records[0]['user_profile_id'], records[0]['realm_id'])+ check_types(records[0]['user_profile_id'], records[0]['realm_id'])def test_zulip_realm(self) -> None:realm = Realm.objects.get(string_id='zulip')diff --git a/zerver/views/streams.py b/zerver/views/streams.pyindex 678f794b95a..5b0e8010270 100644--- a/zerver/views/streams.py+++ b/zerver/views/streams.py@@ -75,7 +75,7 @@ from zerver.lib.validator import (check_list,check_string,check_string_or_int,- check_variable_type,+ check_union,to_non_negative_int,)from zerver.models import (@@ -338,7 +338,7 @@ def compose_views(def remove_subscriptions_backend(request: HttpRequest, user_profile: UserProfile,streams_raw: Iterable[str]=REQ("subscriptions", validator=check_list(check_string)),- principals: Optional[Union[List[str], List[int]]]=REQ(validator=check_variable_type([+ principals: Optional[Union[List[str], List[int]]]=REQ(validator=check_union([check_list(check_string), check_list(check_int)]), default=None),) -> HttpResponse:@@ -408,7 +408,7 @@ def add_subscriptions_backend(message_retention_days: Union[str, int]=REQ(validator=check_string_or_int,default="realm_default"),announce: bool=REQ(validator=check_bool, default=False),- principals: Union[Sequence[str], Sequence[int]]=REQ(validator=check_variable_type([+ principals: Union[Sequence[str], Sequence[int]]=REQ(validator=check_union([check_list(check_string), check_list(check_int)]), default=[]),authorization_errors_fatal: bool=REQ(validator=check_bool, default=True),) -> HttpResponse:@@ -674,7 +674,7 @@ def update_subscription_properties_backend(validator=check_list(check_dict([("stream_id", check_int),("property", check_string),- ("value", check_variable_type([check_string, check_bool]))]),+ ("value", check_union([check_string, check_bool]))]),),),) -> HttpResponse: