def test_upload_import_in_place(factories, mocker): mocker.patch( "funkwhale_api.music.models.Upload.get_audio_data", return_value={ "size": 23, "duration": 42, "bitrate": 66 }, ) track = factories["music.Track"]() path = os.path.join(DATA_DIR, "test.ogg") upload = factories["music.Upload"]( track=None, audio_file=None, source="file://{}".format(path), import_metadata={ "funkwhale": { "track": { "uuid": track.uuid } } }, ) tasks.process_upload(upload_id=upload.pk) upload.refresh_from_db() assert upload.size == 23 assert upload.duration == 42 assert upload.bitrate == 66 assert upload.mimetype == "audio/ogg"
def test_upload_import_get_audio_data(factories, mocker): mocker.patch( "funkwhale_api.music.models.Upload.get_audio_data", return_value={ "size": 23, "duration": 42, "bitrate": 66 }, ) track = factories["music.Track"]() upload = factories["music.Upload"](track=None, import_metadata={ "funkwhale": { "track": { "uuid": track.uuid } } }) tasks.process_upload(upload_id=upload.pk) upload.refresh_from_db() assert upload.size == 23 assert upload.duration == 42 assert upload.bitrate == 66
def test_upload_import(now, factories, temp_signal, mocker): outbox = mocker.patch("funkwhale_api.federation.routes.outbox.dispatch") track = factories["music.Track"]() upload = factories["music.Upload"](track=None, import_metadata={ "funkwhale": { "track": { "uuid": str(track.uuid) } } }) with temp_signal(signals.upload_import_status_updated) as handler: tasks.process_upload(upload_id=upload.pk) upload.refresh_from_db() assert upload.track == track assert upload.import_status == "finished" assert upload.import_date == now handler.assert_called_once_with( upload=upload, old_status="pending", new_status="finished", sender=None, signal=signals.upload_import_status_updated, ) outbox.assert_called_once_with( { "type": "Create", "object": { "type": "Audio" } }, context={"upload": upload})
def test_upload_import_updates_cover_if_no_cover(factories, mocker, now): mocked_update = mocker.patch( "funkwhale_api.music.tasks.update_album_cover") album = factories["music.Album"](cover="") track = factories["music.Track"](album=album) upload = factories["music.Upload"](track=None, import_metadata={ "funkwhale": { "track": { "uuid": track.uuid } } }) tasks.process_upload(upload_id=upload.pk) mocked_update.assert_called_once_with(album, source=None, cover_data=None)
def test_upload_import_skip_existing_track_in_own_library( factories, temp_signal): track = factories["music.Track"]() library = factories["music.Library"]() existing = factories["music.Upload"]( track=track, import_status="finished", library=library, import_metadata={ "funkwhale": { "track": { "uuid": track.mbid } } }, ) duplicate = factories["music.Upload"]( track=track, import_status="pending", library=library, import_metadata={ "funkwhale": { "track": { "uuid": track.uuid } } }, ) with temp_signal(signals.upload_import_status_updated) as handler: tasks.process_upload(upload_id=duplicate.pk) duplicate.refresh_from_db() assert duplicate.import_status == "skipped" assert duplicate.import_details == { "code": "already_imported_in_owned_libraries", "duplicates": [str(existing.uuid)], } handler.assert_called_once_with( upload=duplicate, old_status="pending", new_status="skipped", sender=None, signal=signals.upload_import_status_updated, )
def test_upload_import_track_uuid(now, factories): track = factories["music.Track"]() upload = factories["music.Upload"](track=None, import_metadata={ "funkwhale": { "track": { "uuid": track.uuid } } }) tasks.process_upload(upload_id=upload.pk) upload.refresh_from_db() assert upload.track == track assert upload.import_status == "finished" assert upload.import_date == now
def test_upload_import_skip_federation(now, factories, mocker): outbox = mocker.patch("funkwhale_api.federation.routes.outbox.dispatch") track = factories["music.Track"]() upload = factories["music.Upload"]( track=None, import_metadata={ "funkwhale": { "track": { "uuid": track.uuid }, "config": { "dispatch_outbox": False }, } }, ) tasks.process_upload(upload_id=upload.pk) outbox.assert_not_called()
def test_upload_import_skip_broadcast(now, factories, mocker): group_send = mocker.patch("funkwhale_api.common.channels.group_send") track = factories["music.Track"]() upload = factories["music.Upload"]( library__actor__local=True, track=None, import_metadata={ "funkwhale": { "track": { "uuid": track.uuid }, "config": { "broadcast": False } } }, ) tasks.process_upload(upload_id=upload.pk) group_send.assert_not_called()
def test_upload_import_error(factories, now, temp_signal): upload = factories["music.Upload"](import_metadata={ "funkwhale": { "track": { "uuid": uuid.uuid4() } } }) with temp_signal(signals.upload_import_status_updated) as handler: tasks.process_upload(upload_id=upload.pk) upload.refresh_from_db() assert upload.import_status == "errored" assert upload.import_date == now assert upload.import_details == {"error_code": "track_uuid_not_found"} handler.assert_called_once_with( upload=upload, old_status="pending", new_status="errored", sender=None, signal=signals.upload_import_status_updated, )