Fixed: DownloadedEpisodeScan API should delete source folder if ImportMode is Move.

pull/2104/head
Taloth Saldono 7 years ago
parent ac837c8f74
commit 0ec64e7043

@ -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.EpisodeImport;
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<IImportApprovedEpisodes>()
.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 remoteEpisode = Builder<RemoteEpisode>.CreateNew()
.With(v => v.Series = new Series())
.Build();
_trackedDownload = new TrackedDownload
{
DownloadItem = downloadItem,
RemoteEpisode = remoteEpisode,
State = TrackedDownloadStage.Downloading
};
}
private void GivenValidSeries()
@ -52,6 +72,29 @@ namespace NzbDrone.Core.Test.MediaFiles
.Returns(Builder<Series>.CreateNew().Build());
}
private void GivenSuccessfulImport()
{
var localEpisode = new LocalEpisode();
var imported = new List<ImportDecision>();
imported.Add(new ImportDecision(localEpisode));
Mocker.GetMock<IMakeImportDecision>()
.Setup(s => s.GetImportDecisions(It.IsAny<List<string>>(), It.IsAny<Series>(), It.IsAny<DownloadClientItem>(), null, true))
.Returns(imported);
Mocker.GetMock<IImportApprovedEpisodes>()
.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.GetVideoFiles(It.IsAny<string>(), It.IsAny<bool>()))
.Returns(new string[0]);
}
[Test]
public void should_search_for_series_using_folder_name()
{
@ -360,6 +403,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()
{
GivenValidSeries();
GivenSuccessfulImport();
_trackedDownload.DownloadItem.CanMoveFiles = false;
Subject.ProcessPath(_droneFactory, ImportMode.Auto, _trackedDownload.RemoteEpisode.Series, _trackedDownload.DownloadItem);
Mocker.GetMock<IDiskProvider>()
.Verify(v => v.DeleteFolder(It.IsAny<string>(), true), Times.Never());
}
[Test]
public void should_delete_folder_if_importmode_move()
{
GivenValidSeries();
GivenSuccessfulImport();
_trackedDownload.DownloadItem.CanMoveFiles = false;
Subject.ProcessPath(_droneFactory, ImportMode.Move, _trackedDownload.RemoteEpisode.Series, _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()
{
GivenValidSeries();
GivenSuccessfulImport();
_trackedDownload.DownloadItem.CanMoveFiles = true;
Subject.ProcessPath(_droneFactory, ImportMode.Copy, _trackedDownload.RemoteEpisode.Series, _trackedDownload.DownloadItem);
Mocker.GetMock<IDiskProvider>()
.Verify(v => v.DeleteFolder(It.IsAny<string>(), true), Times.Never());
}
private void VerifyNoImport()
{
Mocker.GetMock<IImportApprovedEpisodes>().Verify(c => c.Import(It.IsAny<List<ImportDecision>>(), true, null, ImportMode.Auto),

@ -183,7 +183,12 @@ namespace NzbDrone.Core.MediaFiles
var decisions = _importDecisionMaker.GetImportDecisions(videoFiles.ToList(), series, downloadClientItem, folderInfo, true);
var importResults = _importApprovedEpisodes.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, series))
{

Loading…
Cancel
Save