chore: add pyupgrade pre-commit hook
- add --py3-plus flag to pyupgrade hook - add --py36-plus flag to pyupgrade hook
This commit is contained in:
parent
21aaf9bca1
commit
32cb67806a
26 changed files with 90 additions and 86 deletions
|
@ -60,7 +60,7 @@ class User(AbstractBaseUser):
|
|||
objects = UserManager()
|
||||
|
||||
def get_full_name(self):
|
||||
return "{} {}".format(self.first_name, self.last_name)
|
||||
return f"{self.first_name} {self.last_name}"
|
||||
|
||||
def get_short_name(self):
|
||||
return self.first_name
|
||||
|
|
|
@ -38,7 +38,7 @@ def get_permission_for_view(request, view):
|
|||
try:
|
||||
permission_type = REQUEST_PERMISSION_TYPE_MAP[request.method]
|
||||
if view.__class__.__name__ == "APIRootView":
|
||||
return "{}_apiroot".format(permission_type)
|
||||
return f"{permission_type}_apiroot"
|
||||
model = view.model_permission_name
|
||||
own_obj = get_own_obj(request, view)
|
||||
return "{permission_type}_{own_obj}{model}".format(
|
||||
|
|
|
@ -14,10 +14,10 @@ class ManagedModelTestRunner(DiscoverRunner):
|
|||
self.unmanaged_models = [m for m in apps.get_models() if not m._meta.managed]
|
||||
for m in self.unmanaged_models:
|
||||
m._meta.managed = True
|
||||
super(ManagedModelTestRunner, self).setup_test_environment(*args, **kwargs)
|
||||
super().setup_test_environment(*args, **kwargs)
|
||||
|
||||
def teardown_test_environment(self, *args, **kwargs):
|
||||
super(ManagedModelTestRunner, self).teardown_test_environment(*args, **kwargs)
|
||||
super().teardown_test_environment(*args, **kwargs)
|
||||
# reset unmanaged models
|
||||
for m in self.unmanaged_models:
|
||||
m._meta.managed = False
|
||||
|
|
|
@ -28,7 +28,7 @@ class TestIsSystemTokenOrUser(APITestCase):
|
|||
token = "doesnotexist"
|
||||
request = APIRequestFactory().get(self.path)
|
||||
request.user = AnonymousUser()
|
||||
request.META["Authorization"] = "Api-Key {token}".format(token=token)
|
||||
request.META["Authorization"] = f"Api-Key {token}"
|
||||
allowed = IsSystemTokenOrUser().has_permission(request, None)
|
||||
self.assertFalse(allowed)
|
||||
|
||||
|
@ -36,7 +36,7 @@ class TestIsSystemTokenOrUser(APITestCase):
|
|||
token = settings.CONFIG.get("general", "api_key")
|
||||
request = APIRequestFactory().get(self.path)
|
||||
request.user = AnonymousUser()
|
||||
request.META["Authorization"] = "Api-Key {token}".format(token=token)
|
||||
request.META["Authorization"] = f"Api-Key {token}"
|
||||
allowed = IsSystemTokenOrUser().has_permission(request, None)
|
||||
self.assertTrue(allowed)
|
||||
|
||||
|
@ -81,7 +81,7 @@ class TestPermissions(APITestCase):
|
|||
for model in self.URLS:
|
||||
response = self.logged_in_test_model(model, "guest", GUEST, self.client.get)
|
||||
self.assertEqual(
|
||||
response.status_code, 200, msg="Invalid for model {}".format(model)
|
||||
response.status_code, 200, msg=f"Invalid for model {model}"
|
||||
)
|
||||
|
||||
def test_guest_permissions_failure(self):
|
||||
|
@ -90,14 +90,14 @@ class TestPermissions(APITestCase):
|
|||
model, "guest", GUEST, self.client.post
|
||||
)
|
||||
self.assertEqual(
|
||||
response.status_code, 403, msg="Invalid for model {}".format(model)
|
||||
response.status_code, 403, msg=f"Invalid for model {model}"
|
||||
)
|
||||
|
||||
def test_dj_get_permissions(self):
|
||||
for model in self.URLS:
|
||||
response = self.logged_in_test_model(model, "dj", DJ, self.client.get)
|
||||
self.assertEqual(
|
||||
response.status_code, 200, msg="Invalid for model {}".format(model)
|
||||
response.status_code, 200, msg=f"Invalid for model {model}"
|
||||
)
|
||||
|
||||
def test_dj_post_permissions(self):
|
||||
|
@ -110,7 +110,7 @@ class TestPermissions(APITestCase):
|
|||
last_name="user",
|
||||
)
|
||||
f = baker.make("libretime_api.File", owner=user)
|
||||
model = "files/{}".format(f.id)
|
||||
model = f"files/{f.id}"
|
||||
path = self.path.format(model)
|
||||
self.client.login(username="test-dj", password="test")
|
||||
response = self.client.patch(path, {"name": "newFilename"})
|
||||
|
@ -126,7 +126,7 @@ class TestPermissions(APITestCase):
|
|||
last_name="user",
|
||||
)
|
||||
f = baker.make("libretime_api.File")
|
||||
model = "files/{}".format(f.id)
|
||||
model = f"files/{f.id}"
|
||||
path = self.path.format(model)
|
||||
self.client.login(username="test-dj", password="test")
|
||||
response = self.client.patch(path, {"name": "newFilename"})
|
||||
|
|
|
@ -18,13 +18,13 @@ class TestFileViewSet(APITestCase):
|
|||
|
||||
def test_invalid(self):
|
||||
path = self.path.format(id="a")
|
||||
self.client.credentials(HTTP_AUTHORIZATION="Api-Key {}".format(self.token))
|
||||
self.client.credentials(HTTP_AUTHORIZATION=f"Api-Key {self.token}")
|
||||
response = self.client.get(path)
|
||||
self.assertEqual(response.status_code, 400)
|
||||
|
||||
def test_does_not_exist(self):
|
||||
path = self.path.format(id="1")
|
||||
self.client.credentials(HTTP_AUTHORIZATION="Api-Key {}".format(self.token))
|
||||
self.client.credentials(HTTP_AUTHORIZATION=f"Api-Key {self.token}")
|
||||
response = self.client.get(path)
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
|
@ -40,7 +40,7 @@ class TestFileViewSet(APITestCase):
|
|||
filepath="song.mp3",
|
||||
)
|
||||
path = self.path.format(id=str(f.pk))
|
||||
self.client.credentials(HTTP_AUTHORIZATION="Api-Key {}".format(self.token))
|
||||
self.client.credentials(HTTP_AUTHORIZATION=f"Api-Key {self.token}")
|
||||
response = self.client.get(path)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
|
@ -78,7 +78,7 @@ class TestScheduleViewSet(APITestCase):
|
|||
instance=show,
|
||||
file=f,
|
||||
)
|
||||
self.client.credentials(HTTP_AUTHORIZATION="Api-Key {}".format(self.token))
|
||||
self.client.credentials(HTTP_AUTHORIZATION=f"Api-Key {self.token}")
|
||||
response = self.client.get(self.path)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
result = response.json()
|
||||
|
@ -111,7 +111,7 @@ class TestScheduleViewSet(APITestCase):
|
|||
instance=show,
|
||||
file=f,
|
||||
)
|
||||
self.client.credentials(HTTP_AUTHORIZATION="Api-Key {}".format(self.token))
|
||||
self.client.credentials(HTTP_AUTHORIZATION=f"Api-Key {self.token}")
|
||||
response = self.client.get(self.path)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
result = response.json()
|
||||
|
@ -157,7 +157,7 @@ class TestScheduleViewSet(APITestCase):
|
|||
instance=show,
|
||||
file=f,
|
||||
)
|
||||
self.client.credentials(HTTP_AUTHORIZATION="Api-Key {}".format(self.token))
|
||||
self.client.credentials(HTTP_AUTHORIZATION=f"Api-Key {self.token}")
|
||||
response = self.client.get(self.path, {"is_valid": True})
|
||||
self.assertEqual(response.status_code, 200)
|
||||
result = response.json()
|
||||
|
@ -203,13 +203,13 @@ class TestScheduleViewSet(APITestCase):
|
|||
instance=show,
|
||||
file=f,
|
||||
)
|
||||
self.client.credentials(HTTP_AUTHORIZATION="Api-Key {}".format(self.token))
|
||||
self.client.credentials(HTTP_AUTHORIZATION=f"Api-Key {self.token}")
|
||||
range_start = (filter_point - timedelta(minutes=1)).isoformat(
|
||||
timespec="seconds"
|
||||
)
|
||||
range_end = (filter_point + timedelta(minutes=1)).isoformat(timespec="seconds")
|
||||
response = self.client.get(
|
||||
self.path, {"starts__range": "{},{}".format(range_start, range_end)}
|
||||
self.path, {"starts__range": f"{range_start},{range_end}"}
|
||||
)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
result = response.json()
|
||||
|
|
|
@ -10,7 +10,7 @@ def read_config_file(config_filepath):
|
|||
try:
|
||||
with open(config_filepath, encoding="utf-8") as config_file:
|
||||
config.read_file(config_file)
|
||||
except IOError as error:
|
||||
except OSError as error:
|
||||
print(
|
||||
f"Unable to read config file at {config_filepath}: {error.strerror}",
|
||||
file=sys.stderr,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue