refactor: upgrade code to >=python3.7 (pre-commit)
Part-of: <https://dev.funkwhale.audio/funkwhale/funkwhale/-/merge_requests/2189>
This commit is contained in:
parent
7768ea77a4
commit
8d9946d35a
143 changed files with 454 additions and 582 deletions
|
|
@ -665,7 +665,7 @@ def test_rss_feed_item_serializer_create(factories):
|
|||
|
||||
expected_uuid = uuid.uuid3(
|
||||
uuid.NAMESPACE_URL,
|
||||
"rss://{}-16f66fff-41ae-4a1c-9101-2746218c4f32".format(channel.pk),
|
||||
f"rss://{channel.pk}-16f66fff-41ae-4a1c-9101-2746218c4f32",
|
||||
)
|
||||
assert upload.library == channel.library
|
||||
assert upload.import_status == "finished"
|
||||
|
|
@ -692,7 +692,7 @@ def test_rss_feed_item_serializer_update(factories):
|
|||
channel = factories["audio.Channel"](rss_url=rss_url, external=True)
|
||||
expected_uuid = uuid.uuid3(
|
||||
uuid.NAMESPACE_URL,
|
||||
"rss://{}-16f66fff-41ae-4a1c-9101-2746218c4f32".format(channel.pk),
|
||||
f"rss://{channel.pk}-16f66fff-41ae-4a1c-9101-2746218c4f32",
|
||||
)
|
||||
upload = factories["music.Upload"](
|
||||
track__uuid=expected_uuid,
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ def test_channel_detail(attribute, spa_html, no_api_auth, client, factories, set
|
|||
library__privacy_level="everyone", artist__with_cover=True
|
||||
)
|
||||
factories["music.Upload"](playable=True, library=channel.library)
|
||||
url = "/channels/{}".format(utils.recursive_getattr(channel, attribute))
|
||||
detail_url = "/channels/{}".format(channel.actor.full_username)
|
||||
url = f"/channels/{utils.recursive_getattr(channel, attribute)}"
|
||||
detail_url = f"/channels/{channel.actor.full_username}"
|
||||
|
||||
response = client.get(url)
|
||||
|
||||
|
|
@ -44,7 +44,7 @@ def test_channel_detail(attribute, spa_html, no_api_auth, client, factories, set
|
|||
"rel": "alternate",
|
||||
"type": "application/rss+xml",
|
||||
"href": channel.get_rss_url(),
|
||||
"title": "{} - RSS Podcast Feed".format(channel.artist.name),
|
||||
"title": f"{channel.artist.name} - RSS Podcast Feed",
|
||||
},
|
||||
{
|
||||
"tag": "link",
|
||||
|
|
@ -81,8 +81,8 @@ def test_oembed_channel(factories, no_api_auth, api_client, settings):
|
|||
channel = factories["audio.Channel"](artist__with_cover=True)
|
||||
artist = channel.artist
|
||||
url = reverse("api:v1:oembed")
|
||||
obj_url = "https://test.com/channels/{}".format(channel.uuid)
|
||||
iframe_src = "http://embed?type=channel&id={}".format(channel.uuid)
|
||||
obj_url = f"https://test.com/channels/{channel.uuid}"
|
||||
iframe_src = f"http://embed?type=channel&id={channel.uuid}"
|
||||
expected = {
|
||||
"version": "1.0",
|
||||
"type": "rich",
|
||||
|
|
|
|||
|
|
@ -442,7 +442,7 @@ def test_can_filter_channels_through_api_scope(factories, logged_in_api_client):
|
|||
factories["audio.Channel"]()
|
||||
url = reverse("api:v1:channels-list")
|
||||
response = logged_in_api_client.get(
|
||||
url, {"scope": "actor:{}".format(channel.attributed_to.full_username)}
|
||||
url, {"scope": f"actor:{channel.attributed_to.full_username}"}
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ def test_should_verify_email(
|
|||
def test_app_token_authentication(factories, api_request):
|
||||
user = factories["users.User"]()
|
||||
app = factories["users.Application"](user=user, scope="read write")
|
||||
request = api_request.get("/", HTTP_AUTHORIZATION="Bearer {}".format(app.token))
|
||||
request = api_request.get("/", HTTP_AUTHORIZATION=f"Bearer {app.token}")
|
||||
|
||||
auth = authentication.ApplicationTokenAuthentication()
|
||||
assert auth.authenticate(request)[0] == app.user
|
||||
|
|
|
|||
|
|
@ -101,5 +101,5 @@ def test_generic_relation_filter_target_type_and_id(factories):
|
|||
}
|
||||
},
|
||||
)
|
||||
qs = f.filter(note.__class__.objects.all(), "user:{}".format(user.username))
|
||||
qs = f.filter(note.__class__.objects.all(), f"user:{user.username}")
|
||||
assert list(qs) == [note]
|
||||
|
|
|
|||
|
|
@ -31,9 +31,7 @@ def test_mutation_filter_is_approved(value, expected, factories):
|
|||
|
||||
qs = mutations[True].__class__.objects.all()
|
||||
|
||||
filterset = filters.MutationFilter(
|
||||
{"q": "is_approved:{}".format(value)}, queryset=qs
|
||||
)
|
||||
filterset = filters.MutationFilter({"q": f"is_approved:{value}"}, queryset=qs)
|
||||
|
||||
assert list(filterset.qs) == [mutations[expected]]
|
||||
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ def test_get_spa_html_from_http(local_cache, r_mock, mocker, settings):
|
|||
|
||||
assert middleware.get_spa_html("http://test") == "hello world"
|
||||
cache_set.assert_called_once_with(
|
||||
"spa-file:{}:index.html".format(url),
|
||||
f"spa-file:{url}:index.html",
|
||||
"hello world",
|
||||
settings.FUNKWHALE_SPA_HTML_CACHE_DURATION,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ def command():
|
|||
],
|
||||
)
|
||||
def test_script_command_list(command, script_name, mocker):
|
||||
mocked = mocker.patch("funkwhale_api.common.scripts.{}.main".format(script_name))
|
||||
mocked = mocker.patch(f"funkwhale_api.common.scripts.{script_name}.main")
|
||||
|
||||
command.handle(script_name=script_name, interactive=False)
|
||||
|
||||
|
|
@ -168,7 +168,7 @@ def test_migrate_to_user_libraries_update_actors_shared_inbox_url(factories, std
|
|||
def test_migrate_to_user_libraries_generate_actor_urls(
|
||||
factories, part, settings, stdout
|
||||
):
|
||||
field = "{}_url".format(part)
|
||||
field = f"{part}_url"
|
||||
ok = factories["users.User"]().create_actor()
|
||||
local = factories["federation.Actor"](local=True, **{field: None})
|
||||
remote = factories["federation.Actor"](local=False, **{field: None})
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ def test_track_fields_for_update(mocker):
|
|||
|
||||
on_updated_fields = mocker.stub()
|
||||
|
||||
class Obj(object):
|
||||
class Obj:
|
||||
field1 = "value1"
|
||||
field2 = "value2"
|
||||
|
||||
|
|
|
|||
|
|
@ -88,9 +88,7 @@ def test_can_approve_reject_mutation_with_perm(
|
|||
has_perm = mocker.patch(
|
||||
"funkwhale_api.common.mutations.registry.has_perm", return_value=True
|
||||
)
|
||||
url = reverse(
|
||||
"api:v1:mutations-{}".format(endpoint), kwargs={"uuid": mutation.uuid}
|
||||
)
|
||||
url = reverse(f"api:v1:mutations-{endpoint}", kwargs={"uuid": mutation.uuid})
|
||||
|
||||
response = logged_in_api_client.post(url)
|
||||
|
||||
|
|
@ -126,9 +124,7 @@ def test_cannot_approve_reject_applied_mutation(
|
|||
target=track, type="update", payload={}, is_applied=True
|
||||
)
|
||||
mocker.patch("funkwhale_api.common.mutations.registry.has_perm", return_value=True)
|
||||
url = reverse(
|
||||
"api:v1:mutations-{}".format(endpoint), kwargs={"uuid": mutation.uuid}
|
||||
)
|
||||
url = reverse(f"api:v1:mutations-{endpoint}", kwargs={"uuid": mutation.uuid})
|
||||
|
||||
response = logged_in_api_client.post(url)
|
||||
|
||||
|
|
@ -150,9 +146,7 @@ def test_cannot_approve_reject_without_perm(
|
|||
track = factories["music.Track"]()
|
||||
mutation = factories["common.Mutation"](target=track, type="update", payload={})
|
||||
mocker.patch("funkwhale_api.common.mutations.registry.has_perm", return_value=False)
|
||||
url = reverse(
|
||||
"api:v1:mutations-{}".format(endpoint), kwargs={"uuid": mutation.uuid}
|
||||
)
|
||||
url = reverse(f"api:v1:mutations-{endpoint}", kwargs={"uuid": mutation.uuid})
|
||||
|
||||
response = logged_in_api_client.post(url)
|
||||
|
||||
|
|
@ -218,7 +212,7 @@ def test_attachment_proxy_dont_crash_on_long_filename(
|
|||
):
|
||||
long_filename = "a" * 400
|
||||
attachment = factories["common.Attachment"](
|
||||
file=None, url="https://domain/{}.jpg".format(long_filename)
|
||||
file=None, url=f"https://domain/{long_filename}.jpg"
|
||||
)
|
||||
|
||||
avatar_content = avatar.read()
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ from funkwhale_api.users.serializers import UserActivitySerializer
|
|||
def test_get_favorite_activity_url(settings, factories):
|
||||
favorite = factories["favorites.TrackFavorite"]()
|
||||
user_url = favorite.user.get_activity_url()
|
||||
expected = "{}/favorites/tracks/{}".format(user_url, favorite.pk)
|
||||
expected = f"{user_url}/favorites/tracks/{favorite.pk}"
|
||||
assert favorite.get_activity_url() == expected
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -352,7 +352,7 @@ def test_inbox_routing_send_to_channel(factories, mocker):
|
|||
ii.refresh_from_db()
|
||||
|
||||
group_send.assert_called_once_with(
|
||||
"user.{}.inbox".format(ii.actor.user.pk),
|
||||
f"user.{ii.actor.user.pk}.inbox",
|
||||
{
|
||||
"type": "event.send",
|
||||
"text": "",
|
||||
|
|
@ -455,10 +455,10 @@ def test_outbox_router_dispatch_allow_list(mocker, factories, preferences, now):
|
|||
router.connect({"type": "Noop"}, handler)
|
||||
router.dispatch({"type": "Noop"}, {"summary": "hello"})
|
||||
prepare_deliveries_and_inbox_items.assert_any_call(
|
||||
[r1], "to", allowed_domains=set([r1.domain_id])
|
||||
[r1], "to", allowed_domains={r1.domain_id}
|
||||
)
|
||||
prepare_deliveries_and_inbox_items.assert_any_call(
|
||||
[r2], "cc", allowed_domains=set([r1.domain_id])
|
||||
[r2], "cc", allowed_domains={r1.domain_id}
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -579,7 +579,7 @@ def test_prepare_deliveries_and_inbox_items_allow_list(factories, preferences):
|
|||
recipients = [remote_actor1, remote_actor2]
|
||||
|
||||
inbox_items, deliveries, urls = activity.prepare_deliveries_and_inbox_items(
|
||||
recipients, "to", allowed_domains=set([remote_actor1.domain_id])
|
||||
recipients, "to", allowed_domains={remote_actor1.domain_id}
|
||||
)
|
||||
expected_inbox_items = []
|
||||
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ def test_user_cannot_edit_someone_else_library_follow(
|
|||
logged_in_api_client.user.create_actor()
|
||||
follow = factories["federation.LibraryFollow"]()
|
||||
url = reverse(
|
||||
"api:v1:federation:library-follows-{}".format(action),
|
||||
f"api:v1:federation:library-follows-{action}",
|
||||
kwargs={"uuid": follow.uuid},
|
||||
)
|
||||
response = logged_in_api_client.post(url)
|
||||
|
|
@ -111,7 +111,7 @@ def test_user_can_accept_or_reject_own_follows(
|
|||
actor = logged_in_api_client.user.create_actor()
|
||||
follow = factories["federation.LibraryFollow"](target__actor=actor)
|
||||
url = reverse(
|
||||
"api:v1:federation:library-follows-{}".format(action),
|
||||
f"api:v1:federation:library-follows-{action}",
|
||||
kwargs={"uuid": follow.uuid},
|
||||
)
|
||||
response = logged_in_api_client.post(url)
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ def test_authenticate(factories, mocker, api_request):
|
|||
**{
|
||||
"HTTP_DATE": prepared.headers["date"],
|
||||
"HTTP_SIGNATURE": prepared.headers["signature"],
|
||||
}
|
||||
},
|
||||
)
|
||||
authenticator = authentication.SignatureAuthentication()
|
||||
user, _ = authenticator.authenticate(django_request)
|
||||
|
|
@ -52,7 +52,7 @@ def test_authenticate(factories, mocker, api_request):
|
|||
def test_authenticate_skips_blocked_domain(factories, api_request):
|
||||
policy = factories["moderation.InstancePolicy"](block_all=True, for_domain=True)
|
||||
private, public = keys.get_key_pair()
|
||||
actor_url = "https://{}/actor".format(policy.target_domain.name)
|
||||
actor_url = f"https://{policy.target_domain.name}/actor"
|
||||
|
||||
signed_request = factories["federation.SignedRequest"](
|
||||
auth__key=private, auth__key_id=actor_url + "#main-key", auth__headers=["date"]
|
||||
|
|
@ -63,7 +63,7 @@ def test_authenticate_skips_blocked_domain(factories, api_request):
|
|||
**{
|
||||
"HTTP_DATE": prepared.headers["date"],
|
||||
"HTTP_SIGNATURE": prepared.headers["signature"],
|
||||
}
|
||||
},
|
||||
)
|
||||
authenticator = authentication.SignatureAuthentication()
|
||||
|
||||
|
|
@ -85,7 +85,7 @@ def test_authenticate_skips_blocked_actor(factories, api_request):
|
|||
**{
|
||||
"HTTP_DATE": prepared.headers["date"],
|
||||
"HTTP_SIGNATURE": prepared.headers["signature"],
|
||||
}
|
||||
},
|
||||
)
|
||||
authenticator = authentication.SignatureAuthentication()
|
||||
|
||||
|
|
@ -98,7 +98,7 @@ def test_authenticate_ignore_inactive_policy(factories, api_request, mocker):
|
|||
block_all=True, for_domain=True, is_active=False
|
||||
)
|
||||
private, public = keys.get_key_pair()
|
||||
actor_url = "https://{}/actor".format(policy.target_domain.name)
|
||||
actor_url = f"https://{policy.target_domain.name}/actor"
|
||||
|
||||
signed_request = factories["federation.SignedRequest"](
|
||||
auth__key=private, auth__key_id=actor_url + "#main-key", auth__headers=["date"]
|
||||
|
|
@ -126,7 +126,7 @@ def test_authenticate_ignore_inactive_policy(factories, api_request, mocker):
|
|||
**{
|
||||
"HTTP_DATE": prepared.headers["date"],
|
||||
"HTTP_SIGNATURE": prepared.headers["signature"],
|
||||
}
|
||||
},
|
||||
)
|
||||
authenticator = authentication.SignatureAuthentication()
|
||||
authenticator.authenticate(django_request)
|
||||
|
|
@ -169,7 +169,7 @@ def test_autenthicate_supports_blind_key_rotation(factories, mocker, api_request
|
|||
**{
|
||||
"HTTP_DATE": prepared.headers["date"],
|
||||
"HTTP_SIGNATURE": prepared.headers["signature"],
|
||||
}
|
||||
},
|
||||
)
|
||||
authenticator = authentication.SignatureAuthentication()
|
||||
user, _ = authenticator.authenticate(django_request)
|
||||
|
|
@ -186,7 +186,7 @@ def test_authenticate_checks_signature_with_allow_list(
|
|||
preferences["moderation__allow_list_enabled"] = True
|
||||
domain = factories["federation.Domain"](allowed=False)
|
||||
private, public = keys.get_key_pair()
|
||||
actor_url = "https://{}/actor".format(domain.name)
|
||||
actor_url = f"https://{domain.name}/actor"
|
||||
|
||||
signed_request = factories["federation.SignedRequest"](
|
||||
auth__key=private, auth__key_id=actor_url + "#main-key", auth__headers=["date"]
|
||||
|
|
@ -197,7 +197,7 @@ def test_authenticate_checks_signature_with_allow_list(
|
|||
**{
|
||||
"HTTP_DATE": prepared.headers["date"],
|
||||
"HTTP_SIGNATURE": prepared.headers["signature"],
|
||||
}
|
||||
},
|
||||
)
|
||||
authenticator = authentication.SignatureAuthentication()
|
||||
|
||||
|
|
|
|||
|
|
@ -39,9 +39,7 @@ def test_fetches_route_create(factories, api_request, mocker):
|
|||
def test_fetches_route_create_local(factories, api_request, mocker, settings):
|
||||
user = factories["users.User"]()
|
||||
user.create_actor()
|
||||
track = factories["music.Track"](
|
||||
fid="https://{}/test".format(settings.FEDERATION_HOSTNAME)
|
||||
)
|
||||
track = factories["music.Track"](fid=f"https://{settings.FEDERATION_HOSTNAME}/test")
|
||||
view = V.as_view({"post": "fetches"})
|
||||
|
||||
request = api_request.post("/", format="json")
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ def test_cannot_duplicate_follow(factories):
|
|||
|
||||
def test_follow_federation_url(factories):
|
||||
follow = factories["federation.Follow"](local=True)
|
||||
expected = "{}#follows/{}".format(follow.actor.fid, follow.uuid)
|
||||
expected = f"{follow.actor.fid}#follows/{follow.uuid}"
|
||||
|
||||
assert follow.get_federation_id() == expected
|
||||
|
||||
|
|
@ -179,7 +179,7 @@ def test_actor_can_manage_attributed_to(mocker, factories):
|
|||
|
||||
def test_actor_can_manage_domain_not_service_actor(mocker, factories):
|
||||
actor = factories["federation.Actor"]()
|
||||
obj = mocker.Mock(fid="https://{}/hello".format(actor.domain_id))
|
||||
obj = mocker.Mock(fid=f"https://{actor.domain_id}/hello")
|
||||
|
||||
assert actor.can_manage(obj) is False
|
||||
|
||||
|
|
@ -188,7 +188,7 @@ def test_actor_can_manage_domain_service_actor(mocker, factories):
|
|||
actor = factories["federation.Actor"]()
|
||||
actor.domain.service_actor = actor
|
||||
actor.domain.save()
|
||||
obj = mocker.Mock(fid="https://{}/hello".format(actor.domain_id))
|
||||
obj = mocker.Mock(fid=f"https://{actor.domain_id}/hello")
|
||||
|
||||
assert actor.can_manage(obj) is True
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ def test_inbox_routes(route, handler):
|
|||
matching = [
|
||||
handler for r, handler in routes.inbox.routes if activity.match_route(r, route)
|
||||
]
|
||||
assert len(matching) == 1, "Inbox route {} not found".format(route)
|
||||
assert len(matching) == 1, f"Inbox route {route} not found"
|
||||
assert matching[0] == handler
|
||||
|
||||
|
||||
|
|
@ -88,7 +88,7 @@ def test_outbox_routes(route, handler):
|
|||
matching = [
|
||||
handler for r, handler in routes.outbox.routes if activity.match_route(r, route)
|
||||
]
|
||||
assert len(matching) == 1, "Outbox route {} not found".format(route)
|
||||
assert len(matching) == 1, f"Outbox route {route} not found"
|
||||
assert matching[0] == handler
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1940,7 +1940,7 @@ def test_report_serializer_to_ap(factories):
|
|||
"actor": actors.get_service_actor().fid,
|
||||
"content": report.summary,
|
||||
"object": [report.target.fid],
|
||||
"tag": [{"type": "Hashtag", "name": "#{}".format(report.type)}],
|
||||
"tag": [{"type": "Hashtag", "name": f"#{report.type}"}],
|
||||
}
|
||||
serializer = serializers.FlagSerializer(report)
|
||||
assert serializer.data == expected
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ from funkwhale_api.common import utils
|
|||
def test_channel_detail(spa_html, no_api_auth, client, factories, settings):
|
||||
icon = factories["common.Attachment"]()
|
||||
actor = factories["federation.Actor"](local=True, attachment_icon=icon)
|
||||
url = "/@{}".format(actor.preferred_username)
|
||||
url = f"/@{actor.preferred_username}"
|
||||
|
||||
response = client.get(url)
|
||||
|
||||
|
|
|
|||
|
|
@ -214,7 +214,7 @@ def test_update_domain_nodeinfo(factories, mocker, now, service_actor):
|
|||
|
||||
def test_update_domain_nodeinfo_error(factories, r_mock, now):
|
||||
domain = factories["federation.Domain"](nodeinfo_fetch_date=None)
|
||||
wellknown_url = "https://{}/.well-known/nodeinfo".format(domain.name)
|
||||
wellknown_url = f"https://{domain.name}/.well-known/nodeinfo"
|
||||
|
||||
r_mock.get(wellknown_url, status_code=500)
|
||||
|
||||
|
|
@ -225,7 +225,7 @@ def test_update_domain_nodeinfo_error(factories, r_mock, now):
|
|||
assert domain.nodeinfo_fetch_date == now
|
||||
assert domain.nodeinfo == {
|
||||
"status": "error",
|
||||
"error": "500 Server Error: None for url: {}".format(wellknown_url),
|
||||
"error": f"500 Server Error: None for url: {wellknown_url}",
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -406,14 +406,12 @@ def test_fetch_success(factories, r_mock, mocker):
|
|||
|
||||
def test_fetch_webfinger(factories, r_mock, mocker):
|
||||
actor = factories["federation.Actor"]()
|
||||
fetch = factories["federation.Fetch"](
|
||||
url="webfinger://{}".format(actor.full_username)
|
||||
)
|
||||
fetch = factories["federation.Fetch"](url=f"webfinger://{actor.full_username}")
|
||||
payload = serializers.ActorSerializer(actor).data
|
||||
init = mocker.spy(serializers.ActorSerializer, "__init__")
|
||||
save = mocker.spy(serializers.ActorSerializer, "save")
|
||||
webfinger_payload = {
|
||||
"subject": "acct:{}".format(actor.full_username),
|
||||
"subject": f"acct:{actor.full_username}",
|
||||
"aliases": ["https://test.webfinger"],
|
||||
"links": [
|
||||
{"rel": "self", "type": "application/activity+json", "href": actor.fid}
|
||||
|
|
@ -542,7 +540,7 @@ def test_fetch_honor_instance_policy_domain(factories):
|
|||
domain = factories["moderation.InstancePolicy"](
|
||||
block_all=True, for_domain=True
|
||||
).target_domain
|
||||
fid = "https://{}/test".format(domain.name)
|
||||
fid = f"https://{domain.name}/test"
|
||||
|
||||
fetch = factories["federation.Fetch"](url=fid)
|
||||
tasks.fetch(fetch_id=fetch.pk)
|
||||
|
|
@ -588,7 +586,7 @@ def test_fetch_honor_instance_policy_different_url_and_id(r_mock, factories):
|
|||
block_all=True, for_domain=True
|
||||
).target_domain
|
||||
fid = "https://ok/test"
|
||||
r_mock.get(fid, json={"id": "http://{}/test".format(domain.name)})
|
||||
r_mock.get(fid, json={"id": f"http://{domain.name}/test"})
|
||||
fetch = factories["federation.Fetch"](url=fid)
|
||||
tasks.fetch(fetch_id=fetch.pk)
|
||||
fetch.refresh_from_db()
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ def test_retrieve_ap_object_honor_instance_policy_domain(factories):
|
|||
domain = factories["moderation.InstancePolicy"](
|
||||
block_all=True, for_domain=True
|
||||
).target_domain
|
||||
fid = "https://{}/test".format(domain.name)
|
||||
fid = f"https://{domain.name}/test"
|
||||
|
||||
with pytest.raises(exceptions.BlockedActorOrDomain):
|
||||
utils.retrieve_ap_object(fid, actor=None)
|
||||
|
|
@ -106,7 +106,7 @@ def test_retrieve_ap_object_honor_instance_policy_different_url_and_id(
|
|||
block_all=True, for_domain=True
|
||||
).target_domain
|
||||
fid = "https://ok/test"
|
||||
r_mock.get(fid, json={"id": "http://{}/test".format(domain.name)})
|
||||
r_mock.get(fid, json={"id": f"http://{domain.name}/test"})
|
||||
|
||||
with pytest.raises(exceptions.BlockedActorOrDomain):
|
||||
utils.retrieve_ap_object(fid, actor=None)
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ def test_wellknown_webfinger_local(factories, api_client, settings, mocker):
|
|||
url = reverse("federation:well-known-webfinger")
|
||||
response = api_client.get(
|
||||
url,
|
||||
data={"resource": "acct:{}".format(user.actor.webfinger_subject)},
|
||||
data={"resource": f"acct:{user.actor.webfinger_subject}"},
|
||||
HTTP_ACCEPT="application/jrd+json",
|
||||
)
|
||||
serializer = serializers.ActorWebfingerSerializer(user.actor)
|
||||
|
|
@ -327,10 +327,8 @@ def test_music_library_retrieve_page_follow(
|
|||
def test_music_local_entity_detail(
|
||||
factories, api_client, factory, serializer_class, namespace, settings
|
||||
):
|
||||
obj = factories[factory](fid="http://{}/1".format(settings.FEDERATION_HOSTNAME))
|
||||
url = reverse(
|
||||
"federation:music:{}-detail".format(namespace), kwargs={"uuid": obj.uuid}
|
||||
)
|
||||
obj = factories[factory](fid=f"http://{settings.FEDERATION_HOSTNAME}/1")
|
||||
url = reverse(f"federation:music:{namespace}-detail", kwargs={"uuid": obj.uuid})
|
||||
response = api_client.get(url)
|
||||
|
||||
assert response.status_code == 200
|
||||
|
|
@ -345,9 +343,7 @@ def test_music_non_local_entity_detail(
|
|||
factories, api_client, factory, namespace, settings
|
||||
):
|
||||
obj = factories[factory](fid="http://wrong-domain/1")
|
||||
url = reverse(
|
||||
"federation:music:{}-detail".format(namespace), kwargs={"uuid": obj.uuid}
|
||||
)
|
||||
url = reverse(f"federation:music:{namespace}-detail", kwargs={"uuid": obj.uuid})
|
||||
response = api_client.get(url)
|
||||
|
||||
assert response.status_code == 404
|
||||
|
|
@ -539,7 +535,7 @@ def test_artist_retrieve_redirects_to_html_if_header_set(
|
|||
@pytest.mark.parametrize("index", ["channels", "libraries"])
|
||||
def test_public_index_disabled(index, api_client, preferences):
|
||||
preferences["federation__public_index"] = False
|
||||
url = reverse("federation:index:index-{}".format(index))
|
||||
url = reverse(f"federation:index:index-{index}")
|
||||
response = api_client.get(url)
|
||||
|
||||
assert response.status_code == 405
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ def test_webfinger_get_resource(r_mock):
|
|||
],
|
||||
}
|
||||
r_mock.get(
|
||||
"https://test.webfinger/.well-known/webfinger?resource={}".format(resource),
|
||||
f"https://test.webfinger/.well-known/webfinger?resource={resource}",
|
||||
json=payload,
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ from funkwhale_api.users.serializers import UserActivitySerializer
|
|||
def test_get_listening_activity_url(settings, factories):
|
||||
listening = factories["history.Listening"]()
|
||||
user_url = listening.user.get_activity_url()
|
||||
expected = "{}/listenings/tracks/{}".format(user_url, listening.pk)
|
||||
expected = f"{user_url}/listenings/tracks/{listening.pk}"
|
||||
assert listening.get_activity_url() == expected
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -59,10 +59,7 @@ def test_get(mocker):
|
|||
"music_duration",
|
||||
"downloads",
|
||||
]
|
||||
[
|
||||
mocker.patch.object(stats, "get_{}".format(k), return_value=i)
|
||||
for i, k in enumerate(keys)
|
||||
]
|
||||
[mocker.patch.object(stats, f"get_{k}", return_value=i) for i, k in enumerate(keys)]
|
||||
|
||||
expected = {k: i for i, k in enumerate(keys)}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ DATA = {"playable": True}
|
|||
HEADERS = {}
|
||||
if JWT_TOKEN:
|
||||
print("Starting authenticated session")
|
||||
HEADERS["authorization"] = "JWT {}".format(JWT_TOKEN)
|
||||
HEADERS["authorization"] = f"JWT {JWT_TOKEN}"
|
||||
|
||||
|
||||
class WebsiteTasks(TaskSet):
|
||||
|
|
|
|||
|
|
@ -216,9 +216,7 @@ def test_album_list(factories, superuser_api_client, settings):
|
|||
album = factories["music.Album"]()
|
||||
factories["music.Album"]()
|
||||
url = reverse("api:v1:manage:library:albums-list")
|
||||
response = superuser_api_client.get(
|
||||
url, {"q": 'artist:"{}"'.format(album.artist.name)}
|
||||
)
|
||||
response = superuser_api_client.get(url, {"q": f'artist:"{album.artist.name}"'})
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
|
|
|
|||
|
|
@ -23,9 +23,7 @@ def test_report_created_signal_sends_email_to_mods(factories, mailoutbox, settin
|
|||
|
||||
tasks.send_new_report_email_to_moderators(report_id=report.pk)
|
||||
|
||||
detail_url = federation_utils.full_url(
|
||||
"/manage/moderation/reports/{}".format(report.uuid)
|
||||
)
|
||||
detail_url = federation_utils.full_url(f"/manage/moderation/reports/{report.uuid}")
|
||||
unresolved_reports_url = federation_utils.full_url(
|
||||
"/manage/moderation/reports?q=resolved:no"
|
||||
)
|
||||
|
|
@ -56,7 +54,7 @@ def test_signup_request_pending_sends_email_to_mods(factories, mailoutbox, setti
|
|||
tasks.user_request_handle(user_request_id=signup_request.pk, new_status="pending")
|
||||
|
||||
detail_url = federation_utils.full_url(
|
||||
"/manage/moderation/requests/{}".format(signup_request.uuid)
|
||||
f"/manage/moderation/requests/{signup_request.uuid}"
|
||||
)
|
||||
unresolved_requests_url = federation_utils.full_url(
|
||||
"/manage/moderation/requests?q=status:pending"
|
||||
|
|
|
|||
|
|
@ -3,13 +3,13 @@ from funkwhale_api.music import serializers, signals
|
|||
|
||||
def test_get_track_activity_url_mbid(factories):
|
||||
track = factories["music.Track"]()
|
||||
expected = "https://musicbrainz.org/recording/{}".format(track.mbid)
|
||||
expected = f"https://musicbrainz.org/recording/{track.mbid}"
|
||||
assert track.get_activity_url() == expected
|
||||
|
||||
|
||||
def test_get_track_activity_url_no_mbid(settings, factories):
|
||||
track = factories["music.Track"](mbid=None)
|
||||
expected = settings.FUNKWHALE_URL + "/tracks/{}".format(track.pk)
|
||||
expected = settings.FUNKWHALE_URL + f"/tracks/{track.pk}"
|
||||
assert track.get_activity_url() == expected
|
||||
|
||||
|
||||
|
|
@ -23,7 +23,7 @@ def test_upload_import_status_updated_broadcast(factories, mocker):
|
|||
sender=None, upload=upload, old_status="pending", new_status="finished"
|
||||
)
|
||||
group_send.assert_called_once_with(
|
||||
"user.{}.imports".format(user.pk),
|
||||
f"user.{user.pk}.imports",
|
||||
{
|
||||
"type": "event.send",
|
||||
"text": "",
|
||||
|
|
|
|||
|
|
@ -62,14 +62,14 @@ def test_fix_uploads_mimetype(factories, mocker):
|
|||
ogg_path = os.path.join(DATA_DIR, "test.ogg")
|
||||
upload1 = factories["music.Upload"](
|
||||
audio_file__from_path=mp3_path,
|
||||
source="file://{}".format(mp3_path),
|
||||
source=f"file://{mp3_path}",
|
||||
mimetype="application/x-empty",
|
||||
)
|
||||
|
||||
# this one already has a mimetype set, to it should not be updated
|
||||
upload2 = factories["music.Upload"](
|
||||
audio_file__from_path=ogg_path,
|
||||
source="file://{}".format(ogg_path),
|
||||
source=f"file://{ogg_path}",
|
||||
mimetype="audio/something",
|
||||
)
|
||||
c = fix_uploads.Command()
|
||||
|
|
@ -179,7 +179,7 @@ def test_prune_library(factories, mocker):
|
|||
def test_check_inplace_files_dry_run(factories, tmpfile):
|
||||
prunable = factories["music.Upload"](source="file:///notfound", audio_file=None)
|
||||
not_prunable = factories["music.Upload"](
|
||||
source="file://{}".format(tmpfile.name), audio_file=None
|
||||
source=f"file://{tmpfile.name}", audio_file=None
|
||||
)
|
||||
c = check_inplace_files.Command()
|
||||
c.handle(dry_run=True)
|
||||
|
|
@ -192,9 +192,7 @@ def test_check_inplace_files_dry_run(factories, tmpfile):
|
|||
def test_check_inplace_files_no_dry_run(factories, tmpfile):
|
||||
prunable = factories["music.Upload"](source="file:///notfound", audio_file=None)
|
||||
not_prunable = [
|
||||
factories["music.Upload"](
|
||||
source="file://{}".format(tmpfile.name), audio_file=None
|
||||
),
|
||||
factories["music.Upload"](source=f"file://{tmpfile.name}", audio_file=None),
|
||||
factories["music.Upload"](source="upload://"),
|
||||
factories["music.Upload"](source="https://"),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -193,7 +193,7 @@ def test_track_get_file_size(factories):
|
|||
def test_track_get_file_size_in_place(factories):
|
||||
name = "test.mp3"
|
||||
path = os.path.join(DATA_DIR, name)
|
||||
upload = factories["music.Upload"](in_place=True, source="file://{}".format(path))
|
||||
upload = factories["music.Upload"](in_place=True, source=f"file://{path}")
|
||||
|
||||
assert upload.get_file_size() == 297745
|
||||
|
||||
|
|
@ -435,14 +435,14 @@ def test_artist_playable_by_anonymous(privacy_level, expected, factories):
|
|||
|
||||
def test_upload_listen_url(factories):
|
||||
upload = factories["music.Upload"]()
|
||||
expected = upload.track.listen_url + "?upload={}".format(upload.uuid)
|
||||
expected = upload.track.listen_url + f"?upload={upload.uuid}"
|
||||
|
||||
assert upload.listen_url == expected
|
||||
|
||||
|
||||
def test_upload_listen_url_no_download(factories):
|
||||
upload = factories["music.Upload"]()
|
||||
expected = upload.track.listen_url + "?upload={}&download=false".format(upload.uuid)
|
||||
expected = upload.track.listen_url + f"?upload={upload.uuid}&download=false"
|
||||
|
||||
assert upload.listen_url_no_download == expected
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ def test_can_create_artist_from_api(artists, mocker, db):
|
|||
assert artist.mbid, data["id"]
|
||||
assert artist.name, "Adhesive Wombat"
|
||||
assert artist.fid == federation_utils.full_url(
|
||||
"/federation/music/artists/{}".format(artist.uuid)
|
||||
f"/federation/music/artists/{artist.uuid}"
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ def test_can_create_album_from_api(artists, albums, mocker, db):
|
|||
assert album.artist.name, "System of a Down"
|
||||
assert album.artist.mbid, data["artist-credit"][0]["artist"]["id"]
|
||||
assert album.fid == federation_utils.full_url(
|
||||
"/federation/music/albums/{}".format(album.uuid)
|
||||
f"/federation/music/albums/{album.uuid}"
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -70,7 +70,7 @@ def test_can_create_track_from_api(artists, albums, tracks, mocker, db):
|
|||
assert str(track.album.mbid) == "a50d2a81-2a50-484d-9cb4-b9f6833f583e"
|
||||
assert track.album.title == "Marsupial Madness"
|
||||
assert track.fid == federation_utils.full_url(
|
||||
"/federation/music/tracks/{}".format(track.uuid)
|
||||
f"/federation/music/tracks/{track.uuid}"
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ def test_library_track(spa_html, no_api_auth, client, factories, settings):
|
|||
track__album__with_cover=True,
|
||||
)
|
||||
track = upload.track
|
||||
url = "/library/tracks/{}".format(track.pk)
|
||||
url = f"/library/tracks/{track.pk}"
|
||||
|
||||
response = client.get(url)
|
||||
|
||||
|
|
@ -100,7 +100,7 @@ def test_library_album(spa_html, no_api_auth, client, factories, settings):
|
|||
playable=True, track__disc_number=1, track__album__with_cover=True
|
||||
).track
|
||||
album = track.album
|
||||
url = "/library/albums/{}".format(album.pk)
|
||||
url = f"/library/albums/{album.pk}"
|
||||
|
||||
response = client.get(url)
|
||||
|
||||
|
|
@ -167,7 +167,7 @@ def test_library_artist(spa_html, no_api_auth, client, factories, settings):
|
|||
album = factories["music.Album"](with_cover=True)
|
||||
factories["music.Upload"](playable=True, track__album=album)
|
||||
artist = album.artist
|
||||
url = "/library/artists/{}".format(artist.pk)
|
||||
url = f"/library/artists/{artist.pk}"
|
||||
|
||||
response = client.get(url)
|
||||
|
||||
|
|
@ -224,7 +224,7 @@ def test_library_playlist(spa_html, no_api_auth, client, factories, settings):
|
|||
).track
|
||||
playlist.insert_many([track])
|
||||
|
||||
url = "/library/playlists/{}".format(playlist.pk)
|
||||
url = f"/library/playlists/{playlist.pk}"
|
||||
|
||||
response = client.get(url)
|
||||
|
||||
|
|
@ -271,7 +271,7 @@ def test_library_playlist(spa_html, no_api_auth, client, factories, settings):
|
|||
def test_library_playlist_empty(spa_html, no_api_auth, client, factories, settings):
|
||||
playlist = factories["playlists.Playlist"](privacy_level="everyone")
|
||||
|
||||
url = "/library/playlists/{}".format(playlist.pk)
|
||||
url = f"/library/playlists/{playlist.pk}"
|
||||
|
||||
response = client.get(url)
|
||||
|
||||
|
|
@ -293,7 +293,7 @@ def test_library_playlist_empty(spa_html, no_api_auth, client, factories, settin
|
|||
|
||||
def test_library_library(spa_html, no_api_auth, client, factories, settings):
|
||||
library = factories["music.Library"]()
|
||||
url = "/library/{}".format(library.uuid)
|
||||
url = f"/library/{library.uuid}"
|
||||
|
||||
response = client.get(url)
|
||||
|
||||
|
|
|
|||
|
|
@ -390,7 +390,7 @@ def test_upload_import_in_place(factories, mocker):
|
|||
upload = factories["music.Upload"](
|
||||
track=None,
|
||||
audio_file=None,
|
||||
source="file://{}".format(path),
|
||||
source=f"file://{path}",
|
||||
import_metadata={"funkwhale": {"track": {"uuid": track.uuid}}},
|
||||
)
|
||||
|
||||
|
|
@ -564,7 +564,7 @@ def test_populate_album_cover_file_cover_separate_file(
|
|||
ext, mimetype, factories, mocker
|
||||
):
|
||||
mocker.patch("funkwhale_api.music.tasks.IMAGE_TYPES", [(ext, mimetype)])
|
||||
image_path = os.path.join(DATA_DIR, "cover.{}".format(ext))
|
||||
image_path = os.path.join(DATA_DIR, f"cover.{ext}")
|
||||
with open(image_path, "rb") as f:
|
||||
image_content = f.read()
|
||||
album = factories["music.Album"](attachment_cover=None, mbid=None)
|
||||
|
|
@ -775,7 +775,7 @@ def test_scan_page_fetches_page_and_creates_tracks(now, mocker, factories, r_moc
|
|||
scan = factories["music.LibraryScan"](status="scanning", total_files=5)
|
||||
uploads = [
|
||||
factories["music.Upload"](
|
||||
fid="https://track.test/{}".format(i),
|
||||
fid=f"https://track.test/{i}",
|
||||
size=42,
|
||||
bitrate=66,
|
||||
duration=99,
|
||||
|
|
@ -947,7 +947,7 @@ def test_update_library_entity(factories, mocker):
|
|||
],
|
||||
)
|
||||
def test_get_cover_from_fs(name, ext, mimetype, tmpdir):
|
||||
cover_path = os.path.join(tmpdir, "{}.{}".format(name, ext))
|
||||
cover_path = os.path.join(tmpdir, f"{name}.{ext}")
|
||||
content = "Hello"
|
||||
with open(cover_path, "w") as f:
|
||||
f.write(content)
|
||||
|
|
@ -1064,7 +1064,7 @@ def test_process_channel_upload_forces_artist_and_attributed_to(
|
|||
get_track_from_import_metadata.assert_called_once_with(
|
||||
expected_final_metadata,
|
||||
attributed_to=channel.attributed_to,
|
||||
**expected_forced_values
|
||||
**expected_forced_values,
|
||||
)
|
||||
|
||||
assert upload.track.description.content_type == "text/markdown"
|
||||
|
|
|
|||
|
|
@ -459,7 +459,7 @@ def test_stream(factories, logged_in_api_client, mocker, settings):
|
|||
reverse("api:v1:stream-detail", kwargs={"uuid": str(upload.track.uuid)})
|
||||
+ ".mp3"
|
||||
)
|
||||
assert url.endswith("/{}.mp3".format(upload.track.uuid))
|
||||
assert url.endswith(f"/{upload.track.uuid}.mp3")
|
||||
response = logged_in_api_client.get(url)
|
||||
|
||||
assert response.status_code == 200
|
||||
|
|
@ -978,7 +978,7 @@ def test_can_get_libraries_for_music_entities(
|
|||
library=channel.library, playable=True, track=upload.track
|
||||
)
|
||||
|
||||
url = reverse("api:v1:{}s-libraries".format(entity), kwargs={"pk": data[entity].pk})
|
||||
url = reverse(f"api:v1:{entity}s-libraries", kwargs={"pk": data[entity].pk})
|
||||
|
||||
response = api_client.get(url)
|
||||
expected = federation_api_serializers.LibrarySerializer(library).data
|
||||
|
|
@ -1026,8 +1026,8 @@ def test_oembed_track(factories, no_api_auth, api_client, settings):
|
|||
settings.FUNKWHALE_EMBED_URL = "http://embed"
|
||||
track = factories["music.Track"](album__with_cover=True)
|
||||
url = reverse("api:v1:oembed")
|
||||
track_url = "https://test.com/library/tracks/{}".format(track.pk)
|
||||
iframe_src = "http://embed?type=track&id={}".format(track.pk)
|
||||
track_url = f"https://test.com/library/tracks/{track.pk}"
|
||||
iframe_src = f"http://embed?type=track&id={track.pk}"
|
||||
expected = {
|
||||
"version": "1.0",
|
||||
"type": "rich",
|
||||
|
|
@ -1035,7 +1035,7 @@ def test_oembed_track(factories, no_api_auth, api_client, settings):
|
|||
"provider_url": settings.FUNKWHALE_URL,
|
||||
"height": 150,
|
||||
"width": 600,
|
||||
"title": "{} by {}".format(track.title, track.artist.name),
|
||||
"title": f"{track.title} by {track.artist.name}",
|
||||
"description": track.full_name,
|
||||
"thumbnail_url": federation_utils.full_url(
|
||||
track.album.attachment_cover.file.crop["200x200"].url
|
||||
|
|
@ -1062,8 +1062,8 @@ def test_oembed_album(factories, no_api_auth, api_client, settings):
|
|||
track = factories["music.Track"](album__with_cover=True)
|
||||
album = track.album
|
||||
url = reverse("api:v1:oembed")
|
||||
album_url = "https://test.com/library/albums/{}".format(album.pk)
|
||||
iframe_src = "http://embed?type=album&id={}".format(album.pk)
|
||||
album_url = f"https://test.com/library/albums/{album.pk}"
|
||||
iframe_src = f"http://embed?type=album&id={album.pk}"
|
||||
expected = {
|
||||
"version": "1.0",
|
||||
"type": "rich",
|
||||
|
|
@ -1071,8 +1071,8 @@ def test_oembed_album(factories, no_api_auth, api_client, settings):
|
|||
"provider_url": settings.FUNKWHALE_URL,
|
||||
"height": 400,
|
||||
"width": 600,
|
||||
"title": "{} by {}".format(album.title, album.artist.name),
|
||||
"description": "{} by {}".format(album.title, album.artist.name),
|
||||
"title": f"{album.title} by {album.artist.name}",
|
||||
"description": f"{album.title} by {album.artist.name}",
|
||||
"thumbnail_url": federation_utils.full_url(
|
||||
album.attachment_cover.file.crop["200x200"].url
|
||||
),
|
||||
|
|
@ -1099,8 +1099,8 @@ def test_oembed_artist(factories, no_api_auth, api_client, settings):
|
|||
album = track.album
|
||||
artist = track.artist
|
||||
url = reverse("api:v1:oembed")
|
||||
artist_url = "https://test.com/library/artists/{}".format(artist.pk)
|
||||
iframe_src = "http://embed?type=artist&id={}".format(artist.pk)
|
||||
artist_url = f"https://test.com/library/artists/{artist.pk}"
|
||||
iframe_src = f"http://embed?type=artist&id={artist.pk}"
|
||||
expected = {
|
||||
"version": "1.0",
|
||||
"type": "rich",
|
||||
|
|
@ -1138,8 +1138,8 @@ def test_oembed_playlist(factories, no_api_auth, api_client, settings):
|
|||
).track
|
||||
playlist.insert_many([track])
|
||||
url = reverse("api:v1:oembed")
|
||||
playlist_url = "https://test.com/library/playlists/{}".format(playlist.pk)
|
||||
iframe_src = "http://embed?type=playlist&id={}".format(playlist.pk)
|
||||
playlist_url = f"https://test.com/library/playlists/{playlist.pk}"
|
||||
iframe_src = f"http://embed?type=playlist&id={playlist.pk}"
|
||||
expected = {
|
||||
"version": "1.0",
|
||||
"type": "rich",
|
||||
|
|
|
|||
|
|
@ -89,13 +89,13 @@ def test_get_artists_serializer(factories):
|
|||
"id": artist1.pk,
|
||||
"name": artist1.name,
|
||||
"albumCount": 3,
|
||||
"coverArt": "ar-{}".format(artist1.id),
|
||||
"coverArt": f"ar-{artist1.id}",
|
||||
},
|
||||
{
|
||||
"id": artist2.pk,
|
||||
"name": artist2.name,
|
||||
"albumCount": 2,
|
||||
"coverArt": "ar-{}".format(artist2.id),
|
||||
"coverArt": f"ar-{artist2.id}",
|
||||
},
|
||||
],
|
||||
},
|
||||
|
|
@ -106,7 +106,7 @@ def test_get_artists_serializer(factories):
|
|||
"id": artist3.pk,
|
||||
"name": artist3.name,
|
||||
"albumCount": 0,
|
||||
"coverArt": "ar-{}".format(artist3.id),
|
||||
"coverArt": f"ar-{artist3.id}",
|
||||
}
|
||||
],
|
||||
},
|
||||
|
|
@ -129,11 +129,11 @@ def test_get_artist_serializer(factories):
|
|||
"id": artist.pk,
|
||||
"name": artist.name,
|
||||
"albumCount": 1,
|
||||
"coverArt": "ar-{}".format(artist.id),
|
||||
"coverArt": f"ar-{artist.id}",
|
||||
"album": [
|
||||
{
|
||||
"id": album.pk,
|
||||
"coverArt": "al-{}".format(album.id),
|
||||
"coverArt": f"al-{album.id}",
|
||||
"artistId": artist.pk,
|
||||
"name": album.title,
|
||||
"artist": artist.name,
|
||||
|
|
@ -159,7 +159,7 @@ def test_get_artist_serializer(factories):
|
|||
def test_get_track_data_content_type(mimetype, extension, expected, factories):
|
||||
upload = factories["music.Upload"]()
|
||||
upload.mimetype = mimetype
|
||||
upload.audio_file = "test.{}".format(extension)
|
||||
upload.audio_file = f"test.{extension}"
|
||||
|
||||
data = serializers.get_track_data(
|
||||
album=upload.track.album, track=upload.track, upload=upload
|
||||
|
|
@ -182,7 +182,7 @@ def test_get_album_serializer(factories):
|
|||
"songCount": 1,
|
||||
"created": serializers.to_subsonic_date(album.creation_date),
|
||||
"year": album.release_date.year,
|
||||
"coverArt": "al-{}".format(album.id),
|
||||
"coverArt": f"al-{album.id}",
|
||||
"genre": tagged_item.tag.name,
|
||||
"duration": 43,
|
||||
"playCount": album.tracks.aggregate(l=Count("listenings"))["l"] or 0,
|
||||
|
|
@ -191,7 +191,7 @@ def test_get_album_serializer(factories):
|
|||
"id": track.pk,
|
||||
"isDir": "false",
|
||||
"title": track.title,
|
||||
"coverArt": "al-{}".format(album.id),
|
||||
"coverArt": f"al-{album.id}",
|
||||
"album": album.title,
|
||||
"artist": artist.name,
|
||||
"track": track.position,
|
||||
|
|
@ -308,7 +308,7 @@ def test_channel_serializer(factories):
|
|||
"url": channel.rss_url,
|
||||
"title": channel.artist.name,
|
||||
"description": description.as_plain_text,
|
||||
"coverArt": "at-{}".format(channel.artist.attachment_cover.uuid),
|
||||
"coverArt": f"at-{channel.artist.attachment_cover.uuid}",
|
||||
"originalImageUrl": channel.artist.attachment_cover.url,
|
||||
"status": "completed",
|
||||
"episode": [serializers.get_channel_episode_data(upload, channel.uuid)],
|
||||
|
|
@ -333,7 +333,7 @@ def test_channel_episode_serializer(factories):
|
|||
"streamId": upload.track.id,
|
||||
"title": track.title,
|
||||
"description": description.as_plain_text,
|
||||
"coverArt": "at-{}".format(track.attachment_cover.uuid),
|
||||
"coverArt": f"at-{track.attachment_cover.uuid}",
|
||||
"isDir": "false",
|
||||
"year": track.creation_date.year,
|
||||
"created": track.creation_date.isoformat(),
|
||||
|
|
|
|||
|
|
@ -775,7 +775,7 @@ def test_get_cover_art_album(factories, logged_in_api_client):
|
|||
url = reverse("api:subsonic:subsonic-get_cover_art")
|
||||
assert url.endswith("getCoverArt") is True
|
||||
album = factories["music.Album"](with_cover=True)
|
||||
response = logged_in_api_client.get(url, {"id": "al-{}".format(album.pk)})
|
||||
response = logged_in_api_client.get(url, {"id": f"al-{album.pk}"})
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response["Content-Type"] == ""
|
||||
|
|
@ -788,7 +788,7 @@ def test_get_cover_art_attachment(factories, logged_in_api_client):
|
|||
attachment = factories["common.Attachment"]()
|
||||
url = reverse("api:subsonic:subsonic-get_cover_art")
|
||||
assert url.endswith("getCoverArt") is True
|
||||
response = logged_in_api_client.get(url, {"id": "at-{}".format(attachment.uuid)})
|
||||
response = logged_in_api_client.get(url, {"id": f"at-{attachment.uuid}"})
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response["Content-Type"] == ""
|
||||
|
|
|
|||
|
|
@ -52,9 +52,9 @@ def test_import_files_stores_proper_data(factories, mocker, now, path):
|
|||
"import_files", str(library.uuid), path, async_=False, interactive=False
|
||||
)
|
||||
upload = library.uploads.last()
|
||||
assert upload.import_reference == "cli-{}".format(now.isoformat())
|
||||
assert upload.import_reference == f"cli-{now.isoformat()}"
|
||||
assert upload.import_status == "pending"
|
||||
assert upload.source == "file://{}".format(path)
|
||||
assert upload.source == f"file://{path}"
|
||||
assert upload.import_metadata == {
|
||||
"funkwhale": {
|
||||
"config": {"replace": False, "dispatch_outbox": False, "broadcast": False}
|
||||
|
|
@ -131,7 +131,7 @@ def test_import_files_skip_if_path_already_imported(factories, mocker):
|
|||
|
||||
# existing one with same source
|
||||
factories["music.Upload"](
|
||||
library=library, import_status="finished", source="file://{}".format(path)
|
||||
library=library, import_status="finished", source=f"file://{path}"
|
||||
)
|
||||
|
||||
call_command(
|
||||
|
|
@ -165,7 +165,7 @@ def test_storage_rename_utf_8_files(factories):
|
|||
|
||||
@pytest.mark.parametrize("name", ["modified", "moved", "created", "deleted"])
|
||||
def test_handle_event(name, mocker):
|
||||
handler = mocker.patch.object(import_files, "handle_{}".format(name))
|
||||
handler = mocker.patch.object(import_files, f"handle_{name}")
|
||||
|
||||
event = {"type": name}
|
||||
stdout = mocker.Mock()
|
||||
|
|
@ -374,5 +374,5 @@ def test_import_files(factories, capsys):
|
|||
|
||||
imported = library.uploads.filter(import_status="finished").count()
|
||||
assert imported > 0
|
||||
assert "Successfully imported {} new tracks".format(imported) in captured.out
|
||||
assert f"Successfully imported {imported} new tracks" in captured.out
|
||||
assert "For details, please refer to import reference" in captured.out
|
||||
|
|
|
|||
|
|
@ -327,7 +327,7 @@ def test_token_view_post(api_client, factories):
|
|||
|
||||
# Now check we can use the token for auth
|
||||
response = api_client.get(
|
||||
reverse("api:v1:users:users-me"), HTTP_AUTHORIZATION="Bearer {}".format(token)
|
||||
reverse("api:v1:users:users-me"), HTTP_AUTHORIZATION=f"Bearer {token}"
|
||||
)
|
||||
assert response.status_code == 200
|
||||
|
||||
|
|
@ -434,7 +434,7 @@ def test_token_auth(
|
|||
settings.ACCOUNT_EMAIL_VERIFICATION = setting_value
|
||||
response = api_client.get(
|
||||
reverse("api:v1:users:users-me"),
|
||||
HTTP_AUTHORIZATION="Bearer {}".format(token.token),
|
||||
HTTP_AUTHORIZATION=f"Bearer {token.token}",
|
||||
)
|
||||
assert response.status_code == expected_status_code
|
||||
|
||||
|
|
|
|||
|
|
@ -179,8 +179,8 @@ def test_get_channels_groups(factories):
|
|||
user = factories["users.User"](permission_library=True)
|
||||
|
||||
assert user.get_channels_groups() == [
|
||||
"user.{}.imports".format(user.pk),
|
||||
"user.{}.inbox".format(user.pk),
|
||||
f"user.{user.pk}.imports",
|
||||
f"user.{user.pk}.inbox",
|
||||
"admin.library",
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -10,4 +10,4 @@ def to_api_date(value):
|
|||
if isinstance(value, datetime.date):
|
||||
f = rest_fields.DateField()
|
||||
return f.to_representation(value)
|
||||
raise ValueError("Invalid value: {}".format(value))
|
||||
raise ValueError(f"Invalid value: {value}")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue