more passing tests

more f strings done
This commit is contained in:
Jeremy Langley 2022-02-13 08:26:41 -08:00
parent e7ecbf92c4
commit 0bb44a8c0f
7 changed files with 15 additions and 15 deletions

View File

@ -106,7 +106,7 @@ class BasicAuthentication(BaseAuthentication):
return (user, None)
def authenticate_header(self, request):
return 'Basic realm="%s"' % self.www_authenticate_realm
return f'Basic realm="{self.www_authenticate_realm}"'
class SessionAuthentication(BaseAuthentication):
@ -145,7 +145,7 @@ class SessionAuthentication(BaseAuthentication):
reason = check.process_view(request, None, (), {})
if reason:
# CSRF failed, bail with explicit error message
raise exceptions.PermissionDenied('CSRF Failed: %s' % reason)
raise exceptions.PermissionDenied(f'CSRF Failed: {reason}')
class TokenAuthentication(BaseAuthentication):

View File

@ -77,7 +77,7 @@ class _MediaType:
return 3
def __str__(self):
ret = "%s/%s" % (self.main_type, self.sub_type)
ret = f"{self.main_type}/{self.sub_type}"
for key, val in self.params.items():
ret += "; %s=%s" % (key, val.decode('ascii'))
ret += f"; {key}={val.decode('ascii')}"
return ret

View File

@ -19,7 +19,7 @@ def manager_repr(value):
]
for manager_name, manager_instance in names_and_managers:
if manager_instance == value:
return '%s.%s.all()' % (model._meta.object_name, manager_name)
return f'{model._meta.object_name}.{manager_name}.all()'
return repr(value)

View File

@ -88,7 +88,7 @@ def exception_handler(exc, context):
if getattr(exc, 'auth_header', None):
headers['WWW-Authenticate'] = exc.auth_header
if getattr(exc, 'wait', None):
headers['Retry-After'] = '%d' % exc.wait
headers['Retry-After'] = f'{exc.wait}'
if isinstance(exc.detail, (list, dict)):
data = exc.detail

View File

@ -88,17 +88,17 @@ class ViewSetMixin:
# sanitize keyword arguments
for key in initkwargs:
if key in cls.http_method_names:
raise TypeError("You tried to pass in the %s method name as a "
"keyword argument to %s(). Don't do that."
% (key, cls.__name__))
raise TypeError(f"You tried to pass in the {key} method name as a "
f"keyword argument to {cls.__name__}(). Don't do that."
)
if not hasattr(cls, key):
raise TypeError("%s() received an invalid keyword %r" % (
cls.__name__, key))
# name and suffix are mutually exclusive
if 'name' in initkwargs and 'suffix' in initkwargs:
raise TypeError("%s() received both `name` and `suffix`, which are "
"mutually exclusive arguments." % (cls.__name__))
raise TypeError(f"{cls.__name__}() received both `name` and `suffix`, which are "
"mutually exclusive arguments.")
def view(request, *args, **kwargs):
self = cls(**initkwargs)
@ -158,7 +158,7 @@ class ViewSetMixin:
"""
Reverse the action for the given `url_name`.
"""
url_name = '%s-%s' % (self.basename, url_name)
url_name = f'{self.basename}-{url_name}'
namespace = None
if self.request and self.request.resolver_match:
namespace = self.request.resolver_match.namespace

View File

@ -26,7 +26,7 @@ class Bookmark(models.Model):
tags = GenericRelation(Tag)
def __str__(self):
return 'Bookmark: %s' % self.url
return f'Bookmark: {self.url}'
class Note(models.Model):
@ -37,4 +37,4 @@ class Note(models.Model):
tags = GenericRelation(Tag)
def __str__(self):
return 'Note: %s' % self.text
return f'Note: {self.text}'

View File

@ -2310,7 +2310,7 @@ class TestSerializerMethodField:
example_field = serializers.SerializerMethodField()
def get_example_field(self, obj):
return 'ran get_example_field(%d)' % obj['example_field']
return f'ran get_example_field({obj["example_field"]})'
serializer = ExampleSerializer({'example_field': 123})
assert serializer.data == {