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
jovuit
funkwhale
Commits
c9259c90
Verified
Commit
c9259c90
authored
Mar 23, 2020
by
Eliot Berriot
Browse files
Faster tests by not creating covers unless mandatory
parent
48681c39
Changes
22
Hide whitespace changes
Inline
Side-by-side
api/funkwhale_api/federation/factories.py
View file @
c9259c90
...
...
@@ -86,6 +86,17 @@ class DomainFactory(NoUpdateOnCreate, factory.django.DjangoModelFactory):
return
self
.
service_actor
_CACHE
=
{}
def
get_cached_key_pair
():
try
:
return
_CACHE
[
"keys"
]
except
KeyError
:
_CACHE
[
"keys"
]
=
keys
.
get_key_pair
()
return
_CACHE
[
"keys"
]
@
registry
.
register
class
ActorFactory
(
NoUpdateOnCreate
,
factory
.
DjangoModelFactory
):
public_key
=
None
...
...
@@ -111,11 +122,14 @@ class ActorFactory(NoUpdateOnCreate, factory.DjangoModelFactory):
o
.
domain
.
name
,
o
.
preferred_username
)
)
keys
=
factory
.
LazyFunction
(
keys
.
get
_key_pair
)
keys
=
factory
.
LazyFunction
(
get_cached
_key_pair
)
class
Meta
:
model
=
models
.
Actor
class
Params
:
with_real_keys
=
factory
.
Trait
(
keys
=
factory
.
LazyFunction
(
keys
.
get_key_pair
),)
@
factory
.
post_generation
def
local
(
self
,
create
,
extracted
,
**
kwargs
):
if
not
extracted
and
not
kwargs
:
...
...
api/funkwhale_api/music/factories.py
View file @
c9259c90
...
...
@@ -64,7 +64,6 @@ class ArtistFactory(
mbid
=
factory
.
Faker
(
"uuid4"
)
fid
=
factory
.
Faker
(
"federation_url"
)
playable
=
playable_factory
(
"track__album__artist"
)
attachment_cover
=
factory
.
SubFactory
(
common_factories
.
AttachmentFactory
)
class
Meta
:
model
=
"music.Artist"
...
...
@@ -74,6 +73,9 @@ class ArtistFactory(
attributed_to
=
factory
.
SubFactory
(
federation_factories
.
ActorFactory
)
)
local
=
factory
.
Trait
(
fid
=
factory
.
Faker
(
"federation_url"
,
local
=
True
))
with_cover
=
factory
.
Trait
(
attachment_cover
=
factory
.
SubFactory
(
common_factories
.
AttachmentFactory
)
)
@
registry
.
register
...
...
@@ -83,7 +85,6 @@ class AlbumFactory(
title
=
factory
.
Faker
(
"sentence"
,
nb_words
=
3
)
mbid
=
factory
.
Faker
(
"uuid4"
)
release_date
=
factory
.
Faker
(
"date_object"
)
attachment_cover
=
factory
.
SubFactory
(
common_factories
.
AttachmentFactory
)
artist
=
factory
.
SubFactory
(
ArtistFactory
)
release_group_id
=
factory
.
Faker
(
"uuid4"
)
fid
=
factory
.
Faker
(
"federation_url"
)
...
...
@@ -100,6 +101,9 @@ class AlbumFactory(
local
=
factory
.
Trait
(
fid
=
factory
.
Faker
(
"federation_url"
,
local
=
True
),
artist__local
=
True
)
with_cover
=
factory
.
Trait
(
attachment_cover
=
factory
.
SubFactory
(
common_factories
.
AttachmentFactory
)
)
@
registry
.
register
...
...
@@ -112,7 +116,6 @@ class TrackFactory(
album
=
factory
.
SubFactory
(
AlbumFactory
)
position
=
1
playable
=
playable_factory
(
"track"
)
attachment_cover
=
factory
.
SubFactory
(
common_factories
.
AttachmentFactory
)
class
Meta
:
model
=
"music.Track"
...
...
@@ -125,6 +128,9 @@ class TrackFactory(
local
=
factory
.
Trait
(
fid
=
factory
.
Faker
(
"federation_url"
,
local
=
True
),
album__local
=
True
)
with_cover
=
factory
.
Trait
(
attachment_cover
=
factory
.
SubFactory
(
common_factories
.
AttachmentFactory
)
)
@
factory
.
post_generation
def
artist
(
self
,
created
,
extracted
,
**
kwargs
):
...
...
api/tests/audio/test_serializers.py
View file @
c9259c90
...
...
@@ -290,6 +290,7 @@ def test_rss_item_serializer(factories):
track__description
=
description
,
track__disc_number
=
4
,
track__position
=
42
,
track__with_cover
=
True
,
)
setattr
(
upload
.
track
,
...
...
@@ -339,6 +340,7 @@ def test_rss_channel_serializer(factories):
artist__set_tags
=
[
"pop"
,
"rock"
],
artist__description
=
description
,
metadata
=
metadata
,
artist__with_cover
=
True
,
)
setattr
(
channel
.
artist
,
...
...
api/tests/audio/test_spa_views.py
View file @
c9259c90
...
...
@@ -11,7 +11,9 @@ from funkwhale_api.music import serializers
@
pytest
.
mark
.
parametrize
(
"attribute"
,
[
"uuid"
,
"actor.full_username"
])
def
test_channel_detail
(
attribute
,
spa_html
,
no_api_auth
,
client
,
factories
,
settings
):
channel
=
factories
[
"audio.Channel"
](
library__privacy_level
=
"everyone"
)
channel
=
factories
[
"audio.Channel"
](
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
)
...
...
@@ -77,7 +79,7 @@ def test_channel_detail(attribute, spa_html, no_api_auth, client, factories, set
def
test_oembed_channel
(
factories
,
no_api_auth
,
api_client
,
settings
):
settings
.
FUNKWHALE_URL
=
"http://test"
settings
.
FUNKWHALE_EMBED_URL
=
"http://embed"
channel
=
factories
[
"audio.Channel"
]()
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
)
...
...
api/tests/audio/test_views.py
View file @
c9259c90
...
...
@@ -55,7 +55,9 @@ def test_channel_create(logged_in_api_client):
"field"
,
[
"uuid"
,
"actor.preferred_username"
,
"actor.full_username"
],
)
def
test_channel_detail
(
field
,
factories
,
logged_in_api_client
):
channel
=
factories
[
"audio.Channel"
](
artist__description
=
None
,
local
=
True
)
channel
=
factories
[
"audio.Channel"
](
artist__description
=
None
,
local
=
True
,
artist__with_cover
=
True
)
url
=
reverse
(
"api:v1:channels-detail"
,
...
...
@@ -74,7 +76,9 @@ def test_channel_detail(field, factories, logged_in_api_client):
def
test_channel_list
(
factories
,
logged_in_api_client
):
channel
=
factories
[
"audio.Channel"
](
artist__description
=
None
)
channel
=
factories
[
"audio.Channel"
](
artist__description
=
None
,
artist__with_cover
=
True
)
setattr
(
channel
.
artist
,
"_tracks_count"
,
0
)
setattr
(
channel
.
artist
,
"_prefetched_tagged_items"
,
[])
url
=
reverse
(
"api:v1:channels-list"
)
...
...
@@ -216,7 +220,9 @@ def test_channel_unsubscribe(factories, logged_in_api_client):
def
test_subscriptions_list
(
factories
,
logged_in_api_client
):
actor
=
logged_in_api_client
.
user
.
create_actor
()
channel
=
factories
[
"audio.Channel"
](
artist__description
=
None
)
channel
=
factories
[
"audio.Channel"
](
artist__description
=
None
,
artist__with_cover
=
True
)
subscription
=
factories
[
"audio.Subscription"
](
target
=
channel
.
actor
,
actor
=
actor
)
setattr
(
subscription
.
target
.
channel
.
artist
,
"_tracks_count"
,
0
)
setattr
(
subscription
.
target
.
channel
.
artist
,
"_prefetched_tagged_items"
,
[])
...
...
api/tests/common/test_models.py
View file @
c9259c90
...
...
@@ -64,7 +64,9 @@ def test_attachment(factories, now):
@
pytest
.
mark
.
parametrize
(
"args, expected"
,
[([],
[
0
]),
([
True
],
[
0
]),
([
False
],
[
1
])])
def
test_attachment_queryset_attached
(
args
,
expected
,
factories
,
queryset_equal_list
):
attachments
=
[
factories
[
"music.Album"
](
artist__attachment_cover
=
None
).
attachment_cover
,
factories
[
"music.Album"
](
with_cover
=
True
,
artist__attachment_cover
=
None
).
attachment_cover
,
factories
[
"common.Attachment"
](),
]
...
...
api/tests/common/test_tasks.py
View file @
c9259c90
...
...
@@ -74,7 +74,7 @@ def test_prune_unattached_attachments(factories, settings, now):
)
attachments
=
[
# attached, kept
factories
[
"music.Album"
]().
attachment_cover
,
factories
[
"music.Album"
](
with_cover
=
True
).
attachment_cover
,
# recent, kept
factories
[
"common.Attachment"
](),
# too old, pruned
...
...
api/tests/common/test_utils.py
View file @
c9259c90
...
...
@@ -141,7 +141,7 @@ def test_render_html(text, content_type, permissive, expected):
def
test_attach_file_url
(
factories
):
album
=
factories
[
"music.Album"
]()
album
=
factories
[
"music.Album"
](
with_cover
=
True
)
existing_attachment
=
album
.
attachment_cover
assert
existing_attachment
is
not
None
...
...
@@ -160,7 +160,7 @@ def test_attach_file_url(factories):
def
test_attach_file_url_fetch
(
factories
,
r_mock
):
album
=
factories
[
"music.Album"
]()
album
=
factories
[
"music.Album"
](
with_cover
=
True
)
data
=
{
"mimetype"
:
"image/jpeg"
,
"url"
:
"https://example.com/test.jpg"
}
r_mock
.
get
(
data
[
"url"
],
body
=
io
.
BytesIO
(
b
"content"
))
...
...
api/tests/favorites/test_favorites.py
View file @
c9259c90
...
...
@@ -29,8 +29,6 @@ def test_user_can_get_his_favorites(
favorite
,
context
=
{
"request"
:
request
}
).
data
]
expected
[
0
][
"track"
][
"artist"
].
pop
(
"cover"
)
expected
[
0
][
"track"
][
"album"
][
"artist"
].
pop
(
"cover"
)
assert
response
.
status_code
==
200
assert
response
.
data
[
"results"
]
==
expected
...
...
api/tests/federation/test_routes.py
View file @
c9259c90
...
...
@@ -321,7 +321,9 @@ def test_outbox_create_audio_channel(factories, mocker):
def
test_inbox_create_audio
(
factories
,
mocker
):
activity
=
factories
[
"federation.Activity"
]()
upload
=
factories
[
"music.Upload"
](
bitrate
=
42
,
duration
=
55
)
upload
=
factories
[
"music.Upload"
](
bitrate
=
42
,
duration
=
55
,
track__album__with_cover
=
True
)
payload
=
{
"@context"
:
jsonld
.
get_default_context
(),
"type"
:
"Create"
,
...
...
api/tests/federation/test_serializers.py
View file @
c9259c90
...
...
@@ -646,7 +646,7 @@ def test_music_library_serializer_from_ap_update(factories, mocker):
def
test_activity_pub_artist_serializer_to_ap
(
factories
):
content
=
factories
[
"common.Content"
]()
artist
=
factories
[
"music.Artist"
](
description
=
content
,
attributed
=
True
,
set_tags
=
[
"Punk"
,
"Rock"
]
description
=
content
,
attributed
=
True
,
set_tags
=
[
"Punk"
,
"Rock"
]
,
with_cover
=
True
)
expected
=
{
"@context"
:
jsonld
.
get_default_context
(),
...
...
@@ -756,7 +756,7 @@ def test_activity_pub_artist_serializer_from_ap_update(factories, faker, now, mo
def
test_activity_pub_album_serializer_to_ap
(
factories
):
content
=
factories
[
"common.Content"
]()
album
=
factories
[
"music.Album"
](
description
=
content
,
attributed
=
True
,
set_tags
=
[
"Punk"
,
"Rock"
]
description
=
content
,
attributed
=
True
,
set_tags
=
[
"Punk"
,
"Rock"
]
,
with_cover
=
True
)
expected
=
{
...
...
@@ -886,6 +886,7 @@ def test_activity_pub_track_serializer_to_ap(factories):
disc_number
=
3
,
attributed
=
True
,
set_tags
=
[
"Punk"
,
"Rock"
],
with_cover
=
True
,
)
expected
=
{
"@context"
:
jsonld
.
get_default_context
(),
...
...
@@ -1210,7 +1211,7 @@ def test_activity_pub_upload_serializer_from_ap(factories, mocker, r_mock):
def
test_activity_pub_upload_serializer_from_ap_update
(
factories
,
mocker
,
now
,
r_mock
):
library
=
factories
[
"music.Library"
]()
upload
=
factories
[
"music.Upload"
](
library
=
library
)
upload
=
factories
[
"music.Upload"
](
library
=
library
,
track__album__with_cover
=
True
)
data
=
{
"@context"
:
jsonld
.
get_default_context
(),
...
...
@@ -1393,7 +1394,9 @@ def test_track_serializer_update_license(factories):
def
test_channel_actor_serializer
(
factories
):
channel
=
factories
[
"audio.Channel"
](
actor__attachment_icon
=
None
)
channel
=
factories
[
"audio.Channel"
](
actor__attachment_icon
=
None
,
artist__with_cover
=
True
)
serializer
=
serializers
.
ActorSerializer
(
channel
.
actor
)
expected_url
=
[
...
...
api/tests/manage/test_serializers.py
View file @
c9259c90
...
...
@@ -286,7 +286,7 @@ def test_instance_policy_serializer_purges_target_actor(
def
test_manage_artist_serializer
(
factories
,
now
,
to_api_date
):
artist
=
factories
[
"music.Artist"
](
attributed
=
True
)
artist
=
factories
[
"music.Artist"
](
attributed
=
True
,
with_cover
=
True
)
track
=
factories
[
"music.Track"
](
artist
=
artist
)
album
=
factories
[
"music.Album"
](
artist
=
artist
)
expected
=
{
...
...
@@ -331,7 +331,7 @@ def test_manage_nested_track_serializer(factories, now, to_api_date):
def
test_manage_nested_album_serializer
(
factories
,
now
,
to_api_date
):
album
=
factories
[
"music.Album"
]()
album
=
factories
[
"music.Album"
](
with_cover
=
True
)
setattr
(
album
,
"tracks_count"
,
44
)
expected
=
{
"id"
:
album
.
id
,
...
...
@@ -367,7 +367,7 @@ def test_manage_nested_artist_serializer(factories, now, to_api_date):
def
test_manage_album_serializer
(
factories
,
now
,
to_api_date
):
album
=
factories
[
"music.Album"
](
attributed
=
True
)
album
=
factories
[
"music.Album"
](
attributed
=
True
,
with_cover
=
True
)
track
=
factories
[
"music.Track"
](
album
=
album
)
expected
=
{
"id"
:
album
.
id
,
...
...
@@ -392,7 +392,7 @@ def test_manage_album_serializer(factories, now, to_api_date):
def
test_manage_track_serializer
(
factories
,
now
,
to_api_date
):
track
=
factories
[
"music.Track"
](
attributed
=
True
)
track
=
factories
[
"music.Track"
](
attributed
=
True
,
with_cover
=
True
)
setattr
(
track
,
"uploads_count"
,
44
)
expected
=
{
"id"
:
track
.
id
,
...
...
api/tests/music/test_mutations.py
View file @
c9259c90
...
...
@@ -182,7 +182,7 @@ def test_perm_checkers_can_approve(
@
pytest
.
mark
.
parametrize
(
"factory_name"
,
[
"music.Artist"
,
"music.Track"
,
"music.Album"
])
def
test_mutation_set_attachment_cover
(
factory_name
,
factories
,
now
,
mocker
):
new_attachment
=
factories
[
"common.Attachment"
](
actor__local
=
True
)
obj
=
factories
[
factory_name
]()
obj
=
factories
[
factory_name
](
with_cover
=
True
)
old_attachment
=
obj
.
attachment_cover
mutation
=
factories
[
"common.Mutation"
](
type
=
"update"
,
target
=
obj
,
payload
=
{
"cover"
:
new_attachment
.
uuid
}
...
...
api/tests/music/test_serializers.py
View file @
c9259c90
...
...
@@ -32,7 +32,7 @@ def test_license_serializer():
def
test_artist_album_serializer
(
factories
,
to_api_date
):
track
=
factories
[
"music.Track"
]()
track
=
factories
[
"music.Track"
](
album__with_cover
=
True
)
album
=
track
.
album
album
=
album
.
__class__
.
objects
.
with_tracks_count
().
get
(
pk
=
album
.
pk
)
expected
=
{
...
...
@@ -55,7 +55,9 @@ def test_artist_album_serializer(factories, to_api_date):
def
test_artist_with_albums_serializer
(
factories
,
to_api_date
):
actor
=
factories
[
"federation.Actor"
]()
track
=
factories
[
"music.Track"
](
album__artist__attributed_to
=
actor
)
track
=
factories
[
"music.Track"
](
album__artist__attributed_to
=
actor
,
album__artist__with_cover
=
True
)
artist
=
track
.
artist
artist
=
artist
.
__class__
.
objects
.
with_albums
().
get
(
pk
=
artist
.
pk
)
album
=
list
(
artist
.
albums
.
all
())[
0
]
...
...
@@ -81,7 +83,7 @@ def test_artist_with_albums_serializer(factories, to_api_date):
def
test_artist_with_albums_serializer_channel
(
factories
,
to_api_date
):
actor
=
factories
[
"federation.Actor"
]()
channel
=
factories
[
"audio.Channel"
](
attributed_to
=
actor
)
channel
=
factories
[
"audio.Channel"
](
attributed_to
=
actor
,
artist__with_cover
=
True
)
track
=
factories
[
"music.Track"
](
album__artist
=
channel
.
artist
)
artist
=
track
.
artist
artist
=
artist
.
__class__
.
objects
.
with_albums
().
get
(
pk
=
artist
.
pk
)
...
...
@@ -195,7 +197,9 @@ def test_upload_owner_serializer(factories, to_api_date):
def
test_album_serializer
(
factories
,
to_api_date
):
actor
=
factories
[
"federation.Actor"
]()
track1
=
factories
[
"music.Track"
](
position
=
2
,
album__attributed_to
=
actor
)
track1
=
factories
[
"music.Track"
](
position
=
2
,
album__attributed_to
=
actor
,
album__with_cover
=
True
)
track2
=
factories
[
"music.Track"
](
position
=
1
,
album
=
track1
.
album
)
album
=
track1
.
album
expected
=
{
...
...
@@ -215,8 +219,6 @@ def test_album_serializer(factories, to_api_date):
}
serializer
=
serializers
.
AlbumSerializer
(
album
)
for
t
in
expected
[
"tracks"
]:
t
[
"artist"
].
pop
(
"cover"
)
assert
serializer
.
data
==
expected
...
...
@@ -236,6 +238,7 @@ def test_track_serializer(factories, to_api_date):
track__copyright
=
"test"
,
track__disc_number
=
2
,
track__attributed_to
=
actor
,
track__with_cover
=
True
,
)
track
=
upload
.
track
setattr
(
track
,
"playable_uploads"
,
[
upload
])
...
...
api/tests/music/test_spa_views.py
View file @
c9259c90
...
...
@@ -8,7 +8,10 @@ from funkwhale_api.music import serializers
def
test_library_track
(
spa_html
,
no_api_auth
,
client
,
factories
,
settings
):
upload
=
factories
[
"music.Upload"
](
playable
=
True
,
track__disc_number
=
1
,
track__attachment_cover
=
None
playable
=
True
,
track__disc_number
=
1
,
track__attachment_cover
=
None
,
track__album__with_cover
=
True
,
)
track
=
upload
.
track
url
=
"/library/tracks/{}"
.
format
(
track
.
pk
)
...
...
@@ -93,7 +96,9 @@ def test_library_track(spa_html, no_api_auth, client, factories, settings):
def
test_library_album
(
spa_html
,
no_api_auth
,
client
,
factories
,
settings
):
track
=
factories
[
"music.Upload"
](
playable
=
True
,
track__disc_number
=
1
).
track
track
=
factories
[
"music.Upload"
](
playable
=
True
,
track__disc_number
=
1
,
track__album__with_cover
=
True
).
track
album
=
track
.
album
url
=
"/library/albums/{}"
.
format
(
album
.
pk
)
...
...
@@ -159,7 +164,7 @@ def test_library_album(spa_html, no_api_auth, client, factories, settings):
def
test_library_artist
(
spa_html
,
no_api_auth
,
client
,
factories
,
settings
):
album
=
factories
[
"music.Album"
]()
album
=
factories
[
"music.Album"
](
with_cover
=
True
)
factories
[
"music.Upload"
](
playable
=
True
,
track__album
=
album
)
artist
=
album
.
artist
url
=
"/library/artists/{}"
.
format
(
artist
.
pk
)
...
...
@@ -214,7 +219,9 @@ def test_library_artist(spa_html, no_api_auth, client, factories, settings):
def
test_library_playlist
(
spa_html
,
no_api_auth
,
client
,
factories
,
settings
):
playlist
=
factories
[
"playlists.Playlist"
](
privacy_level
=
"everyone"
)
track
=
factories
[
"music.Upload"
](
playable
=
True
).
track
track
=
factories
[
"music.Upload"
](
playable
=
True
,
track__album__with_cover
=
True
).
track
playlist
.
insert_many
([
track
])
url
=
"/library/playlists/{}"
.
format
(
playlist
.
pk
)
...
...
api/tests/music/test_tasks.py
View file @
c9259c90
...
...
@@ -379,7 +379,7 @@ def test_upload_import_get_audio_data(factories, mocker):
"funkwhale_api.music.models.Upload.get_audio_data"
,
return_value
=
{
"size"
:
23
,
"duration"
:
42
,
"bitrate"
:
66
},
)
track
=
factories
[
"music.Track"
]()
track
=
factories
[
"music.Track"
](
album__with_cover
=
True
)
upload
=
factories
[
"music.Upload"
](
track
=
None
,
import_metadata
=
{
"funkwhale"
:
{
"track"
:
{
"uuid"
:
track
.
uuid
}}}
)
...
...
@@ -459,7 +459,7 @@ def test_process_upload_picks_ignore_non_pending_uploads(import_status, factorie
def
test_upload_import_track_uuid
(
now
,
factories
):
track
=
factories
[
"music.Track"
]()
track
=
factories
[
"music.Track"
](
album__with_cover
=
True
)
upload
=
factories
[
"music.Upload"
](
track
=
None
,
import_metadata
=
{
"funkwhale"
:
{
"track"
:
{
"uuid"
:
track
.
uuid
}}}
)
...
...
@@ -475,7 +475,7 @@ def test_upload_import_track_uuid(now, factories):
def
test_upload_import_skip_federation
(
now
,
factories
,
mocker
):
outbox
=
mocker
.
patch
(
"funkwhale_api.federation.routes.outbox.dispatch"
)
track
=
factories
[
"music.Track"
]()
track
=
factories
[
"music.Track"
](
album__with_cover
=
True
)
upload
=
factories
[
"music.Upload"
](
track
=
None
,
import_metadata
=
{
...
...
@@ -493,7 +493,7 @@ def test_upload_import_skip_federation(now, factories, mocker):
def
test_upload_import_skip_broadcast
(
now
,
factories
,
mocker
):
group_send
=
mocker
.
patch
(
"funkwhale_api.common.channels.group_send"
)
track
=
factories
[
"music.Track"
]()
track
=
factories
[
"music.Track"
](
album__with_cover
=
True
)
upload
=
factories
[
"music.Upload"
](
library__actor__local
=
True
,
track
=
None
,
...
...
@@ -792,6 +792,7 @@ def test_scan_page_fetches_page_and_creates_tracks(now, mocker, factories, r_moc
bitrate
=
66
,
duration
=
99
,
library
=
scan
.
library
,
track__album__with_cover
=
True
,
)
for
i
in
range
(
5
)
]
...
...
@@ -1019,7 +1020,7 @@ def test_get_track_from_import_metadata_with_forced_values_album(
factories
,
mocker
,
faker
):
channel
=
factories
[
"audio.Channel"
]()
album
=
factories
[
"music.Album"
](
artist
=
channel
.
artist
)
album
=
factories
[
"music.Album"
](
artist
=
channel
.
artist
,
with_cover
=
True
)
forced_values
=
{
"title"
:
"Real title"
,
...
...
@@ -1088,7 +1089,7 @@ def test_process_channel_upload_forces_artist_and_attributed_to(
def
test_process_upload_uses_import_metadata_if_valid
(
factories
,
mocker
):
track
=
factories
[
"music.Track"
]()
track
=
factories
[
"music.Track"
](
album__with_cover
=
True
)
import_metadata
=
{
"title"
:
"hello"
,
"funkwhale"
:
{
"foo"
:
"bar"
}}
upload
=
factories
[
"music.Upload"
](
track
=
None
,
import_metadata
=
import_metadata
)
get_track_from_import_metadata
=
mocker
.
patch
.
object
(
...
...
@@ -1113,7 +1114,7 @@ def test_process_upload_uses_import_metadata_if_valid(factories, mocker):
def
test_process_upload_skips_import_metadata_if_invalid
(
factories
,
mocker
):
track
=
factories
[
"music.Track"
]()
track
=
factories
[
"music.Track"
](
album__with_cover
=
True
)
import_metadata
=
{
"title"
:
None
,
"funkwhale"
:
{
"foo"
:
"bar"
}}
upload
=
factories
[
"music.Upload"
](
track
=
None
,
import_metadata
=
import_metadata
)
get_track_from_import_metadata
=
mocker
.
patch
.
object
(
...
...
api/tests/music/test_views.py
View file @
c9259c90
...
...
@@ -979,7 +979,7 @@ def test_detail_license(api_client, preferences):
def
test_oembed_track
(
factories
,
no_api_auth
,
api_client
,
settings
):
settings
.
FUNKWHALE_URL
=
"http://test"
settings
.
FUNKWHALE_EMBED_URL
=
"http://embed"
track
=
factories
[
"music.Track"
]()
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
)
...
...
@@ -1014,7 +1014,7 @@ def test_oembed_track(factories, no_api_auth, api_client, settings):
def
test_oembed_album
(
factories
,
no_api_auth
,
api_client
,
settings
):
settings
.
FUNKWHALE_URL
=
"http://test"
settings
.
FUNKWHALE_EMBED_URL
=
"http://embed"
track
=
factories
[
"music.Track"
]()
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
)
...
...
@@ -1050,7 +1050,7 @@ def test_oembed_album(factories, no_api_auth, api_client, settings):
def
test_oembed_artist
(
factories
,
no_api_auth
,
api_client
,
settings
):
settings
.
FUNKWHALE_URL
=
"http://test"
settings
.
FUNKWHALE_EMBED_URL
=
"http://embed"
track
=
factories
[
"music.Track"
]()
track
=
factories
[
"music.Track"
](
album__with_cover
=
True
)
album
=
track
.
album
artist
=
track
.
artist
url
=
reverse
(
"api:v1:oembed"
)
...
...
@@ -1088,7 +1088,9 @@ def test_oembed_playlist(factories, no_api_auth, api_client, settings):
settings
.
FUNKWHALE_URL
=
"http://test"
settings
.
FUNKWHALE_EMBED_URL
=
"http://embed"
playlist
=
factories
[
"playlists.Playlist"
](
privacy_level
=
"everyone"
)
track
=
factories
[
"music.Upload"
](
playable
=
True
).
track
track
=
factories
[
"music.Upload"
](
playable
=
True
,
track__album__with_cover
=
True
).
track
playlist
.
insert_many
([
track
])
url
=
reverse
(
"api:v1:oembed"
)
playlist_url
=
"https://test.com/library/playlists/{}"
.
format
(
playlist
.
pk
)
...
...
@@ -1307,12 +1309,6 @@ def test_search_get(use_fts, settings, logged_in_api_client, factories):
"tracks"
:
[
serializers
.
TrackSerializer
(
track
).
data
],
"tags"
:
[
views
.
TagSerializer
(
tag
).
data
],
}
for
album
in
expected
[
"albums"
]:
album
[
"artist"
].
pop
(
"cover"
)
for
track
in
expected
[
"tracks"
]:
track
[
"artist"
].
pop
(
"cover"
)
track
[
"album"
][
"artist"
].
pop
(
"cover"
)
response
=
logged_in_api_client
.
get
(
url
,
{
"q"
:
"foo"
})
...
...
@@ -1380,7 +1376,7 @@ def test_detail_includes_description_key(
def
test_channel_owner_can_create_album
(
factories
,
logged_in_api_client
):
actor
=
logged_in_api_client
.
user
.
create_actor
()
channel
=
factories
[
"audio.Channel"
](
attributed_to
=
actor
)
channel
=
factories
[
"audio.Channel"
](
attributed_to
=
actor
,
artist__with_cover
=
True
)
attachment
=
factories
[
"common.Attachment"
](
actor
=
actor
)
url
=
reverse
(
"api:v1:albums-list"
)
...
...
api/tests/playlists/test_serializers.py
View file @
c9259c90
...
...
@@ -93,13 +93,13 @@ def test_update_insert_is_called_with_duplicate_override_when_duplicates_allowed
def
test_playlist_serializer_include_covers
(
factories
,
api_request
):
playlist
=
factories
[
"playlists.Playlist"
]()
t1
=
factories
[
"music.Track"
]()
t2
=
factories
[
"music.Track"
]()
t1
=
factories
[
"music.Track"
](
album__with_cover
=
True
)
t2
=
factories
[
"music.Track"
](
album__with_cover
=
True
)
t3
=
factories
[
"music.Track"
](
album__attachment_cover
=
None
)
t4
=
factories
[
"music.Track"
]()
t5
=
factories
[
"music.Track"
]()
t6
=
factories
[
"music.Track"
]()
t7
=
factories
[
"music.Track"
]()
t4
=
factories
[
"music.Track"
](
album__with_cover
=
True
)
t5
=
factories
[
"music.Track"
](
album__with_cover
=
True
)
t6
=
factories
[
"music.Track"
](
album__with_cover
=
True
)
t7
=
factories
[
"music.Track"
](
album__with_cover
=
True
)
playlist
.
insert_many
([
t1
,
t2
,
t3
,
t4
,
t5
,
t6
,
t7
])
request
=
api_request
.
get
(
"/"
)
...
...
api/tests/playlists/test_views.py
View file @
c9259c90
...
...
@@ -157,8 +157,6 @@ def test_can_list_tracks_from_playlist(level, factories, logged_in_api_client):
url
=
reverse
(
"api:v1:playlists-tracks"
,
kwargs
=
{
"pk"
:
plt
.
playlist
.
pk
})
response
=
logged_in_api_client
.
get
(
url
)
serialized_plt
=
serializers
.
PlaylistTrackSerializer
(
plt
).
data
serialized_plt
[
"track"
][
"artist"
].
pop
(
"cover"
)
serialized_plt
[
"track"
][
"album"
][
"artist"
].
pop
(
"cover"
)
assert
response
.
data
[
"count"
]
==
1
assert
response
.
data
[
"results"
][
0
]
==
serialized_plt
...
...
api/tests/radios/test_api.py
View file @
c9259c90
...
...
@@ -36,8 +36,6 @@ def test_can_validate_config(logged_in_api_client, factories):
"count"
:
candidates
.
count
(),
"sample"
:
TrackSerializer
(
candidates
,
many
=
True
).
data
,
}
for
s
in
expected
[
"sample"
]:
s
[
"artist"
].
pop
(
"cover"
)
assert
payload
[
"filters"
][
0
][
"candidates"
]
==
expected
assert
payload
[
"filters"
][
0
][
"errors"
]
==
[]
...
...
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