Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def mock_basket(settings):
)
responses.add(
responses.POST,
settings.BASKET_URL + '/news/unsubscribe/{}/'.format(USER_TOKEN),
settings.BASKET_URL + f'/news/unsubscribe/{USER_TOKEN}/',
json={'status': 'ok', 'token': USER_TOKEN},
)

Expand Down Expand Up @@ -165,7 +165,7 @@ def test_pre_setup(request, tmpdir, settings):
# Randomize the cache key prefix to keep
# tests isolated from each other.
prefix = uuid.uuid4().hex
settings.CACHES['default']['KEY_PREFIX'] = 'amo:{0}:'.format(prefix)
settings.CACHES['default']['KEY_PREFIX'] = f'amo:{prefix}:'

# Reset global django-waffle cache instance to make sure it's properly
# using our new key prefix
Expand Down
9 changes: 5 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ line-length = 88

[tool.ruff.lint]
ignore = [
"DTZ", # flake8-datetimez (except DTZ003) - we only run in UTC so unnecessary
"ISC004", # implicit-string-concatenation-in-collection-literal - too many false positives
# The following rules fail currently, and should probably eventually be addressed
"DTZ", # flake8-datetimez (except DTZ003)
"UP", # pyupgrade
# They are in most-error-occuring order
# They are in most-error-occuring order, descending
"UP031", # printf-string-formatting
"RUF012", # mutable-class-default
"ISC004", # implicit-string-concatenation-in-collection-literal
"SIM115", # open-file-with-context-handler
"BLE001", # blind-except
"RUF059", # unused-unpacked-variable
Expand All @@ -54,6 +54,7 @@ ignore = [
"SIM118", # in-dict-keys
"TRY201", # verbose-raise
"INT003", # printf-in-get-text-func-call
"UP030", # format-literals

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why ignore it, isn't it one of the rules this PR is fixing ?

"INT002", # format-in-get-text-func-call
"INT001", # f-string-in-get-text-func-cal
]
Expand Down
1 change: 0 additions & 1 deletion settings_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# ruff: noqa: F405
from settings import * # noqa

Expand Down
2 changes: 1 addition & 1 deletion src/olympia/accounts/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def validate_group(self, group):
if count != 1:
log.info(
'Super creation: looking for group with '
'permissions {} {} (count: {})'.format(group, rule, count)
f'permissions {group} {rule} (count: {count})'
)
raise serializers.ValidationError(
'Could not find a permissions group with the exact rules needed.'
Expand Down
20 changes: 5 additions & 15 deletions src/olympia/accounts/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ def test_fxa_login_url_without_requiring_two_factor_auth():
)

url = urlparse(raw_url)
base = '{scheme}://{netloc}{path}'.format(
scheme=url.scheme, netloc=url.netloc, path=url.path
)
base = f'{url.scheme}://{url.netloc}{url.path}'
assert base == 'https://accounts.firefox.com/oauth/authorization'
query = parse_qs(url.query)
next_path = urlsafe_b64encode(path.encode('utf-8')).rstrip(b'=')
Expand All @@ -58,9 +56,7 @@ def test_fxa_login_url_requiring_two_factor_auth():
)

url = urlparse(raw_url)
base = '{scheme}://{netloc}{path}'.format(
scheme=url.scheme, netloc=url.netloc, path=url.path
)
base = f'{url.scheme}://{url.netloc}{url.path}'
assert base == 'https://accounts.firefox.com/oauth/authorization'
query = parse_qs(url.query)
next_path = urlsafe_b64encode(path.encode('utf-8')).rstrip(b'=')
Expand Down Expand Up @@ -89,9 +85,7 @@ def test_fxa_login_url_requiring_two_factor_auth_passing_token():
)

url = urlparse(raw_url)
base = '{scheme}://{netloc}{path}'.format(
scheme=url.scheme, netloc=url.netloc, path=url.path
)
base = f'{url.scheme}://{url.netloc}{url.path}'
assert base == 'https://accounts.firefox.com/oauth/authorization'
query = parse_qs(url.query)
next_path = urlsafe_b64encode(path.encode('utf-8')).rstrip(b'=')
Expand Down Expand Up @@ -121,9 +115,7 @@ def test_fxa_login_url_requiring_two_factor_auth_passing_request():
)

url = urlparse(raw_url)
base = '{scheme}://{netloc}{path}'.format(
scheme=url.scheme, netloc=url.netloc, path=url.path
)
base = f'{url.scheme}://{url.netloc}{url.path}'
assert base == 'https://accounts.firefox.com/oauth/authorization'
query = parse_qs(url.query)
next_path = urlsafe_b64encode(path.encode('utf-8')).rstrip(b'=')
Expand Down Expand Up @@ -153,9 +145,7 @@ def test_fxa_login_url_requiring_two_factor_auth_passing_login_hint():
)

url = urlparse(raw_url)
base = '{scheme}://{netloc}{path}'.format(
scheme=url.scheme, netloc=url.netloc, path=url.path
)
base = f'{url.scheme}://{url.netloc}{url.path}'
assert base == 'https://accounts.firefox.com/oauth/authorization'
query = parse_qs(url.query)
next_path = urlsafe_b64encode(path.encode('utf-8')).rstrip(b'=')
Expand Down
14 changes: 5 additions & 9 deletions src/olympia/accounts/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ def test_redirect_url_is_correct(self):
== 'max-age=0, no-cache, no-store, must-revalidate, private'
)
url = urlparse(response['location'])
redirect = '{scheme}://{netloc}{path}'.format(
scheme=url.scheme, netloc=url.netloc, path=url.path
)
redirect = f'{url.scheme}://{url.netloc}{url.path}'
assert redirect == 'https://accounts.firefox.com/v1/authorization'
assert parse_qs(url.query) == {
'access_type': ['offline'],
Expand Down Expand Up @@ -606,9 +604,7 @@ def _test_should_redirect_for_two_factor_auth(self):
# as prompt=none to avoid the need for the user to re-authenticate.
assert response.status_code == 302
url = urlparse(response['Location'])
base = '{scheme}://{netloc}{path}'.format(
scheme=url.scheme, netloc=url.netloc, path=url.path
)
base = f'{url.scheme}://{url.netloc}{url.path}'
fxa_config = settings.FXA_CONFIG[settings.DEFAULT_FXA_CONFIG_NAME]
assert base == '{host}{path}'.format(
host=settings.FXA_OAUTH_HOST, path='/authorization'
Expand Down Expand Up @@ -2416,9 +2412,9 @@ def test_basket_integration(self):
'sync': 'Y',
'optin': 'Y',
'source_url': (
'http://testserver/api/{api_version}/accounts/account/'
'{id}/notifications/'
).format(id=self.user.id, api_version=api_settings.DEFAULT_VERSION),
f'http://testserver/api/{api_settings.DEFAULT_VERSION}/accounts/account/'
f'{self.user.id}/notifications/'
),
'email': self.user.email,
},
headers={'x-api-key': 'testkey'},
Expand Down
11 changes: 3 additions & 8 deletions src/olympia/accounts/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,8 @@ def get_fxa_token(*, code=None, refresh_token=None, config=None):
raise IdentificationError(f'No access token returned for {log_identifier}')
else:
log.info(
'Token returned non-200 status {status} {body} [{code_or_token}]'.format(
code_or_token=log_identifier,
status=response.status_code,
body=response.content,
)
f'Token returned non-200 status {response.status_code} {response.content} '
f'[{log_identifier}]'
)
raise IdentificationError(f'Could not get access token for {log_identifier}')

Expand All @@ -102,9 +99,7 @@ def get_fxa_profile(token):
raise IdentificationError(f'Profile incomplete for {token}')
else:
log.info(
'Profile returned non-200 status {status} {body}'.format(
status=response.status_code, body=response.content
)
f'Profile returned non-200 status {response.status_code} {response.content}'
)
raise IdentificationError(f'Could not find profile for {token}')

Expand Down
8 changes: 4 additions & 4 deletions src/olympia/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,10 +630,10 @@ def post(self, request):
request.session.save()

log.info(
'API user {api_user} created and logged in a user from '
'the super-create API: user_id: {user.pk}; '
'user_name: {user.username}; fxa_id: {user.fxa_id}; '
'group: {group}'.format(user=user, api_user=request.user, group=group)
f'API user {request.user} created and logged in a user from '
f'the super-create API: user_id: {user.pk}; '
f'user_name: {user.username}; fxa_id: {user.fxa_id}; '
f'group: {group}'
)

cookie = {
Expand Down
2 changes: 1 addition & 1 deletion src/olympia/activity/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def has_add_permission(self, request):
return False

def get_form(self, request, obj=None, **kwargs):
form = super(ReviewActionReasonLogAdmin, self).get_form(request, obj, **kwargs)
form = super().get_form(request, obj, **kwargs)
form.base_fields['reason'].widget.can_add_related = False
form.base_fields['reason'].widget.can_change_related = False
form.base_fields['reason'].empty_label = None
Expand Down
20 changes: 7 additions & 13 deletions src/olympia/activity/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,7 @@ def _check_email(
):
subject = call[0][0]
body = call[0][1]
assert subject == 'Mozilla Add-ons: {} {}'.format(
self.addon.name,
self.version.version,
)
assert subject == f'Mozilla Add-ons: {self.addon.name} {self.version.version}'
assert url in body
assert ('receiving this email because %s' % reason_text) in body
assert 'If we do not hear from you within' not in body
Expand Down Expand Up @@ -684,16 +681,13 @@ def test_send_activity_mail():
assert mail.outbox[0].body == message
assert mail.outbox[0].subject == subject
uuid = latest_version.token.get(user=user).uuid.hex
reference_header = '<{addon}/{version}@{site}>'.format(
addon=latest_version.addon.id,
version=latest_version.id,
site=settings.INBOUND_EMAIL_DOMAIN,
reference_header = (
f'<{latest_version.addon.id}/'
f'{latest_version.id}@{settings.INBOUND_EMAIL_DOMAIN}>'
)
message_id = '<{addon}/{version}/{action}@{site}>'.format(
addon=latest_version.addon.id,
version=latest_version.id,
action=action.id,
site=settings.INBOUND_EMAIL_DOMAIN,
message_id = (
f'<{latest_version.addon.id}/'
f'{latest_version.id}/{action.id}@{settings.INBOUND_EMAIL_DOMAIN}>'
)

assert mail.outbox[0].extra_headers['In-Reply-To'] == reference_header
Expand Down
19 changes: 4 additions & 15 deletions src/olympia/activity/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,7 @@ def notify_about_activity_log(

# Not being localised because we don't know the recipients locale.
with translation.override('en-US'):
subject = reviewer_subject = 'Mozilla Add-ons: {} {}'.format(
addon.name,
version.version,
)
subject = reviewer_subject = f'Mozilla Add-ons: {addon.name} {version.version}'
# Build and send the mail for authors.
template = template_from_user(note.user, version)
from_email = formataddr((sender_name, settings.ADDONS_EMAIL))
Expand Down Expand Up @@ -353,12 +350,8 @@ def send_activity_mail(
subject, message, version, recipients, from_email, unique_id, perm_setting=None
):
thread_id = f'{version.addon.id}/{version.id}'
reference_header = '<{thread}@{site}>'.format(
thread=thread_id, site=settings.INBOUND_EMAIL_DOMAIN
)
message_id = '<{thread}/{message}@{site}>'.format(
thread=thread_id, message=unique_id, site=settings.INBOUND_EMAIL_DOMAIN
)
reference_header = f'<{thread_id}@{settings.INBOUND_EMAIL_DOMAIN}>'
message_id = f'<{thread_id}/{unique_id}@{settings.INBOUND_EMAIL_DOMAIN}>'
headers = {
'In-Reply-To': reference_header,
'References': reference_header,
Expand All @@ -373,11 +366,7 @@ def send_activity_mail(
token.update(use_count=0)
else:
log.info(f'Created token with UUID {token.uuid} for user: {recipient.id}.')
reply_to = '{}{}@{}'.format(
REPLY_TO_PREFIX,
token.uuid.hex,
settings.INBOUND_EMAIL_DOMAIN,
)
reply_to = f'{REPLY_TO_PREFIX}{token.uuid.hex}@{settings.INBOUND_EMAIL_DOMAIN}'
log.info(
'Sending activity email to %s for %s version %s'
% (recipient, version.addon.pk, version.pk)
Expand Down
4 changes: 1 addition & 3 deletions src/olympia/addons/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,9 +569,7 @@ def discovery_addon(self, obj):
from olympia.discovery.admin import DiscoveryAddon

url = reverse(
'admin:{}_{}_change'.format(
DiscoveryAddon._meta.app_label, DiscoveryAddon._meta.model_name
),
f'admin:{DiscoveryAddon._meta.app_label}_{DiscoveryAddon._meta.model_name}_change',
args=[obj.pk],
)
return format_html('<a href="{}">Discovery Addon</a>', url)
Expand Down
2 changes: 1 addition & 1 deletion src/olympia/addons/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ def setUp(self):
self.addCleanup(patcher2.stop)
self.download_file_contents_from_backup_storage_mock = patcher2.start()
self.download_file_contents_from_backup_storage_mock.side_effect = lambda nme: (
f'Content for {nme}'.encode('utf-8')
f'Content for {nme}'.encode()
)
patcher3 = mock.patch('olympia.addons.tasks.backup_storage_enabled')
self.addCleanup(patcher3.stop)
Expand Down
20 changes: 6 additions & 14 deletions src/olympia/amo/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,8 @@ def process_failure_signal(
def start_task_timer(task_id, task, **kw):
timer = TaskTimer()
log.info(
'starting task timer; id={id}; name={name}; current_dt={current_dt}'.format(
id=task_id, name=task.name, current_dt=timer.current_datetime
)
f'starting task timer; id={task_id}; name={task.name}; '
f'current_dt={timer.current_datetime}'
)

# Cache start time for one hour. This will allow us to catch crazy long
Expand All @@ -141,21 +140,14 @@ def track_task_run_time(task_id, task, **kw):
start_time = cache.get(timer.cache_key(task_id))
if start_time is None:
log.info(
'could not track task run time; id={id}; name={name}; '
'current_dt={current_dt}'.format(
id=task_id, name=task.name, current_dt=timer.current_datetime
)
f'could not track task run time; id={task_id}; name={task.name}; '
f'current_dt={timer.current_datetime}'
)
else:
run_time = timer.current_epoch_ms - start_time
log.info(
'tracking task run time; id={id}; name={name}; '
'run_time={run_time}; current_dt={current_dt}'.format(
id=task_id,
name=task.name,
current_dt=timer.current_datetime,
run_time=run_time,
)
f'tracking task run time; id={task_id}; name={task.name}; '
f'run_time={run_time}; current_dt={timer.current_datetime}'
)
statsd.timing(f'tasks.{task.name}', run_time)
cache.delete(timer.cache_key(task_id))
Expand Down
4 changes: 1 addition & 3 deletions src/olympia/amo/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ def days_ago(days):
stale_uploads = FileUpload.objects.filter(created__lte=two_weeks_ago).order_by('id')
for file_upload in stale_uploads:
log.info(
'[FileUpload:{uuid}] Removing file: {path}'.format(
uuid=file_upload.uuid, path=file_upload.file_path
)
f'[FileUpload:{file_upload.uuid}] Removing file: {file_upload.file_path}'
)
if file_upload.file_path:
try:
Expand Down
5 changes: 1 addition & 4 deletions src/olympia/amo/templatetags/jinja_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ def url(viewname, *args, **kwargs):
"""Helper for Django's ``reverse`` in templates."""
add_prefix = kwargs.pop('add_prefix', True)
host = kwargs.pop('host', '')
url = '{}{}'.format(
host,
reverse(viewname, args=args, kwargs=kwargs, add_prefix=add_prefix),
)
url = f'{host}{reverse(viewname, args=args, kwargs=kwargs, add_prefix=add_prefix)}'
return url


Expand Down
6 changes: 2 additions & 4 deletions src/olympia/amo/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,7 @@ def prefix_indexes(config):
Note that this is a pytest helper that is primarily used in conftest.
"""
if hasattr(config, 'slaveinput'):
prefix = 'test_{[slaveid]}'.format(config.slaveinput)
prefix = f'test_{config.slaveinput["slaveid"]}'
else:
prefix = 'test'

Expand All @@ -1277,9 +1277,7 @@ def prefix_indexes(config):
# unittest-based setup.
for key, index in settings.ES_INDEXES.items():
if not index.startswith(prefix):
settings.ES_INDEXES[key] = '{prefix}_amo_{index}'.format(
prefix=prefix, index=index
)
settings.ES_INDEXES[key] = f'{prefix}_amo_{index}'


def reverse_ns(viewname, api_version=None, args=None, kwargs=None, **extra):
Expand Down
6 changes: 2 additions & 4 deletions src/olympia/amo/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,8 @@ def test_raises_on_server_error(self):

with (
mock.patch(
(
'olympia.amo.management.commands.generate_js_swagger_files.'
'serve_swagger_ui_js'
)
'olympia.amo.management.commands.generate_js_swagger_files.'
'serve_swagger_ui_js'
) as mock_view,
pytest.raises(CommandError) as error_info,
):
Expand Down
5 changes: 1 addition & 4 deletions src/olympia/amo/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,10 +596,7 @@ def test_version_json(self):
assert result.get('Content-Type') == 'application/json'
assert result.get('Access-Control-Allow-Origin') == '*'
content = result.json()
assert content['python'] == '{}.{}'.format(
sys.version_info.major,
sys.version_info.minor,
)
assert content['python'] == f'{sys.version_info.major}.{sys.version_info.minor}'
assert content['django'] == f'{django.VERSION[0]}.{django.VERSION[1]}'
assert 'addons-linter' in content
assert '.' in content['addons-linter']
Expand Down
Loading
Loading