mirror of https://github.com/lidarr/Lidarr
Fixed: DownloadedEpisodesScan API command couldn't be used to process individual files.
This commit is contained in:
parent
f25f5abced
commit
72f0085ef7
|
@ -22,15 +22,13 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||||
{
|
{
|
||||||
private string _droneFactory = "c:\\drop\\".AsOsAgnostic();
|
private string _droneFactory = "c:\\drop\\".AsOsAgnostic();
|
||||||
private string _downloadFolder = "c:\\drop_other\\Show.S01E01\\".AsOsAgnostic();
|
private string _downloadFolder = "c:\\drop_other\\Show.S01E01\\".AsOsAgnostic();
|
||||||
|
private string _downloadFile = "c:\\drop_other\\Show.S01E01.mkv".AsOsAgnostic();
|
||||||
|
|
||||||
private TrackedDownload _trackedDownload;
|
private TrackedDownload _trackedDownload;
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void Setup()
|
public void Setup()
|
||||||
{
|
{
|
||||||
Mocker.GetMock<IDiskProvider>().Setup(c => c.FolderExists(It.IsAny<string>()))
|
|
||||||
.Returns(true);
|
|
||||||
|
|
||||||
Mocker.GetMock<IConfigService>().SetupGet(c => c.DownloadedEpisodesFolder)
|
Mocker.GetMock<IConfigService>().SetupGet(c => c.DownloadedEpisodesFolder)
|
||||||
.Returns(_droneFactory);
|
.Returns(_droneFactory);
|
||||||
|
|
||||||
|
@ -59,6 +57,18 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void GivenExistingFolder(string path)
|
||||||
|
{
|
||||||
|
Mocker.GetMock<IDiskProvider>().Setup(c => c.FolderExists(It.IsAny<string>()))
|
||||||
|
.Returns(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void GivenExistingFile(string path)
|
||||||
|
{
|
||||||
|
Mocker.GetMock<IDiskProvider>().Setup(c => c.FileExists(It.IsAny<string>()))
|
||||||
|
.Returns(true);
|
||||||
|
}
|
||||||
|
|
||||||
private void GivenValidQueueItem()
|
private void GivenValidQueueItem()
|
||||||
{
|
{
|
||||||
Mocker.GetMock<ITrackedDownloadService>()
|
Mocker.GetMock<ITrackedDownloadService>()
|
||||||
|
@ -69,6 +79,8 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||||
[Test]
|
[Test]
|
||||||
public void should_process_dronefactory_if_path_is_not_specified()
|
public void should_process_dronefactory_if_path_is_not_specified()
|
||||||
{
|
{
|
||||||
|
GivenExistingFolder(_droneFactory);
|
||||||
|
|
||||||
Subject.Execute(new DownloadedEpisodesScanCommand());
|
Subject.Execute(new DownloadedEpisodesScanCommand());
|
||||||
|
|
||||||
Mocker.GetMock<IDownloadedEpisodesImportService>().Verify(c => c.ProcessRootFolder(It.IsAny<DirectoryInfo>()), Times.Once());
|
Mocker.GetMock<IDownloadedEpisodesImportService>().Verify(c => c.ProcessRootFolder(It.IsAny<DirectoryInfo>()), Times.Once());
|
||||||
|
@ -77,8 +89,6 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||||
[Test]
|
[Test]
|
||||||
public void should_skip_import_if_dronefactory_doesnt_exist()
|
public void should_skip_import_if_dronefactory_doesnt_exist()
|
||||||
{
|
{
|
||||||
Mocker.GetMock<IDiskProvider>().Setup(c => c.FolderExists(It.IsAny<string>())).Returns(false);
|
|
||||||
|
|
||||||
Subject.Execute(new DownloadedEpisodesScanCommand());
|
Subject.Execute(new DownloadedEpisodesScanCommand());
|
||||||
|
|
||||||
Mocker.GetMock<IDownloadedEpisodesImportService>().Verify(c => c.ProcessRootFolder(It.IsAny<DirectoryInfo>()), Times.Never());
|
Mocker.GetMock<IDownloadedEpisodesImportService>().Verify(c => c.ProcessRootFolder(It.IsAny<DirectoryInfo>()), Times.Never());
|
||||||
|
@ -89,6 +99,8 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||||
[Test]
|
[Test]
|
||||||
public void should_ignore_downloadclientid_if_path_is_not_specified()
|
public void should_ignore_downloadclientid_if_path_is_not_specified()
|
||||||
{
|
{
|
||||||
|
GivenExistingFolder(_droneFactory);
|
||||||
|
|
||||||
Subject.Execute(new DownloadedEpisodesScanCommand() { DownloadClientId = "sab1" });
|
Subject.Execute(new DownloadedEpisodesScanCommand() { DownloadClientId = "sab1" });
|
||||||
|
|
||||||
Mocker.GetMock<IDownloadedEpisodesImportService>().Verify(c => c.ProcessRootFolder(It.IsAny<DirectoryInfo>()), Times.Once());
|
Mocker.GetMock<IDownloadedEpisodesImportService>().Verify(c => c.ProcessRootFolder(It.IsAny<DirectoryInfo>()), Times.Once());
|
||||||
|
@ -97,14 +109,27 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||||
[Test]
|
[Test]
|
||||||
public void should_process_folder_if_downloadclientid_is_not_specified()
|
public void should_process_folder_if_downloadclientid_is_not_specified()
|
||||||
{
|
{
|
||||||
|
GivenExistingFolder(_downloadFolder);
|
||||||
|
|
||||||
Subject.Execute(new DownloadedEpisodesScanCommand() { Path = _downloadFolder });
|
Subject.Execute(new DownloadedEpisodesScanCommand() { Path = _downloadFolder });
|
||||||
|
|
||||||
Mocker.GetMock<IDownloadedEpisodesImportService>().Verify(c => c.ProcessPath(It.IsAny<string>(), null, null), Times.Once());
|
Mocker.GetMock<IDownloadedEpisodesImportService>().Verify(c => c.ProcessPath(It.IsAny<string>(), null, null), Times.Once());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_process_file_if_downloadclientid_is_not_specified()
|
||||||
|
{
|
||||||
|
GivenExistingFile(_downloadFile);
|
||||||
|
|
||||||
|
Subject.Execute(new DownloadedEpisodesScanCommand() { Path = _downloadFile });
|
||||||
|
|
||||||
|
Mocker.GetMock<IDownloadedEpisodesImportService>().Verify(c => c.ProcessPath(It.IsAny<string>(), null, null), Times.Once());
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void should_process_folder_with_downloadclientitem_if_available()
|
public void should_process_folder_with_downloadclientitem_if_available()
|
||||||
{
|
{
|
||||||
|
GivenExistingFolder(_downloadFolder);
|
||||||
GivenValidQueueItem();
|
GivenValidQueueItem();
|
||||||
|
|
||||||
Subject.Execute(new DownloadedEpisodesScanCommand() { Path = _downloadFolder, DownloadClientId = "sab1" });
|
Subject.Execute(new DownloadedEpisodesScanCommand() { Path = _downloadFolder, DownloadClientId = "sab1" });
|
||||||
|
@ -115,11 +140,23 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||||
[Test]
|
[Test]
|
||||||
public void should_process_folder_without_downloadclientitem_if_not_available()
|
public void should_process_folder_without_downloadclientitem_if_not_available()
|
||||||
{
|
{
|
||||||
|
GivenExistingFolder(_downloadFolder);
|
||||||
|
|
||||||
Subject.Execute(new DownloadedEpisodesScanCommand() { Path = _downloadFolder, DownloadClientId = "sab1" });
|
Subject.Execute(new DownloadedEpisodesScanCommand() { Path = _downloadFolder, DownloadClientId = "sab1" });
|
||||||
|
|
||||||
Mocker.GetMock<IDownloadedEpisodesImportService>().Verify(c => c.ProcessPath(_downloadFolder, null, null), Times.Once());
|
Mocker.GetMock<IDownloadedEpisodesImportService>().Verify(c => c.ProcessPath(_downloadFolder, null, null), Times.Once());
|
||||||
|
|
||||||
ExceptionVerification.ExpectedWarns(1);
|
ExceptionVerification.ExpectedWarns(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_warn_if_neither_folder_or_file_exists()
|
||||||
|
{
|
||||||
|
Subject.Execute(new DownloadedEpisodesScanCommand() { Path = _downloadFolder });
|
||||||
|
|
||||||
|
Mocker.GetMock<IDownloadedEpisodesImportService>().Verify(c => c.ProcessPath(It.IsAny<string>(), null, null), Times.Never());
|
||||||
|
|
||||||
|
ExceptionVerification.ExpectedWarns(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -54,17 +54,16 @@ namespace NzbDrone.Core.MediaFiles
|
||||||
return _downloadedEpisodesImportService.ProcessRootFolder(new DirectoryInfo(downloadedEpisodesFolder));
|
return _downloadedEpisodesImportService.ProcessRootFolder(new DirectoryInfo(downloadedEpisodesFolder));
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ImportResult> ProcessFolder(DownloadedEpisodesScanCommand message)
|
private List<ImportResult> ProcessPath(DownloadedEpisodesScanCommand message)
|
||||||
{
|
{
|
||||||
if (!_diskProvider.FolderExists(message.Path))
|
if (!_diskProvider.FolderExists(message.Path) && !_diskProvider.FileExists(message.Path))
|
||||||
{
|
{
|
||||||
_logger.Warn("Folder specified for import scan [{0}] doesn't exist.", message.Path);
|
_logger.Warn("Folder/File specified for import scan [{0}] doesn't exist.", message.Path);
|
||||||
return new List<ImportResult>();
|
return new List<ImportResult>();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.DownloadClientId.IsNotNullOrWhiteSpace())
|
if (message.DownloadClientId.IsNotNullOrWhiteSpace())
|
||||||
{
|
{
|
||||||
|
|
||||||
var trackedDownload = _trackedDownloadService.Find(message.DownloadClientId);
|
var trackedDownload = _trackedDownloadService.Find(message.DownloadClientId);
|
||||||
|
|
||||||
if (trackedDownload != null)
|
if (trackedDownload != null)
|
||||||
|
@ -90,7 +89,7 @@ namespace NzbDrone.Core.MediaFiles
|
||||||
|
|
||||||
if (message.Path.IsNotNullOrWhiteSpace())
|
if (message.Path.IsNotNullOrWhiteSpace())
|
||||||
{
|
{
|
||||||
importResults = ProcessFolder(message);
|
importResults = ProcessPath(message);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue