Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Julien Veyssier
funkwhale
Commits
799386c2
Verified
Commit
799386c2
authored
Jun 10, 2018
by
Eliot Berriot
Browse files
See #297: removed a lot of unused variables
parent
9bea804f
Changes
28
Hide whitespace changes
Inline
Side-by-side
api/funkwhale_api/federation/library.py
View file @
799386c2
...
...
@@ -24,13 +24,6 @@ def scan_from_account_name(account_name):
except
serializers
.
ValidationError
:
return
{
"webfinger"
:
{
"errors"
:
[
"Invalid account string"
]}}
system_library
=
actors
.
SYSTEM_ACTORS
[
"library"
].
get_actor_instance
()
library
=
(
models
.
Library
.
objects
.
filter
(
actor__domain
=
domain
,
actor__preferred_username
=
username
)
.
select_related
(
"actor"
)
.
first
()
)
data
[
"local"
]
=
{
"following"
:
False
,
"awaiting_approval"
:
False
}
try
:
follow
=
models
.
Follow
.
objects
.
get
(
...
...
api/funkwhale_api/federation/views.py
View file @
799386c2
...
...
@@ -21,7 +21,7 @@ from . import (
serializers
,
tasks
,
utils
,
webfinger
webfinger
,
)
...
...
@@ -57,7 +57,7 @@ class InstanceActorViewSet(FederationMixin, viewsets.GenericViewSet):
handler
=
getattr
(
system_actor
,
"{}_inbox"
.
format
(
request
.
method
.
lower
()))
try
:
data
=
handler
(
request
.
data
,
actor
=
request
.
actor
)
handler
(
request
.
data
,
actor
=
request
.
actor
)
except
NotImplementedError
:
return
response
.
Response
(
status
=
405
)
return
response
.
Response
({},
status
=
200
)
...
...
@@ -67,7 +67,7 @@ class InstanceActorViewSet(FederationMixin, viewsets.GenericViewSet):
system_actor
=
self
.
get_object
()
handler
=
getattr
(
system_actor
,
"{}_outbox"
.
format
(
request
.
method
.
lower
()))
try
:
data
=
handler
(
request
.
data
,
actor
=
request
.
actor
)
handler
(
request
.
data
,
actor
=
request
.
actor
)
except
NotImplementedError
:
return
response
.
Response
(
status
=
405
)
return
response
.
Response
({},
status
=
200
)
...
...
api/funkwhale_api/music/management/commands/fix_track_files.py
View file @
799386c2
...
...
@@ -67,8 +67,7 @@ class Command(BaseCommand):
try
:
audio_file
=
tf
.
get_audio_file
()
if
audio_file
:
with
audio_file
as
f
:
data
=
utils
.
get_audio_file_data
(
audio_file
)
data
=
utils
.
get_audio_file_data
(
audio_file
)
tf
.
bitrate
=
data
[
"bitrate"
]
tf
.
duration
=
data
[
"length"
]
tf
.
save
(
update_fields
=
[
"duration"
,
"bitrate"
])
...
...
api/funkwhale_api/music/models.py
View file @
799386c2
...
...
@@ -67,7 +67,7 @@ class APIModelMixin(models.Model):
try
:
cleaned_key
,
cleaned_value
=
mapping
.
from_musicbrainz
(
key
,
value
)
cleaned_data
[
cleaned_key
]
=
cleaned_value
except
KeyError
as
e
:
except
KeyError
:
pass
return
cleaned_data
...
...
@@ -134,9 +134,7 @@ def import_tracks(instance, cleaned_data, raw_data):
track_cleaned_data
=
Track
.
clean_musicbrainz_data
(
track_data
[
"recording"
])
track_cleaned_data
[
"album"
]
=
instance
track_cleaned_data
[
"position"
]
=
int
(
track_data
[
"position"
])
track
=
importers
.
load
(
Track
,
track_cleaned_data
,
track_data
,
Track
.
import_hooks
)
importers
.
load
(
Track
,
track_cleaned_data
,
track_data
,
Track
.
import_hooks
)
class
AlbumQuerySet
(
models
.
QuerySet
):
...
...
api/funkwhale_api/music/views.py
View file @
799386c2
...
...
@@ -457,9 +457,7 @@ class SubmitViewSet(viewsets.ViewSet):
import_request
=
self
.
get_import_request
(
data
)
artist_data
=
api
.
artists
.
get
(
id
=
data
[
"artistId"
])[
"artist"
]
cleaned_data
=
models
.
Artist
.
clean_musicbrainz_data
(
artist_data
)
artist
=
importers
.
load
(
models
.
Artist
,
cleaned_data
,
artist_data
,
import_hooks
=
[]
)
importers
.
load
(
models
.
Artist
,
cleaned_data
,
artist_data
,
import_hooks
=
[])
import_data
=
[]
batch
=
None
...
...
api/tests/activity/test_utils.py
View file @
799386c2
...
...
@@ -11,9 +11,9 @@ def test_get_activity(factories):
def
test_get_activity_honors_privacy_level
(
factories
,
anonymous_user
):
listening
=
factories
[
"history.Listening"
](
user__privacy_level
=
"me"
)
factories
[
"history.Listening"
](
user__privacy_level
=
"me"
)
favorite1
=
factories
[
"favorites.TrackFavorite"
](
user__privacy_level
=
"everyone"
)
favorite2
=
factories
[
"favorites.TrackFavorite"
](
user__privacy_level
=
"instance"
)
factories
[
"favorites.TrackFavorite"
](
user__privacy_level
=
"instance"
)
objects
=
list
(
utils
.
get_activity
(
anonymous_user
))
assert
objects
==
[
favorite1
]
api/tests/activity/test_views.py
View file @
799386c2
...
...
@@ -5,7 +5,7 @@ from funkwhale_api.activity import serializers, utils
def
test_activity_view
(
factories
,
api_client
,
preferences
,
anonymous_user
):
preferences
[
"common__api_authentication_required"
]
=
False
favorite
=
factories
[
"favorites.TrackFavorite"
](
user__privacy_level
=
"everyone"
)
factories
[
"favorites.TrackFavorite"
](
user__privacy_level
=
"everyone"
)
factories
[
"history.Listening"
]()
url
=
reverse
(
"api:v1:activity-list"
)
objects
=
utils
.
get_activity
(
anonymous_user
)
...
...
api/tests/favorites/test_activity.py
View file @
799386c2
...
...
@@ -55,6 +55,5 @@ def test_broadcast_track_favorite_to_instance_activity_private(factories, mocker
favorite
=
factories
[
"favorites.TrackFavorite"
](
user__privacy_level
=
"me"
)
data
=
serializers
.
TrackFavoriteActivitySerializer
(
favorite
).
data
consumer
=
activities
.
broadcast_track_favorite_to_instance_activity
message
=
{
"type"
:
"event.send"
,
"text"
:
""
,
"data"
:
data
}
consumer
(
data
=
data
,
obj
=
favorite
)
p
.
assert_not_called
()
api/tests/federation/test_actors.py
View file @
799386c2
...
...
@@ -48,9 +48,7 @@ def test_get_actor_refresh(factories, preferences, mocker):
payload
=
serializers
.
ActorSerializer
(
actor
).
data
# actor changed their username in the meantime
payload
[
"preferredUsername"
]
=
"New me"
get_data
=
mocker
.
patch
(
"funkwhale_api.federation.actors.get_actor_data"
,
return_value
=
payload
)
mocker
.
patch
(
"funkwhale_api.federation.actors.get_actor_data"
,
return_value
=
payload
)
new_actor
=
actors
.
get_actor
(
actor
.
url
)
assert
new_actor
==
actor
...
...
@@ -59,7 +57,7 @@ def test_get_actor_refresh(factories, preferences, mocker):
def
test_get_library
(
db
,
settings
,
mocker
):
get_key_pair
=
mocker
.
patch
(
mocker
.
patch
(
"funkwhale_api.federation.keys.get_key_pair"
,
return_value
=
(
b
"private"
,
b
"public"
),
)
...
...
@@ -92,7 +90,7 @@ def test_get_library(db, settings, mocker):
def
test_get_test
(
db
,
mocker
,
settings
):
get_key_pair
=
mocker
.
patch
(
mocker
.
patch
(
"funkwhale_api.federation.keys.get_key_pair"
,
return_value
=
(
b
"private"
,
b
"public"
),
)
...
...
@@ -240,7 +238,7 @@ def test_actor_is_system(username, domain, expected, nodb_factories, settings):
(
"test"
,
""
,
actors
.
SYSTEM_ACTORS
[
"test"
]),
],
)
def
test_actor_
is_
system
(
username
,
domain
,
expected
,
nodb_factories
,
settings
):
def
test_actor_system
_conf
(
username
,
domain
,
expected
,
nodb_factories
,
settings
):
if
not
domain
:
domain
=
settings
.
FEDERATION_HOSTNAME
actor
=
nodb_factories
[
"federation.Actor"
](
...
...
api/tests/federation/test_serializers.py
View file @
799386c2
...
...
@@ -162,7 +162,7 @@ def test_follow_serializer_save(factories):
actor
=
factories
[
"federation.Actor"
]()
target
=
factories
[
"federation.Actor"
]()
data
=
expected
=
{
data
=
{
"id"
:
"https://test.follow"
,
"type"
:
"Follow"
,
"actor"
:
actor
.
url
,
...
...
@@ -185,7 +185,7 @@ def test_follow_serializer_save_validates_on_context(factories):
target
=
factories
[
"federation.Actor"
]()
impostor
=
factories
[
"federation.Actor"
]()
data
=
expected
=
{
data
=
{
"id"
:
"https://test.follow"
,
"type"
:
"Follow"
,
"actor"
:
actor
.
url
,
...
...
api/tests/federation/test_tasks.py
View file @
799386c2
...
...
@@ -109,11 +109,11 @@ def test_clean_federation_music_cache_if_no_listen(preferences, factories):
lt1
=
factories
[
"federation.LibraryTrack"
](
with_audio_file
=
True
)
lt2
=
factories
[
"federation.LibraryTrack"
](
with_audio_file
=
True
)
lt3
=
factories
[
"federation.LibraryTrack"
](
with_audio_file
=
True
)
tf1
=
factories
[
"music.TrackFile"
](
accessed_date
=
timezone
.
now
(),
library_track
=
lt1
)
tf2
=
factories
[
"music.TrackFile"
](
factories
[
"music.TrackFile"
](
accessed_date
=
timezone
.
now
(),
library_track
=
lt1
)
factories
[
"music.TrackFile"
](
accessed_date
=
timezone
.
now
()
-
datetime
.
timedelta
(
minutes
=
61
),
library_track
=
lt2
)
tf3
=
factories
[
"music.TrackFile"
](
accessed_date
=
None
,
library_track
=
lt3
)
factories
[
"music.TrackFile"
](
accessed_date
=
None
,
library_track
=
lt3
)
path1
=
lt1
.
audio_file
.
path
path2
=
lt2
.
audio_file
.
path
path3
=
lt3
.
audio_file
.
path
...
...
@@ -144,7 +144,7 @@ def test_clean_federation_music_cache_orphaned(settings, preferences, factories)
lt
=
factories
[
"federation.LibraryTrack"
](
with_audio_file
=
True
,
audio_file__path
=
keep_path
)
tf
=
factories
[
"music.TrackFile"
](
library_track
=
lt
,
accessed_date
=
timezone
.
now
())
factories
[
"music.TrackFile"
](
library_track
=
lt
,
accessed_date
=
timezone
.
now
())
tasks
.
clean_music_cache
()
...
...
api/tests/federation/test_views.py
View file @
799386c2
...
...
@@ -3,7 +3,15 @@ from django.core.paginator import Paginator
from
django.urls
import
reverse
from
django.utils
import
timezone
from
funkwhale_api.federation
import
activity
,
actors
,
models
,
serializers
,
utils
,
views
,
webfinger
from
funkwhale_api.federation
import
(
activity
,
actors
,
models
,
serializers
,
utils
,
views
,
webfinger
,
)
@
pytest
.
mark
.
parametrize
(
...
...
@@ -152,7 +160,7 @@ def test_audio_file_list_actor_page_exclude_federated_files(
db
,
preferences
,
api_client
,
factories
):
preferences
[
"federation__music_needs_approval"
]
=
False
tfs
=
factories
[
"music.TrackFile"
].
create_batch
(
size
=
5
,
federation
=
True
)
factories
[
"music.TrackFile"
].
create_batch
(
size
=
5
,
federation
=
True
)
url
=
reverse
(
"federation:music:files-list"
)
response
=
api_client
.
get
(
url
)
...
...
@@ -265,7 +273,7 @@ def test_can_list_system_actor_following(factories, superuser_api_client):
def
test_can_list_system_actor_followers
(
factories
,
superuser_api_client
):
library_actor
=
actors
.
SYSTEM_ACTORS
[
"library"
].
get_actor_instance
()
follow1
=
factories
[
"federation.Follow"
](
actor
=
library_actor
)
factories
[
"federation.Follow"
](
actor
=
library_actor
)
follow2
=
factories
[
"federation.Follow"
](
target
=
library_actor
)
url
=
reverse
(
"api:v1:federation:libraries-followers"
)
...
...
@@ -375,7 +383,7 @@ def test_can_update_follow_status(factories, superuser_api_client, mocker):
def
test_can_filter_pending_follows
(
factories
,
superuser_api_client
):
library_actor
=
actors
.
SYSTEM_ACTORS
[
"library"
].
get_actor_instance
()
follow
=
factories
[
"federation.Follow"
](
target
=
library_actor
,
approved
=
True
)
factories
[
"federation.Follow"
](
target
=
library_actor
,
approved
=
True
)
params
=
{
"pending"
:
True
}
url
=
reverse
(
"api:v1:federation:libraries-followers"
)
...
...
@@ -389,7 +397,7 @@ def test_library_track_action_import(factories, superuser_api_client, mocker):
lt1
=
factories
[
"federation.LibraryTrack"
]()
lt2
=
factories
[
"federation.LibraryTrack"
](
library
=
lt1
.
library
)
lt3
=
factories
[
"federation.LibraryTrack"
]()
lt4
=
factories
[
"federation.LibraryTrack"
](
library
=
lt3
.
library
)
factories
[
"federation.LibraryTrack"
](
library
=
lt3
.
library
)
mocked_run
=
mocker
.
patch
(
"funkwhale_api.music.tasks.import_batch_run.delay"
)
payload
=
{
...
...
api/tests/history/test_activity.py
View file @
799386c2
...
...
@@ -55,6 +55,5 @@ def test_broadcast_listening_to_instance_activity_private(factories, mocker):
listening
=
factories
[
"history.Listening"
](
user__privacy_level
=
"me"
)
data
=
serializers
.
ListeningActivitySerializer
(
listening
).
data
consumer
=
activities
.
broadcast_listening_to_instance_activity
message
=
{
"type"
:
"event.send"
,
"text"
:
""
,
"data"
:
data
}
consumer
(
data
=
data
,
obj
=
listening
)
p
.
assert_not_called
()
api/tests/history/test_history.py
View file @
799386c2
...
...
@@ -6,7 +6,7 @@ from funkwhale_api.history import models
def
test_can_create_listening
(
factories
):
track
=
factories
[
"music.Track"
]()
user
=
factories
[
"users.User"
]()
l
=
models
.
Listening
.
objects
.
create
(
user
=
user
,
track
=
track
)
models
.
Listening
.
objects
.
create
(
user
=
user
,
track
=
track
)
def
test_logged_in_user_can_create_listening_via_api
(
...
...
@@ -15,7 +15,7 @@ def test_logged_in_user_can_create_listening_via_api(
track
=
factories
[
"music.Track"
]()
url
=
reverse
(
"api:v1:history:listenings-list"
)
response
=
logged_in_client
.
post
(
url
,
{
"track"
:
track
.
pk
})
logged_in_client
.
post
(
url
,
{
"track"
:
track
.
pk
})
listening
=
models
.
Listening
.
objects
.
latest
(
"id"
)
...
...
@@ -29,7 +29,7 @@ def test_adding_listening_calls_activity_record(
track
=
factories
[
"music.Track"
]()
url
=
reverse
(
"api:v1:history:listenings-list"
)
response
=
logged_in_client
.
post
(
url
,
{
"track"
:
track
.
pk
})
logged_in_client
.
post
(
url
,
{
"track"
:
track
.
pk
})
listening
=
models
.
Listening
.
objects
.
latest
(
"id"
)
...
...
api/tests/instance/test_stats.py
View file @
799386c2
from
funkwhale_api.instance
import
stats
...
...
@@ -54,7 +53,7 @@ def test_get(mocker):
"listenings"
,
"music_duration"
,
]
mocks
=
[
[
mocker
.
patch
.
object
(
stats
,
"get_{}"
.
format
(
k
),
return_value
=
i
)
for
i
,
k
in
enumerate
(
keys
)
]
...
...
api/tests/instance/test_views.py
View file @
799386c2
...
...
@@ -11,9 +11,7 @@ def test_permissions(assert_user_permission, view, permissions):
def
test_nodeinfo_endpoint
(
db
,
api_client
,
mocker
):
payload
=
{
"test"
:
"test"
}
mocked_nodeinfo
=
mocker
.
patch
(
"funkwhale_api.instance.nodeinfo.get"
,
return_value
=
payload
)
mocker
.
patch
(
"funkwhale_api.instance.nodeinfo.get"
,
return_value
=
payload
)
url
=
reverse
(
"api:v1:instance:nodeinfo-2.0"
)
response
=
api_client
.
get
(
url
)
ct
=
"application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.0#; charset=utf-8"
# noqa
...
...
api/tests/music/test_api.py
View file @
799386c2
...
...
@@ -47,7 +47,7 @@ def test_import_creates_an_import_with_correct_data(mocker, superuser_client):
mbid
=
"9968a9d6-8d92-4051-8f76-674e157b6eed"
video_id
=
"tPEE9ZwTmy0"
url
=
reverse
(
"api:v1:submit-single"
)
response
=
superuser_client
.
post
(
superuser_client
.
post
(
url
,
{
"import_url"
:
"https://www.youtube.com/watch?v={0}"
.
format
(
video_id
),
...
...
@@ -93,9 +93,7 @@ def test_can_import_whole_album(artists, albums, mocker, superuser_client):
],
}
url
=
reverse
(
"api:v1:submit-album"
)
response
=
superuser_client
.
post
(
url
,
json
.
dumps
(
payload
),
content_type
=
"application/json"
)
superuser_client
.
post
(
url
,
json
.
dumps
(
payload
),
content_type
=
"application/json"
)
batch
=
models
.
ImportBatch
.
objects
.
latest
(
"id"
)
assert
batch
.
jobs
.
count
()
==
3
...
...
@@ -153,9 +151,7 @@ def test_can_import_whole_artist(artists, albums, mocker, superuser_client):
],
}
url
=
reverse
(
"api:v1:submit-artist"
)
response
=
superuser_client
.
post
(
url
,
json
.
dumps
(
payload
),
content_type
=
"application/json"
)
superuser_client
.
post
(
url
,
json
.
dumps
(
payload
),
content_type
=
"application/json"
)
batch
=
models
.
ImportBatch
.
objects
.
latest
(
"id"
)
assert
batch
.
jobs
.
count
()
==
3
...
...
api/tests/music/test_import.py
View file @
799386c2
...
...
@@ -35,9 +35,7 @@ def test_create_import_can_bind_to_request(
],
}
url
=
reverse
(
"api:v1:submit-album"
)
response
=
superuser_api_client
.
post
(
url
,
json
.
dumps
(
payload
),
content_type
=
"application/json"
)
superuser_api_client
.
post
(
url
,
json
.
dumps
(
payload
),
content_type
=
"application/json"
)
batch
=
request
.
import_batches
.
latest
(
"id"
)
assert
batch
.
import_request
==
request
...
...
@@ -160,7 +158,7 @@ def test_import_job_run_triggers_notifies_followers(factories, mocker, tmpfile):
)
batch
=
factories
[
"music.ImportBatch"
]()
job
=
factories
[
"music.ImportJob"
](
finished
=
True
,
batch
=
batch
)
track
=
factories
[
"music.Track"
](
mbid
=
job
.
mbid
)
factories
[
"music.Track"
](
mbid
=
job
.
mbid
)
batch
.
update_status
()
batch
.
refresh_from_db
()
...
...
@@ -193,14 +191,14 @@ def test_import_batch_notifies_followers(factories, mocker):
library_actor
=
actors
.
SYSTEM_ACTORS
[
"library"
].
get_actor_instance
()
f1
=
factories
[
"federation.Follow"
](
approved
=
True
,
target
=
library_actor
)
f2
=
factories
[
"federation.Follow"
](
approved
=
False
,
target
=
library_actor
)
factories
[
"federation.Follow"
](
approved
=
False
,
target
=
library_actor
)
factories
[
"federation.Follow"
]()
mocked_deliver
=
mocker
.
patch
(
"funkwhale_api.federation.activity.deliver"
)
batch
=
factories
[
"music.ImportBatch"
]()
job1
=
factories
[
"music.ImportJob"
](
finished
=
True
,
batch
=
batch
)
job2
=
factories
[
"music.ImportJob"
](
finished
=
True
,
federation
=
True
,
batch
=
batch
)
job3
=
factories
[
"music.ImportJob"
](
status
=
"pending"
,
batch
=
batch
)
factories
[
"music.ImportJob"
](
finished
=
True
,
federation
=
True
,
batch
=
batch
)
factories
[
"music.ImportJob"
](
status
=
"pending"
,
batch
=
batch
)
batch
.
status
=
"finished"
batch
.
save
()
...
...
@@ -233,7 +231,7 @@ def test__do_import_in_place_mbid(factories, tmpfile):
path
=
os
.
path
.
join
(
DATA_DIR
,
"test.ogg"
)
job
=
factories
[
"music.ImportJob"
](
in_place
=
True
,
source
=
"file://{}"
.
format
(
path
))
track
=
factories
[
"music.Track"
](
mbid
=
job
.
mbid
)
factories
[
"music.Track"
](
mbid
=
job
.
mbid
)
tf
=
tasks
.
_do_import
(
job
,
use_acoustid
=
False
)
assert
bool
(
tf
.
audio_file
)
is
False
...
...
api/tests/music/test_models.py
View file @
799386c2
...
...
@@ -104,7 +104,7 @@ def test_saving_job_updates_batch_status(status, factories, mocker):
assert
batch
.
status
==
"pending"
job
=
factories
[
"music.ImportJob"
](
batch
=
batch
,
status
=
status
)
factories
[
"music.ImportJob"
](
batch
=
batch
,
status
=
status
)
batch
.
refresh_from_db
()
...
...
api/tests/music/test_music.py
View file @
799386c2
...
...
@@ -120,7 +120,7 @@ def test_can_get_or_create_track_from_api(artists, albums, tracks, mocker, db):
def
test_album_tags_deduced_from_tracks_tags
(
factories
,
django_assert_num_queries
):
tag
=
factories
[
"taggit.Tag"
]()
album
=
factories
[
"music.Album"
]()
tracks
=
factories
[
"music.Track"
].
create_batch
(
5
,
album
=
album
,
tags
=
[
tag
])
factories
[
"music.Track"
].
create_batch
(
5
,
album
=
album
,
tags
=
[
tag
])
album
=
models
.
Album
.
objects
.
prefetch_related
(
"tracks__tags"
).
get
(
pk
=
album
.
pk
)
...
...
@@ -132,7 +132,7 @@ def test_artist_tags_deduced_from_album_tags(factories, django_assert_num_querie
tag
=
factories
[
"taggit.Tag"
]()
album
=
factories
[
"music.Album"
]()
artist
=
album
.
artist
tracks
=
factories
[
"music.Track"
].
create_batch
(
5
,
album
=
album
,
tags
=
[
tag
])
factories
[
"music.Track"
].
create_batch
(
5
,
album
=
album
,
tags
=
[
tag
])
artist
=
models
.
Artist
.
objects
.
prefetch_related
(
"albums__tracks__tags"
).
get
(
pk
=
artist
.
pk
...
...
Prev
1
2
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment