diff --git a/analytics/views.py b/analytics/views.py index 3670cec3de..4987344709 100644 --- a/analytics/views.py +++ b/analytics/views.py @@ -1096,9 +1096,7 @@ def support(request: HttpRequest) -> HttpResponse: new_plan_type = int(new_plan_type) current_plan_type = realm.plan_type do_change_plan_type(realm, new_plan_type) - msg = "Plan type of {} changed from {} to {} ".format(realm.name, - get_plan_name(current_plan_type), - get_plan_name(new_plan_type)) + msg = f"Plan type of {realm.name} changed from {get_plan_name(current_plan_type)} to {get_plan_name(new_plan_type)} " context["message"] = msg new_discount = request.POST.get("discount", None) diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py index 049ba96629..d16a8b5c9a 100644 --- a/corporate/tests/test_stripe.py +++ b/corporate/tests/test_stripe.py @@ -64,8 +64,7 @@ def stripe_fixture_path(decorated_function_name: str, mocked_function_name: str, # use test_* for the python test files if decorated_function_name[:5] == 'test_': decorated_function_name = decorated_function_name[5:] - return "{}/{}--{}.{}.json".format( - STRIPE_FIXTURES_DIR, decorated_function_name, mocked_function_name[7:], call_count) + return f"{STRIPE_FIXTURES_DIR}/{decorated_function_name}--{mocked_function_name[7:]}.{call_count}.json" def fixture_files_for_function(decorated_function: CallableT) -> List[str]: # nocoverage decorated_function_name = decorated_function.__name__ diff --git a/tools/linter_lib/custom_check.py b/tools/linter_lib/custom_check.py index 792a6508e1..649f613cd0 100644 --- a/tools/linter_lib/custom_check.py +++ b/tools/linter_lib/custom_check.py @@ -257,13 +257,11 @@ python_rules = RuleList( # This next check could have false positives, but it seems pretty # rare; if we find any, they can be added to the exclude list for # this rule. - {'pattern': r"""^(?:[^'"#\\]|{}|{})*(?:{}|{})\s*%\s*(?![\s({{\\]|dict\(|tuple\()(?:[^,{}]|{})+(?:$|[,#\\]|{})""".format( - PYSQ, PYDQ, PYSQ, PYDQ, PYDELIMS, PYGROUP, PYRIGHT), + {'pattern': fr"""^(?:[^'"#\\]|{PYSQ}|{PYDQ})*(?:{PYSQ}|{PYDQ})\s*%\s*(?![\s({{\\]|dict\(|tuple\()(?:[^,{PYDELIMS}]|{PYGROUP})+(?:$|[,#\\]|{PYRIGHT})""", 'description': 'Used % formatting without a tuple', 'good_lines': ['"foo %s bar" % ("baz",)'], 'bad_lines': ['"foo %s bar" % "baz"']}, - {'pattern': r"""^(?:[^'"#\\]|{}|{})*(?:{}|{})\s*%\s*\((?:[^,{}]|{})*\)""".format( - PYSQ, PYDQ, PYSQ, PYDQ, PYDELIMS, PYGROUP), + {'pattern': fr"""^(?:[^'"#\\]|{PYSQ}|{PYDQ})*(?:{PYSQ}|{PYDQ})\s*%\s*\((?:[^,{PYDELIMS}]|{PYGROUP})*\)""", 'description': 'Used % formatting with parentheses that do not form a tuple', 'good_lines': ['"foo %s bar" % ("baz",)"'], 'bad_lines': ['"foo %s bar" % ("baz")']}, diff --git a/zerver/data_import/hipchat_attachment.py b/zerver/data_import/hipchat_attachment.py index d56a4a9c11..265654244a 100644 --- a/zerver/data_import/hipchat_attachment.py +++ b/zerver/data_import/hipchat_attachment.py @@ -57,10 +57,7 @@ class AttachmentHandler: size = os.path.getsize(local_fn) mtime = os.path.getmtime(local_fn) - content = '[{name}](/user_uploads/{path})'.format( - name=name, - path=target_path, - ) + content = f'[{name}](/user_uploads/{target_path})' info = dict( message_ids={message_id}, diff --git a/zerver/data_import/slack.py b/zerver/data_import/slack.py index 98e89ed3b7..f612fa4d0e 100755 --- a/zerver/data_import/slack.py +++ b/zerver/data_import/slack.py @@ -300,8 +300,7 @@ def get_user_email(user: ZerverFieldsT, domain_name: str) -> str: raise AssertionError("Could not find email address for Slack user %s" % (user,)) def build_avatar_url(slack_user_id: str, team_id: str, avatar_hash: str) -> str: - avatar_url = "https://ca.slack-edge.com/{}-{}-{}".format(team_id, slack_user_id, - avatar_hash) + avatar_url = f"https://ca.slack-edge.com/{team_id}-{slack_user_id}-{avatar_hash}" return avatar_url def get_owner(user: ZerverFieldsT) -> bool: diff --git a/zerver/lib/bugdown/__init__.py b/zerver/lib/bugdown/__init__.py index bac604ae30..423545c815 100644 --- a/zerver/lib/bugdown/__init__.py +++ b/zerver/lib/bugdown/__init__.py @@ -1718,8 +1718,7 @@ class StreamTopicPattern(CompiledPattern): el.set('data-stream-id', str(stream['id'])) stream_url = encode_stream(stream['id'], stream_name) topic_url = hash_util_encode(topic_name) - link = '/#narrow/stream/{stream_url}/topic/{topic_url}'.format(stream_url=stream_url, - topic_url=topic_url) + link = f'/#narrow/stream/{stream_url}/topic/{topic_url}' el.set('href', link) text = f'#{stream_name} > {topic_name}' el.text = markdown.util.AtomicString(text) diff --git a/zerver/lib/webhooks/common.py b/zerver/lib/webhooks/common.py index e0230f765b..129e599489 100644 --- a/zerver/lib/webhooks/common.py +++ b/zerver/lib/webhooks/common.py @@ -134,9 +134,7 @@ def get_fixture_http_headers(integration_name: str, function from the target integration module to determine what set of HTTP headers goes with the given test fixture. """ - view_module_name = "zerver.webhooks.{integration_name}.view".format( - integration_name=integration_name - ) + view_module_name = f"zerver.webhooks.{integration_name}.view" try: # TODO: We may want to migrate to a more explicit registration # strategy for this behavior rather than a try/except import. diff --git a/zerver/lib/webhooks/git.py b/zerver/lib/webhooks/git.py index 28c85baf41..68623ee90a 100644 --- a/zerver/lib/webhooks/git.py +++ b/zerver/lib/webhooks/git.py @@ -178,14 +178,12 @@ def get_pull_request_event_message(user_name: str, action: str, url: str, number punctuation = ':' if message else '.' if (assignees or assignee or (target_branch and base_branch) or (title is None)): - main_message = '{message}{punctuation}'.format( - message=main_message, punctuation=punctuation) + main_message = f'{main_message}{punctuation}' elif title is not None: # Once we get here, we know that the message ends with a title # which could already have punctuation at the end if title[-1] not in string.punctuation: - main_message = '{message}{punctuation}'.format( - message=main_message, punctuation=punctuation) + main_message = f'{main_message}{punctuation}' if message: main_message += '\n' + CONTENT_MESSAGE_TEMPLATE.format(message=message) diff --git a/zerver/openapi/markdown_extension.py b/zerver/openapi/markdown_extension.py index 646fe1b35d..19f4ecb3cd 100644 --- a/zerver/openapi/markdown_extension.py +++ b/zerver/openapi/markdown_extension.py @@ -177,8 +177,7 @@ def curl_method_arguments(endpoint: str, method: str, elif method in valid_methods: return ["-sSX", method, url] else: - msg = "The request method {} is not one of {}".format(method, - valid_methods) + msg = f"The request method {method} is not one of {valid_methods}" raise ValueError(msg) def get_openapi_param_example_value_as_string(endpoint: str, method: str, param: Dict[str, Any], diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.py index ebebe3904b..239f61ee07 100644 --- a/zerver/tests/test_auth_backends.py +++ b/zerver/tests/test_auth_backends.py @@ -863,8 +863,7 @@ class SocialAuthBase(DesktopFlowTestingLib, ZulipTestCase): self.assertEqual(data['redirect_to'], '/user_uploads/image') self.assertEqual(result.status_code, 302) parsed_url = urllib.parse.urlparse(result.url) - uri = "{}://{}{}".format(parsed_url.scheme, parsed_url.netloc, - parsed_url.path) + uri = f"{parsed_url.scheme}://{parsed_url.netloc}{parsed_url.path}" self.assertTrue(uri.startswith('http://zulip.testserver/accounts/login/subdomain/')) @override_settings(SOCIAL_AUTH_SUBDOMAIN=None) @@ -881,8 +880,7 @@ class SocialAuthBase(DesktopFlowTestingLib, ZulipTestCase): self.assertEqual(data['redirect_to'], '/user_uploads/image') self.assertEqual(result.status_code, 302) parsed_url = urllib.parse.urlparse(result.url) - uri = "{}://{}{}".format(parsed_url.scheme, parsed_url.netloc, - parsed_url.path) + uri = f"{parsed_url.scheme}://{parsed_url.netloc}{parsed_url.path}" self.assertTrue(uri.startswith('http://zulip.testserver/accounts/login/subdomain/')) def test_social_auth_deactivated_user(self) -> None: @@ -1043,8 +1041,7 @@ class SocialAuthBase(DesktopFlowTestingLib, ZulipTestCase): self.assertEqual(data['subdomain'], 'zulip') self.assertEqual(result.status_code, 302) parsed_url = urllib.parse.urlparse(result.url) - uri = "{}://{}{}".format(parsed_url.scheme, parsed_url.netloc, - parsed_url.path) + uri = f"{parsed_url.scheme}://{parsed_url.netloc}{parsed_url.path}" self.assertTrue(uri.startswith('http://zulip.testserver/accounts/login/subdomain/')) hamlet = self.example_user("hamlet") # Name wasn't changed at all @@ -1063,8 +1060,7 @@ class SocialAuthBase(DesktopFlowTestingLib, ZulipTestCase): self.assertEqual(data['subdomain'], 'zulip') self.assertEqual(result.status_code, 302) parsed_url = urllib.parse.urlparse(result.url) - uri = "{}://{}{}".format(parsed_url.scheme, parsed_url.netloc, - parsed_url.path) + uri = f"{parsed_url.scheme}://{parsed_url.netloc}{parsed_url.path}" self.assertTrue(uri.startswith('http://zulip.testserver/accounts/login/subdomain/')) result = self.client_get(result.url) @@ -1251,8 +1247,7 @@ class SocialAuthBase(DesktopFlowTestingLib, ZulipTestCase): self.assertEqual(data['subdomain'], 'zulip') self.assertEqual(result.status_code, 302) parsed_url = urllib.parse.urlparse(result.url) - uri = "{}://{}{}".format(parsed_url.scheme, parsed_url.netloc, - parsed_url.path) + uri = f"{parsed_url.scheme}://{parsed_url.netloc}{parsed_url.path}" self.assertTrue(uri.startswith('http://zulip.testserver/accounts/login/subdomain/')) result = self.client_get(result.url) @@ -1276,8 +1271,7 @@ class SocialAuthBase(DesktopFlowTestingLib, ZulipTestCase): self.assertEqual(data['subdomain'], 'zulip') self.assertEqual(result.status_code, 302) parsed_url = urllib.parse.urlparse(result.url) - uri = "{}://{}{}".format(parsed_url.scheme, parsed_url.netloc, - parsed_url.path) + uri = f"{parsed_url.scheme}://{parsed_url.netloc}{parsed_url.path}" self.assertTrue(uri.startswith('http://zulip.testserver/accounts/login/subdomain/')) result = self.client_get(result.url) @@ -1793,8 +1787,7 @@ class SAMLAuthBackendTest(SocialAuthBase): self.assertEqual(data['subdomain'], 'zulip') self.assertEqual(result.status_code, 302) parsed_url = urllib.parse.urlparse(result.url) - uri = "{}://{}{}".format(parsed_url.scheme, parsed_url.netloc, - parsed_url.path) + uri = f"{parsed_url.scheme}://{parsed_url.netloc}{parsed_url.path}" self.assertTrue(uri.startswith('http://zulip.testserver/accounts/login/subdomain/')) self.client_get(uri) @@ -1829,8 +1822,7 @@ class SAMLAuthBackendTest(SocialAuthBase): self.assertEqual(data['subdomain'], 'zulip') self.assertEqual(result.status_code, 302) parsed_url = urllib.parse.urlparse(result.url) - uri = "{}://{}{}".format(parsed_url.scheme, parsed_url.netloc, - parsed_url.path) + uri = f"{parsed_url.scheme}://{parsed_url.netloc}{parsed_url.path}" self.assertTrue(uri.startswith('http://zulip.testserver/accounts/login/subdomain/')) self.client_get(uri) @@ -1851,8 +1843,7 @@ class SAMLAuthBackendTest(SocialAuthBase): self.assertEqual(data['subdomain'], 'zulip') self.assertEqual(result.status_code, 302) parsed_url = urllib.parse.urlparse(result.url) - uri = "{}://{}{}".format(parsed_url.scheme, parsed_url.netloc, - parsed_url.path) + uri = f"{parsed_url.scheme}://{parsed_url.netloc}{parsed_url.path}" self.assertTrue(uri.startswith('http://zulip.testserver/accounts/login/subdomain/')) self.client_get(uri) @@ -2220,8 +2211,7 @@ class GitHubAuthBackendTest(SocialAuthBase): self.assertEqual(data['redirect_to'], '/user_uploads/image') self.assertEqual(result.status_code, 302) parsed_url = urllib.parse.urlparse(result.url) - uri = "{}://{}{}".format(parsed_url.scheme, parsed_url.netloc, - parsed_url.path) + uri = f"{parsed_url.scheme}://{parsed_url.netloc}{parsed_url.path}" self.assertTrue(uri.startswith('http://zulip.testserver/accounts/login/subdomain/')) def test_github_oauth2_success_single_email(self) -> None: @@ -2246,8 +2236,7 @@ class GitHubAuthBackendTest(SocialAuthBase): self.assertEqual(data['redirect_to'], '/user_uploads/image') self.assertEqual(result.status_code, 302) parsed_url = urllib.parse.urlparse(result.url) - uri = "{}://{}{}".format(parsed_url.scheme, parsed_url.netloc, - parsed_url.path) + uri = f"{parsed_url.scheme}://{parsed_url.netloc}{parsed_url.path}" self.assertTrue(uri.startswith('http://zulip.testserver/accounts/login/subdomain/')) def test_github_oauth2_login_only_one_account_exists(self) -> None: @@ -2277,8 +2266,7 @@ class GitHubAuthBackendTest(SocialAuthBase): self.assertEqual(data['redirect_to'], '/user_uploads/image') self.assertEqual(result.status_code, 302) parsed_url = urllib.parse.urlparse(result.url) - uri = "{}://{}{}".format(parsed_url.scheme, parsed_url.netloc, - parsed_url.path) + uri = f"{parsed_url.scheme}://{parsed_url.netloc}{parsed_url.path}" self.assertTrue(uri.startswith('http://zulip.testserver/accounts/login/subdomain/')) def test_github_oauth2_login_multiple_accounts_exist(self) -> None: @@ -2309,8 +2297,7 @@ class GitHubAuthBackendTest(SocialAuthBase): self.assertEqual(data['redirect_to'], '/user_uploads/image') self.assertEqual(result.status_code, 302) parsed_url = urllib.parse.urlparse(result.url) - uri = "{}://{}{}".format(parsed_url.scheme, parsed_url.netloc, - parsed_url.path) + uri = f"{parsed_url.scheme}://{parsed_url.netloc}{parsed_url.path}" self.assertTrue(uri.startswith('http://zulip.testserver/accounts/login/subdomain/')) def test_github_oauth2_login_no_account_exists(self) -> None: @@ -2363,8 +2350,7 @@ class GitHubAuthBackendTest(SocialAuthBase): self.assertEqual(data['redirect_to'], '/user_uploads/image') self.assertEqual(result.status_code, 302) parsed_url = urllib.parse.urlparse(result.url) - uri = "{}://{}{}".format(parsed_url.scheme, parsed_url.netloc, - parsed_url.path) + uri = f"{parsed_url.scheme}://{parsed_url.netloc}{parsed_url.path}" self.assertTrue(uri.startswith('http://zulip.testserver/accounts/login/subdomain/')) def test_github_oauth2_signup_choose_new_email_to_register(self) -> None: diff --git a/zerver/tests/test_bugdown.py b/zerver/tests/test_bugdown.py index f578b44b57..1b6d68ae0f 100644 --- a/zerver/tests/test_bugdown.py +++ b/zerver/tests/test_bugdown.py @@ -1891,9 +1891,7 @@ class BugdownTest(ZulipTestCase): msg = Message(sender=sender_user_profile, sending_client=get_client("test")) content = "#**привет**" quoted_name = '.D0.BF.D1.80.D0.B8.D0.B2.D0.B5.D1.82' - href = '/#narrow/stream/{stream_id}-{quoted_name}'.format( - stream_id=uni.id, - quoted_name=quoted_name) + href = f'/#narrow/stream/{uni.id}-{quoted_name}' self.assertEqual( render_markdown(msg, content), '

#{s.name}

'.format( diff --git a/zerver/tests/test_messages.py b/zerver/tests/test_messages.py index 5000542b93..219ee98b7c 100644 --- a/zerver/tests/test_messages.py +++ b/zerver/tests/test_messages.py @@ -4299,8 +4299,7 @@ class MessageHasKeywordsTest(ZulipTestCase): with mock.patch("zerver.lib.actions.do_claim_attachments", wraps=do_claim_attachments) as m: - self.update_message(msg, '[link](http://{}/user_uploads/{})'.format( - hamlet.realm.host, dummy_path_ids[0])) + self.update_message(msg, f'[link](http://{hamlet.realm.host}/user_uploads/{dummy_path_ids[0]})') self.assertTrue(m.called) m.reset_mock() @@ -4317,8 +4316,7 @@ class MessageHasKeywordsTest(ZulipTestCase): self.assertFalse(m.called) m.reset_mock() - self.update_message(msg, '[link](https://github.com/user_uploads/{})'.format( - dummy_path_ids[0])) + self.update_message(msg, f'[link](https://github.com/user_uploads/{dummy_path_ids[0]})') self.assertFalse(m.called) m.reset_mock() diff --git a/zerver/tests/test_upload.py b/zerver/tests/test_upload.py index e7bbe18227..95a31b919b 100644 --- a/zerver/tests/test_upload.py +++ b/zerver/tests/test_upload.py @@ -1550,10 +1550,7 @@ class LocalStorageTest(UploadSerializeMixin, ZulipTestCase): result = re.search(re.compile(r"([A-Za-z0-9\-_]{24})"), uri) if result is not None: random_name = result.group(1) - expected_url = "http://zulip.testserver/user_avatars/exports/{realm_id}/{random_name}/tarball.tar.gz".format( - realm_id=user_profile.realm_id, - random_name=random_name, - ) + expected_url = f"http://zulip.testserver/user_avatars/exports/{user_profile.realm_id}/{random_name}/tarball.tar.gz" self.assertEqual(expected_url, uri) # Delete the tarball. @@ -1863,10 +1860,7 @@ class S3Test(ZulipTestCase): result = re.search(re.compile(r"([0-9a-fA-F]{32})"), uri) if result is not None: hex_value = result.group(1) - expected_url = "https://{bucket}.s3.amazonaws.com/exports/{hex_value}/{path}".format( - bucket=bucket.name, - hex_value=hex_value, - path=os.path.basename(tarball_path)) + expected_url = f"https://{bucket.name}.s3.amazonaws.com/exports/{hex_value}/{os.path.basename(tarball_path)}" self.assertEqual(uri, expected_url) # Delete the tarball. diff --git a/zerver/views/development/integrations.py b/zerver/views/development/integrations.py index fbb0a4f02a..9da34f13f9 100644 --- a/zerver/views/development/integrations.py +++ b/zerver/views/development/integrations.py @@ -53,12 +53,10 @@ def get_fixtures(request: HttpResponse, integration_name: str=REQ()) -> HttpResponse: valid_integration_name = get_valid_integration_name(integration_name) if not valid_integration_name: - return json_error("\"{integration_name}\" is not a valid webhook integration.".format( - integration_name=integration_name), status=404) + return json_error(f"\"{integration_name}\" is not a valid webhook integration.", status=404) fixtures = {} - fixtures_dir = os.path.join(ZULIP_PATH, "zerver/webhooks/{valid_integration_name}/fixtures".format( - valid_integration_name=valid_integration_name)) + fixtures_dir = os.path.join(ZULIP_PATH, f"zerver/webhooks/{valid_integration_name}/fixtures") if not os.path.exists(fixtures_dir): msg = ("The integration \"{valid_integration_name}\" does not have fixtures.").format( valid_integration_name=valid_integration_name) @@ -114,11 +112,9 @@ def send_all_webhook_fixture_messages(request: HttpRequest, integration_name: str=REQ()) -> HttpResponse: valid_integration_name = get_valid_integration_name(integration_name) if not valid_integration_name: - return json_error("\"{integration_name}\" is not a valid webhook integration.".format( - integration_name=integration_name), status=404) + return json_error(f"\"{integration_name}\" is not a valid webhook integration.", status=404) - fixtures_dir = os.path.join(ZULIP_PATH, "zerver/webhooks/{valid_integration_name}/fixtures".format( - valid_integration_name=valid_integration_name)) + fixtures_dir = os.path.join(ZULIP_PATH, f"zerver/webhooks/{valid_integration_name}/fixtures") if not os.path.exists(fixtures_dir): msg = ("The integration \"{valid_integration_name}\" does not have fixtures.").format( valid_integration_name=valid_integration_name) diff --git a/zerver/webhooks/alertmanager/view.py b/zerver/webhooks/alertmanager/view.py index 1329bf3216..4156da5e72 100644 --- a/zerver/webhooks/alertmanager/view.py +++ b/zerver/webhooks/alertmanager/view.py @@ -46,16 +46,10 @@ def api_alertmanager_webhook(request: HttpRequest, user_profile: UserProfile, icon = ":squared_ok:" if len(messages) == 1: - body = "{icon} **{title}** {message}".format( - icon=icon, - title=title, - message=messages[0]) + body = f"{icon} **{title}** {messages[0]}" else: message_list = "\n".join([f"* {m}" for m in messages]) - body = "{icon} **{title}**\n{messages}".format( - icon=icon, - title=title, - messages=message_list) + body = f"{icon} **{title}**\n{message_list}" check_send_webhook_message(request, user_profile, topic, body) diff --git a/zerver/webhooks/bitbucket2/tests.py b/zerver/webhooks/bitbucket2/tests.py index 28265076bc..4282e4b376 100644 --- a/zerver/webhooks/bitbucket2/tests.py +++ b/zerver/webhooks/bitbucket2/tests.py @@ -47,17 +47,13 @@ class Bitbucket2HookTests(WebhookTestCase): def test_bitbucket2_on_push_commits_above_limit_event(self) -> None: commit_info = '* a ([6f161a7](https://bitbucket.org/kolaszek/repository-name/commits/6f161a7bced94430ac8947d87dbf45c6deee3fb0))\n' - expected_message = "kolaszek [pushed](https://bitbucket.org/kolaszek/repository-name/branches/compare/6f161a7bced94430ac8947d87dbf45c6deee3fb0..1221f2fda6f1e3654b09f1f3a08390e4cb25bb48) 5 commits to branch master. Commits by Tomasz (5).\n\n{}[and more commit(s)]".format( - (commit_info * 5), - ) + expected_message = f"kolaszek [pushed](https://bitbucket.org/kolaszek/repository-name/branches/compare/6f161a7bced94430ac8947d87dbf45c6deee3fb0..1221f2fda6f1e3654b09f1f3a08390e4cb25bb48) 5 commits to branch master. Commits by Tomasz (5).\n\n{(commit_info * 5)}[and more commit(s)]" self.send_and_test_stream_message('push_commits_above_limit', self.EXPECTED_TOPIC_BRANCH_EVENTS, expected_message) def test_bitbucket2_on_push_commits_above_limit_filtered_by_branches(self) -> None: self.url = self.build_webhook_url(branches='master,development') commit_info = '* a ([6f161a7](https://bitbucket.org/kolaszek/repository-name/commits/6f161a7bced94430ac8947d87dbf45c6deee3fb0))\n' - expected_message = "kolaszek [pushed](https://bitbucket.org/kolaszek/repository-name/branches/compare/6f161a7bced94430ac8947d87dbf45c6deee3fb0..1221f2fda6f1e3654b09f1f3a08390e4cb25bb48) 5 commits to branch master. Commits by Tomasz (5).\n\n{}[and more commit(s)]".format( - (commit_info * 5), - ) + expected_message = f"kolaszek [pushed](https://bitbucket.org/kolaszek/repository-name/branches/compare/6f161a7bced94430ac8947d87dbf45c6deee3fb0..1221f2fda6f1e3654b09f1f3a08390e4cb25bb48) 5 commits to branch master. Commits by Tomasz (5).\n\n{(commit_info * 5)}[and more commit(s)]" self.send_and_test_stream_message('push_commits_above_limit', self.EXPECTED_TOPIC_BRANCH_EVENTS, expected_message) diff --git a/zerver/webhooks/freshdesk/view.py b/zerver/webhooks/freshdesk/view.py index c62989434a..7cff69d77f 100644 --- a/zerver/webhooks/freshdesk/view.py +++ b/zerver/webhooks/freshdesk/view.py @@ -150,10 +150,7 @@ def api_freshdesk_webhook(request: HttpRequest, user_profile: UserProfile, ticket = TicketDict(ticket_data) - subject = "#{ticket_id}: {ticket_subject}".format( - ticket_id=ticket.id, - ticket_subject=ticket.subject - ) + subject = f"#{ticket.id}: {ticket.subject}" event_info = parse_freshdesk_event(ticket.triggered_event) if event_info[1] == "created": diff --git a/zerver/webhooks/github/tests.py b/zerver/webhooks/github/tests.py index f5edd754d3..2ee5824861 100644 --- a/zerver/webhooks/github/tests.py +++ b/zerver/webhooks/github/tests.py @@ -78,17 +78,13 @@ class GithubWebhookTest(WebhookTestCase): def test_push_50_commits(self) -> None: commit_info = "* Update README.md ([0d1a26e](https://github.com/baxterthehacker/public-repo/commit/0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c))\n" - expected_message = "baxterthehacker [pushed](https://github.com/baxterthehacker/public-repo/compare/9049f1265b7d...0d1a26e67d8f) 50 commits to branch changes.\n\n{}[and 30 more commit(s)]".format( - commit_info * COMMITS_LIMIT - ) + expected_message = f"baxterthehacker [pushed](https://github.com/baxterthehacker/public-repo/compare/9049f1265b7d...0d1a26e67d8f) 50 commits to branch changes.\n\n{commit_info * COMMITS_LIMIT}[and 30 more commit(s)]" self.send_and_test_stream_message('push__50_commits', self.EXPECTED_TOPIC_BRANCH_EVENTS, expected_message) def test_push_50_commits_filtered_by_branches(self) -> None: self.url = self.build_webhook_url(branches='master,changes') commit_info = "* Update README.md ([0d1a26e](https://github.com/baxterthehacker/public-repo/commit/0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c))\n" - expected_message = "baxterthehacker [pushed](https://github.com/baxterthehacker/public-repo/compare/9049f1265b7d...0d1a26e67d8f) 50 commits to branch changes.\n\n{}[and 30 more commit(s)]".format( - commit_info * COMMITS_LIMIT - ) + expected_message = f"baxterthehacker [pushed](https://github.com/baxterthehacker/public-repo/compare/9049f1265b7d...0d1a26e67d8f) 50 commits to branch changes.\n\n{commit_info * COMMITS_LIMIT}[and 30 more commit(s)]" self.send_and_test_stream_message('push__50_commits', self.EXPECTED_TOPIC_BRANCH_EVENTS, expected_message) def test_commit_comment_msg(self) -> None: diff --git a/zerver/webhooks/github/view.py b/zerver/webhooks/github/view.py index aafc93b69f..603966201b 100644 --- a/zerver/webhooks/github/view.py +++ b/zerver/webhooks/github/view.py @@ -145,9 +145,7 @@ def get_fork_body(payload: Dict[str, Any]) -> str: ) def get_deployment_body(payload: Dict[str, Any]) -> str: - return '{} created new deployment.'.format( - get_sender_name(payload), - ) + return f'{get_sender_name(payload)} created new deployment.' def get_change_deployment_status_body(payload: Dict[str, Any]) -> str: return 'Deployment changed status to {}.'.format( diff --git a/zerver/webhooks/gitlab/tests.py b/zerver/webhooks/gitlab/tests.py index d8b6fc5cae..1769162f62 100644 --- a/zerver/webhooks/gitlab/tests.py +++ b/zerver/webhooks/gitlab/tests.py @@ -45,20 +45,14 @@ class GitlabHookTests(WebhookTestCase): def test_push_commits_more_than_limit_event_message(self) -> None: expected_topic = "my-awesome-project / tomek" commits_info = '* b ([66abd2d](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/66abd2da28809ffa128ed0447965cf11d7f863a7))\n' - expected_message = "Tomasz Kolek [pushed](https://gitlab.com/tomaszkolek0/my-awesome-project/compare/5fcdd5551fc3085df79bece2c32b1400802ac407...eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9) 50 commits to branch tomek.\n\n{}[and {} more commit(s)]".format( - commits_info * COMMITS_LIMIT, - 50 - COMMITS_LIMIT, - ) + expected_message = f"Tomasz Kolek [pushed](https://gitlab.com/tomaszkolek0/my-awesome-project/compare/5fcdd5551fc3085df79bece2c32b1400802ac407...eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9) 50 commits to branch tomek.\n\n{commits_info * COMMITS_LIMIT}[and {50 - COMMITS_LIMIT} more commit(s)]" self.send_and_test_stream_message('push_hook__push_commits_more_than_limit', expected_topic, expected_message) def test_push_commits_more_than_limit_message_filtered_by_branches(self) -> None: self.url = self.build_webhook_url(branches='master,tomek') expected_topic = "my-awesome-project / tomek" commits_info = '* b ([66abd2d](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/66abd2da28809ffa128ed0447965cf11d7f863a7))\n' - expected_message = "Tomasz Kolek [pushed](https://gitlab.com/tomaszkolek0/my-awesome-project/compare/5fcdd5551fc3085df79bece2c32b1400802ac407...eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9) 50 commits to branch tomek.\n\n{}[and {} more commit(s)]".format( - commits_info * COMMITS_LIMIT, - 50 - COMMITS_LIMIT, - ) + expected_message = f"Tomasz Kolek [pushed](https://gitlab.com/tomaszkolek0/my-awesome-project/compare/5fcdd5551fc3085df79bece2c32b1400802ac407...eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9) 50 commits to branch tomek.\n\n{commits_info * COMMITS_LIMIT}[and {50 - COMMITS_LIMIT} more commit(s)]" self.send_and_test_stream_message('push_hook__push_commits_more_than_limit', expected_topic, expected_message) def test_remove_branch_event_message(self) -> None: diff --git a/zerver/webhooks/gitlab/view.py b/zerver/webhooks/gitlab/view.py index 51c04e6713..e4c69d6356 100644 --- a/zerver/webhooks/gitlab/view.py +++ b/zerver/webhooks/gitlab/view.py @@ -241,8 +241,7 @@ def get_build_hook_event_body(payload: Dict[str, Any]) -> str: ) def get_test_event_body(payload: Dict[str, Any]) -> str: - return "Webhook for **{repo}** has been configured successfully! :tada:".format( - repo=get_repo_name(payload)) + return f"Webhook for **{get_repo_name(payload)}** has been configured successfully! :tada:" def get_pipeline_event_body(payload: Dict[str, Any]) -> str: pipeline_status = payload['object_attributes'].get('status') @@ -269,11 +268,7 @@ def get_pipeline_event_body(payload: Dict[str, Any]) -> str: if artifact_filename: artifact_download_url = f'{build_url}/artifacts/download' artifact_browse_url = f'{build_url}/artifacts/browse' - artifact_string = ' * built artifact: *{}* [[Browse]({})|[Download]({})]\n'.format( - artifact_filename, - artifact_browse_url, - artifact_download_url - ) + artifact_string = f' * built artifact: *{artifact_filename}* [[Browse]({artifact_browse_url})|[Download]({artifact_download_url})]\n' else: artifact_string = '' builds_status += "* [{}]({}) - {}\n{}".format( diff --git a/zerver/webhooks/gogs/tests.py b/zerver/webhooks/gogs/tests.py index b731e9b910..145394cf0f 100644 --- a/zerver/webhooks/gogs/tests.py +++ b/zerver/webhooks/gogs/tests.py @@ -40,20 +40,14 @@ class GogsHookTests(WebhookTestCase): def test_push_commits_more_than_limits(self) -> None: expected_topic = "try-git / master" commits_info = "* Webhook Test ([d8fce16](http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794))\n" - expected_message = "john [pushed](http://localhost:3000/john/try-git/compare/479e6b772b7fba19412457483f50b201286d0103...d8fce16c72a2ff56a5afc8a08645a6ce45491794) 30 commits to branch master. Commits by John (30).\n\n{}[and {} more commit(s)]".format( - commits_info * COMMITS_LIMIT, - 30 - COMMITS_LIMIT - ) + expected_message = f"john [pushed](http://localhost:3000/john/try-git/compare/479e6b772b7fba19412457483f50b201286d0103...d8fce16c72a2ff56a5afc8a08645a6ce45491794) 30 commits to branch master. Commits by John (30).\n\n{commits_info * COMMITS_LIMIT}[and {30 - COMMITS_LIMIT} more commit(s)]" self.send_and_test_stream_message('push__commits_more_than_limits', expected_topic, expected_message) def test_push_commits_more_than_limits_filtered_by_branches(self) -> None: self.url = self.build_webhook_url(branches='master,development') expected_topic = "try-git / master" commits_info = "* Webhook Test ([d8fce16](http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794))\n" - expected_message = "john [pushed](http://localhost:3000/john/try-git/compare/479e6b772b7fba19412457483f50b201286d0103...d8fce16c72a2ff56a5afc8a08645a6ce45491794) 30 commits to branch master. Commits by John (30).\n\n{}[and {} more commit(s)]".format( - commits_info * COMMITS_LIMIT, - 30 - COMMITS_LIMIT - ) + expected_message = f"john [pushed](http://localhost:3000/john/try-git/compare/479e6b772b7fba19412457483f50b201286d0103...d8fce16c72a2ff56a5afc8a08645a6ce45491794) 30 commits to branch master. Commits by John (30).\n\n{commits_info * COMMITS_LIMIT}[and {30 - COMMITS_LIMIT} more commit(s)]" self.send_and_test_stream_message('push__commits_more_than_limits', expected_topic, expected_message) def test_new_branch(self) -> None: diff --git a/zerver/webhooks/harbor/view.py b/zerver/webhooks/harbor/view.py index c16a1a54d2..e47774f150 100644 --- a/zerver/webhooks/harbor/view.py +++ b/zerver/webhooks/harbor/view.py @@ -43,11 +43,7 @@ def handle_push_image_event(payload: Dict[str, Any], image_name = payload["event_data"]["repository"]["repo_full_name"] image_tag = payload["event_data"]["resources"][0]["tag"] - return "{author} pushed image `{image_name}:{image_tag}`".format( - author=operator_username, - image_name=image_name, - image_tag=image_tag - ) + return f"{operator_username} pushed image `{image_name}:{image_tag}`" VULNERABILITY_SEVERITY_NAME_MAP = { diff --git a/zerver/webhooks/raygun/view.py b/zerver/webhooks/raygun/view.py index 98f1751523..cace93e5bb 100644 --- a/zerver/webhooks/raygun/view.py +++ b/zerver/webhooks/raygun/view.py @@ -55,8 +55,7 @@ def make_user_stats_chunk(error_dict: Dict[str, Any]) -> str: total_occurrences = error_dict['totalOccurrences'] # One line is subjectively better than two lines for this. - return "* {} users affected with {} total occurrences\n".format( - users_affected, total_occurrences) + return f"* {users_affected} users affected with {total_occurrences} total occurrences\n" def make_time_chunk(error_dict: Dict[str, Any]) -> str: @@ -76,8 +75,7 @@ def make_time_chunk(error_dict: Dict[str, Any]) -> str: time_last = parse_time(error_dict['lastOccurredOn']) # Provide time information about this error, - return "* **First occurred**: {}\n* **Last occurred**: {}\n".format( - time_first, time_last) + return f"* **First occurred**: {time_first}\n* **Last occurred**: {time_last}\n" def make_message_chunk(message: str) -> str: @@ -185,8 +183,7 @@ def notification_message_error_occurred(payload: Dict[str, Any]) -> str: if affected_user is not None: user_uuid = affected_user['UUID'] - message += "* **Affected user**: {}...{}\n".format( - user_uuid[:6], user_uuid[-5:]) + message += f"* **Affected user**: {user_uuid[:6]}...{user_uuid[-5:]}\n" if custom_data is not None: # We don't know what the keys and values beforehand, so we are forced @@ -241,16 +238,13 @@ def activity_message(payload: Dict[str, Any]) -> str: user = payload['error']['user'] if event_type == "StatusChanged": error_status = payload['error']['status'] - message += "{} status changed to **{}** by {}:\n".format( - error_link_md, error_status, user) + message += f"{error_link_md} status changed to **{error_status}** by {user}:\n" elif event_type == "CommentAdded": comment = payload['error']['comment'] - message += "{} commented on {}:\n\n``` quote\n{}\n```\n".format( - user, error_link_md, comment) + message += f"{user} commented on {error_link_md}:\n\n``` quote\n{comment}\n```\n" elif event_type == "AssignedToUser": assigned_to = payload['error']['assignedTo'] - message += "{} assigned {} to {}:\n".format( - user, error_link_md, assigned_to) + message += f"{user} assigned {error_link_md} to {assigned_to}:\n" message += "* **Timestamp**: {}\n".format( parse_time(payload['error']['activityDate'])) diff --git a/zerver/webhooks/semaphore/view.py b/zerver/webhooks/semaphore/view.py index 14f80d6e22..b1bab46415 100644 --- a/zerver/webhooks/semaphore/view.py +++ b/zerver/webhooks/semaphore/view.py @@ -147,8 +147,7 @@ def semaphore_classic(payload: Dict[str, Any]) -> Tuple[str, str, str]: ) else: # should never get here - content = "{event}: {result}".format( - event=event, result=result) + content = f"{event}: {result}" return content, project_name, branch_name @@ -163,8 +162,7 @@ def semaphore_2(payload: Dict[str, Any]) -> Tuple[str, str, Optional[str]]: author_url=GITHUB_URL_TEMPLATES['user'].format(repo_url=repo_url, username=author_name), pipeline_name=payload["pipeline"]["name"], pipeline_result=payload["pipeline"]["result"], - workflow_url='https://{org}.semaphoreci.com/workflows/{id}'.format( - org=organization_name, id=workflow_id) + workflow_url=f'https://{organization_name}.semaphoreci.com/workflows/{workflow_id}' ) if payload["revision"]["reference_type"] == "branch": # push event diff --git a/zerver/webhooks/teamcity/view.py b/zerver/webhooks/teamcity/view.py index c4aa7d57cb..7356ce09f2 100644 --- a/zerver/webhooks/teamcity/view.py +++ b/zerver/webhooks/teamcity/view.py @@ -76,11 +76,9 @@ def api_teamcity_webhook(request: HttpRequest, user_profile: UserProfile, status = 'was successful! :thumbs_up:' elif build_result == 'failure': if build_result_delta == 'broken': - status = 'is broken with status {status}! :thumbs_down:'.format( - status=build_status) + status = f'is broken with status {build_status}! :thumbs_down:' else: - status = 'is still broken with status {status}! :thumbs_down:'.format( - status=build_status) + status = f'is still broken with status {build_status}! :thumbs_down:' elif build_result == 'running': status = 'has started.' diff --git a/zproject/backends.py b/zproject/backends.py index 57e200cd21..e23d84bb60 100644 --- a/zproject/backends.py +++ b/zproject/backends.py @@ -1198,10 +1198,7 @@ def social_associate_user_helper(backend: BaseAuth, return_data: Dict[str, Any], # In SAML authentication, the IdP may support only sending # the first and last name as separate attributes - in that case # we construct the full name from them. - return_data["full_name"] = "{} {}".format( - first_name, - last_name - ).strip() # strip removes the unnecessary ' ' + return_data["full_name"] = f"{first_name} {last_name}".strip() # strip removes the unnecessary ' ' return user_profile