Fixed: DownloadedTrackScan API should delete source folder if ImportMode is Move

pull/6/head
Qstick 7 years ago
parent f219e883ec
commit 12d89b9ab5

@ -7,6 +7,7 @@ using Moq;
using NUnit.Framework;
using NzbDrone.Common.Disk;
using NzbDrone.Core.Download;
using NzbDrone.Core.Download.TrackedDownloads;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.TrackImport;
using NzbDrone.Core.Parser;
@ -25,6 +26,8 @@ namespace NzbDrone.Core.Test.MediaFiles
private string[] _subFolders = new[] { "c:\\root\\foldername".AsOsAgnostic() };
private string[] _videoFiles = new[] { "c:\\root\\foldername\\30.rock.s01e01.ext".AsOsAgnostic() };
private TrackedDownload _trackedDownload;
[SetUp]
public void Setup()
{
@ -43,6 +46,23 @@ namespace NzbDrone.Core.Test.MediaFiles
Mocker.GetMock<IImportApprovedTracks>()
.Setup(s => s.Import(It.IsAny<List<ImportDecision>>(), true, null, ImportMode.Auto))
.Returns(new List<ImportResult>());
var downloadItem = Builder<DownloadClientItem>.CreateNew()
.With(v => v.DownloadId = "sab1")
.With(v => v.Status = DownloadItemStatus.Downloading)
.Build();
var remoteAlbum = Builder<RemoteAlbum>.CreateNew()
.With(v => v.Artist = new Artist())
.Build();
_trackedDownload = new TrackedDownload
{
DownloadItem = downloadItem,
RemoteAlbum = remoteAlbum,
State = TrackedDownloadStage.Downloading
};
}
private void GivenValidArtist()
@ -52,6 +72,29 @@ namespace NzbDrone.Core.Test.MediaFiles
.Returns(Builder<Artist>.CreateNew().Build());
}
private void GivenSuccessfulImport()
{
var localTrack = new LocalTrack();
var imported = new List<ImportDecision>();
imported.Add(new ImportDecision(localTrack));
Mocker.GetMock<IMakeImportDecision>()
.Setup(s => s.GetImportDecisions(It.IsAny<List<string>>(), It.IsAny<Artist>(), null))
.Returns(imported);
Mocker.GetMock<IImportApprovedTracks>()
.Setup(s => s.Import(It.IsAny<List<ImportDecision>>(), It.IsAny<bool>(), It.IsAny<DownloadClientItem>(), It.IsAny<ImportMode>()))
.Returns(imported.Select(i => new ImportResult(i)).ToList())
.Callback(() => WasImportedResponse());
}
private void WasImportedResponse()
{
Mocker.GetMock<IDiskScanService>().Setup(c => c.GetAudioFiles(It.IsAny<string>(), It.IsAny<bool>()))
.Returns(new string[0]);
}
[Test]
public void should_search_for_artist_using_folder_name()
{
@ -366,6 +409,51 @@ namespace NzbDrone.Core.Test.MediaFiles
.Verify(v => v.DeleteFolder(It.IsAny<string>(), true), Times.Never());
}
[Test]
public void should_not_delete_folder_after_import()
{
GivenValidArtist();
GivenSuccessfulImport();
_trackedDownload.DownloadItem.CanMoveFiles = false;
Subject.ProcessPath(_droneFactory, ImportMode.Auto, _trackedDownload.RemoteAlbum.Artist, _trackedDownload.DownloadItem);
Mocker.GetMock<IDiskProvider>()
.Verify(v => v.DeleteFolder(It.IsAny<string>(), true), Times.Never());
}
[Test]
public void should_delete_folder_if_importmode_move()
{
GivenValidArtist();
GivenSuccessfulImport();
_trackedDownload.DownloadItem.CanMoveFiles = false;
Subject.ProcessPath(_droneFactory, ImportMode.Move, _trackedDownload.RemoteAlbum.Artist, _trackedDownload.DownloadItem);
Mocker.GetMock<IDiskProvider>()
.Verify(v => v.DeleteFolder(It.IsAny<string>(), true), Times.Once());
}
[Test]
public void should_not_delete_folder_if_importmode_copy()
{
GivenValidArtist();
GivenSuccessfulImport();
_trackedDownload.DownloadItem.CanMoveFiles = true;
Subject.ProcessPath(_droneFactory, ImportMode.Copy, _trackedDownload.RemoteAlbum.Artist, _trackedDownload.DownloadItem);
Mocker.GetMock<IDiskProvider>()
.Verify(v => v.DeleteFolder(It.IsAny<string>(), true), Times.Never());
}
private void VerifyNoImport()
{
Mocker.GetMock<IImportApprovedTracks>().Verify(c => c.Import(It.IsAny<List<ImportDecision>>(), true, null, ImportMode.Auto),

@ -197,7 +197,12 @@ namespace NzbDrone.Core.MediaFiles
var decisions = _importDecisionMaker.GetImportDecisions(audioFiles.ToList(), artist, trackInfo);
var importResults = _importApprovedTracks.Import(decisions, true, downloadClientItem, importMode);
if ((downloadClientItem == null || downloadClientItem.CanMoveFiles) &&
if (importMode == ImportMode.Auto)
{
importMode = (downloadClientItem == null || downloadClientItem.CanMoveFiles) ? ImportMode.Move : ImportMode.Copy;
}
if (importMode == ImportMode.Move &&
importResults.Any(i => i.Result == ImportResultType.Imported) &&
ShouldDeleteFolder(directoryInfo, artist))
{

Loading…
Cancel
Save