mirror of
https://github.com/Radarr/Radarr
synced 2026-01-01 05:02:53 +01:00
Fixed: DownloadStation proxy failing if non-bt/nzb downloads exist.
This commit is contained in:
parent
3501e33722
commit
6d9a952bd1
5 changed files with 80 additions and 38 deletions
|
|
@ -304,7 +304,7 @@ protected void GivenTvDirectory()
|
|||
_settings.TvDirectory = _tvDirectory;
|
||||
}
|
||||
|
||||
protected virtual void GivenTorrents(List<DownloadStationTask> torrents)
|
||||
protected virtual void GivenTasks(List<DownloadStationTask> torrents)
|
||||
{
|
||||
if (torrents == null)
|
||||
{
|
||||
|
|
@ -312,13 +312,13 @@ protected virtual void GivenTorrents(List<DownloadStationTask> torrents)
|
|||
}
|
||||
|
||||
Mocker.GetMock<IDownloadStationProxy>()
|
||||
.Setup(s => s.GetTasks(DownloadStationTaskType.BT, It.IsAny<DownloadStationSettings>()))
|
||||
.Setup(s => s.GetTasks(It.IsAny<DownloadStationSettings>()))
|
||||
.Returns(torrents);
|
||||
}
|
||||
|
||||
protected void PrepareClientToReturnQueuedItem()
|
||||
{
|
||||
GivenTorrents(new List<DownloadStationTask>
|
||||
GivenTasks(new List<DownloadStationTask>
|
||||
{
|
||||
_queued
|
||||
});
|
||||
|
|
@ -353,7 +353,7 @@ protected int GivenAllKindOfTasks()
|
|||
var tasks = new List<DownloadStationTask>() { _queued, _completed, _failed, _downloading, _seeding };
|
||||
|
||||
Mocker.GetMock<IDownloadStationProxy>()
|
||||
.Setup(d => d.GetTasks(DownloadStationTaskType.BT, _settings))
|
||||
.Setup(d => d.GetTasks(_settings))
|
||||
.Returns(tasks);
|
||||
|
||||
return tasks.Count;
|
||||
|
|
@ -409,6 +409,28 @@ public void Download_without_TvDirectory_and_Category_should_use_default()
|
|||
.Verify(v => v.AddTaskFromUrl(It.IsAny<string>(), null, It.IsAny<DownloadStationSettings>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetItems_should_return_empty_list_if_no_tasks_available()
|
||||
{
|
||||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
GivenTasks(new List<DownloadStationTask>());
|
||||
|
||||
Subject.GetItems().Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetItems_should_return_ignore_tasks_of_unknown_type()
|
||||
{
|
||||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
GivenTasks(new List<DownloadStationTask> { _completed });
|
||||
|
||||
_completed.Type = "ipfs";
|
||||
|
||||
Subject.GetItems().Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetItems_should_ignore_downloads_in_wrong_folder()
|
||||
{
|
||||
|
|
@ -416,7 +438,7 @@ public void GetItems_should_ignore_downloads_in_wrong_folder()
|
|||
|
||||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
GivenTorrents(new List<DownloadStationTask> { _completed });
|
||||
GivenTasks(new List<DownloadStationTask> { _completed });
|
||||
|
||||
Subject.GetItems().Should().BeEmpty();
|
||||
}
|
||||
|
|
@ -470,7 +492,7 @@ public void GetItems_should_set_outputPath_to_base_folder_when_single_file_non_f
|
|||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
|
||||
GivenTorrents(new List<DownloadStationTask>() { _singleFile });
|
||||
GivenTasks(new List<DownloadStationTask>() { _singleFile });
|
||||
|
||||
var items = Subject.GetItems();
|
||||
|
||||
|
|
@ -484,7 +506,7 @@ public void GetItems_should_set_outputPath_to_torrent_folder_when_multiple_files
|
|||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
|
||||
GivenTorrents(new List<DownloadStationTask>() { _multipleFiles });
|
||||
GivenTasks(new List<DownloadStationTask>() { _multipleFiles });
|
||||
|
||||
var items = Subject.GetItems();
|
||||
|
||||
|
|
@ -498,7 +520,7 @@ public void GetItems_should_set_outputPath_to_base_folder_when_single_file_finis
|
|||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
|
||||
GivenTorrents(new List<DownloadStationTask>() { _singleFileCompleted });
|
||||
GivenTasks(new List<DownloadStationTask>() { _singleFileCompleted });
|
||||
|
||||
var items = Subject.GetItems();
|
||||
|
||||
|
|
@ -512,7 +534,7 @@ public void GetItems_should_set_outputPath_to_torrent_folder_when_multiple_files
|
|||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
|
||||
GivenTorrents(new List<DownloadStationTask>() { _multipleFilesCompleted });
|
||||
GivenTasks(new List<DownloadStationTask>() { _multipleFilesCompleted });
|
||||
|
||||
var items = Subject.GetItems();
|
||||
|
||||
|
|
@ -526,7 +548,7 @@ public void GetItems_should_not_map_outputpath_for_queued_or_downloading_tasks()
|
|||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
|
||||
GivenTorrents(new List<DownloadStationTask>
|
||||
GivenTasks(new List<DownloadStationTask>
|
||||
{
|
||||
_queued, _downloading
|
||||
});
|
||||
|
|
@ -543,7 +565,7 @@ public void GetItems_should_map_outputpath_for_completed_or_failed_tasks()
|
|||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
|
||||
GivenTorrents(new List<DownloadStationTask>
|
||||
GivenTasks(new List<DownloadStationTask>
|
||||
{
|
||||
_completed, _failed, _seeding
|
||||
});
|
||||
|
|
@ -565,7 +587,7 @@ public void GetItems_should_return_readonly_expected(DownloadStationTaskStatus a
|
|||
|
||||
_queued.Status = apiStatus;
|
||||
|
||||
GivenTorrents(new List<DownloadStationTask>() { _queued });
|
||||
GivenTasks(new List<DownloadStationTask>() { _queued });
|
||||
|
||||
var items = Subject.GetItems();
|
||||
|
||||
|
|
@ -589,7 +611,7 @@ public void GetItems_should_return_item_as_downloadItemStatus(DownloadStationTas
|
|||
|
||||
_queued.Status = apiStatus;
|
||||
|
||||
GivenTorrents(new List<DownloadStationTask>() { _queued });
|
||||
GivenTasks(new List<DownloadStationTask>() { _queued });
|
||||
|
||||
var items = Subject.GetItems();
|
||||
items.Should().HaveCount(1);
|
||||
|
|
|
|||
|
|
@ -206,7 +206,7 @@ protected void GivenTvDirectory()
|
|||
_settings.TvDirectory = _tvDirectory;
|
||||
}
|
||||
|
||||
protected virtual void GivenNZBs(List<DownloadStationTask> nzbs)
|
||||
protected virtual void GivenTasks(List<DownloadStationTask> nzbs)
|
||||
{
|
||||
if (nzbs == null)
|
||||
{
|
||||
|
|
@ -214,13 +214,13 @@ protected virtual void GivenNZBs(List<DownloadStationTask> nzbs)
|
|||
}
|
||||
|
||||
Mocker.GetMock<IDownloadStationProxy>()
|
||||
.Setup(s => s.GetTasks(DownloadStationTaskType.NZB, It.IsAny<DownloadStationSettings>()))
|
||||
.Setup(s => s.GetTasks(It.IsAny<DownloadStationSettings>()))
|
||||
.Returns(nzbs);
|
||||
}
|
||||
|
||||
protected void PrepareClientToReturnQueuedItem()
|
||||
{
|
||||
GivenNZBs(new List<DownloadStationTask>
|
||||
GivenTasks(new List<DownloadStationTask>
|
||||
{
|
||||
_queued
|
||||
});
|
||||
|
|
@ -243,7 +243,7 @@ protected void GivenAllKindOfTasks()
|
|||
var tasks = new List<DownloadStationTask>() { _queued, _completed, _failed, _downloading, _seeding };
|
||||
|
||||
Mocker.GetMock<IDownloadStationProxy>()
|
||||
.Setup(d => d.GetTasks(DownloadStationTaskType.NZB, _settings))
|
||||
.Setup(d => d.GetTasks(_settings))
|
||||
.Returns(tasks);
|
||||
}
|
||||
|
||||
|
|
@ -300,11 +300,21 @@ public void Download_without_TvDirectory_and_Category_should_use_default()
|
|||
[Test]
|
||||
public void GetItems_should_return_empty_list_if_no_tasks_available()
|
||||
{
|
||||
_settings.TvDirectory = @"/shared/folder/sub";
|
||||
|
||||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
GivenNZBs(new List<DownloadStationTask>());
|
||||
GivenTasks(new List<DownloadStationTask>());
|
||||
|
||||
Subject.GetItems().Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetItems_should_return_ignore_tasks_of_unknown_type()
|
||||
{
|
||||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
GivenTasks(new List<DownloadStationTask> { _completed });
|
||||
|
||||
_completed.Type = "ipfs";
|
||||
|
||||
Subject.GetItems().Should().BeEmpty();
|
||||
}
|
||||
|
|
@ -316,7 +326,7 @@ public void GetItems_should_ignore_downloads_in_wrong_folder()
|
|||
|
||||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
GivenNZBs(new List<DownloadStationTask> { _completed });
|
||||
GivenTasks(new List<DownloadStationTask> { _completed });
|
||||
|
||||
Subject.GetItems().Should().BeEmpty();
|
||||
}
|
||||
|
|
@ -350,7 +360,7 @@ public void GetItems_should_throw_if_serial_number_unavailable()
|
|||
}
|
||||
|
||||
[Test]
|
||||
public void Download_should_throw_and_not_add_tasks_if_cannot_get_serial_number()
|
||||
public void Download_should_throw_and_not_add_task_if_cannot_get_serial_number()
|
||||
{
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
|
|
@ -370,7 +380,7 @@ public void GetItems_should_not_map_outputpath_for_queued_or_downloading_tasks()
|
|||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
|
||||
GivenNZBs(new List<DownloadStationTask>
|
||||
GivenTasks(new List<DownloadStationTask>
|
||||
{
|
||||
_queued, _downloading
|
||||
});
|
||||
|
|
@ -387,7 +397,7 @@ public void GetItems_should_map_outputpath_for_completed_or_failed_tasks()
|
|||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
|
||||
GivenNZBs(new List<DownloadStationTask>
|
||||
GivenTasks(new List<DownloadStationTask>
|
||||
{
|
||||
_completed, _failed, _seeding
|
||||
});
|
||||
|
|
@ -408,7 +418,7 @@ public void GetItems_should_return_readonly_expected(DownloadStationTaskStatus a
|
|||
|
||||
_queued.Status = apiStatus;
|
||||
|
||||
GivenNZBs(new List<DownloadStationTask>() { _queued });
|
||||
GivenTasks(new List<DownloadStationTask>() { _queued });
|
||||
|
||||
var items = Subject.GetItems();
|
||||
|
||||
|
|
@ -431,7 +441,7 @@ public void GetItems_should_return_item_as_downloadItemStatus(DownloadStationTas
|
|||
|
||||
_queued.Status = apiStatus;
|
||||
|
||||
GivenNZBs(new List<DownloadStationTask>() { _queued });
|
||||
GivenTasks(new List<DownloadStationTask>() { _queued });
|
||||
|
||||
var items = Subject.GetItems();
|
||||
items.Should().HaveCount(1);
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation.Proxies
|
|||
{
|
||||
public interface IDownloadStationProxy
|
||||
{
|
||||
IEnumerable<DownloadStationTask> GetTasks(DownloadStationTaskType type, DownloadStationSettings settings);
|
||||
IEnumerable<DownloadStationTask> GetTasks(DownloadStationSettings settings);
|
||||
Dictionary<string, object> GetConfig(DownloadStationSettings settings);
|
||||
void RemoveTask(string downloadId, DownloadStationSettings settings);
|
||||
void AddTaskFromUrl(string url, string downloadDirectory, DownloadStationSettings settings);
|
||||
|
|
@ -40,8 +40,8 @@ public void AddTaskFromData(byte[] data, string filename, string downloadDirecto
|
|||
}
|
||||
|
||||
arguments.Add("file", new Dictionary<string, object>() { { "name", filename }, { "data", data } });
|
||||
|
||||
var response = ProcessRequest(DiskStationApi.DownloadStationTask, arguments, settings, $"add task from data {filename}", HttpMethod.POST);
|
||||
|
||||
var response = ProcessRequest(DiskStationApi.DownloadStationTask, arguments, settings, $"add task from data {filename}", HttpMethod.POST);
|
||||
}
|
||||
|
||||
public void AddTaskFromUrl(string url, string downloadDirectory, DownloadStationSettings settings)
|
||||
|
|
@ -62,7 +62,7 @@ public void AddTaskFromUrl(string url, string downloadDirectory, DownloadStation
|
|||
var response = ProcessRequest(DiskStationApi.DownloadStationTask, arguments, settings, $"add task from url {url}");
|
||||
}
|
||||
|
||||
public IEnumerable<DownloadStationTask> GetTasks(DownloadStationTaskType type, DownloadStationSettings settings)
|
||||
public IEnumerable<DownloadStationTask> GetTasks(DownloadStationSettings settings)
|
||||
{
|
||||
var arguments = new Dictionary<string, object>
|
||||
{
|
||||
|
|
@ -76,7 +76,7 @@ public IEnumerable<DownloadStationTask> GetTasks(DownloadStationTaskType type, D
|
|||
{
|
||||
var response = ProcessRequest<DownloadStationTaskInfoResponse>(DiskStationApi.DownloadStationTask, arguments, settings, "get tasks");
|
||||
|
||||
return response.Data.Tasks.Where(t => t.Type == type.ToString());
|
||||
return response.Data.Tasks;
|
||||
}
|
||||
catch (DownloadClientException e)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -45,9 +45,14 @@ public TorrentDownloadStation(ISharedFolderResolver sharedFolderResolver,
|
|||
|
||||
public override string Name => "Download Station";
|
||||
|
||||
protected IEnumerable<DownloadStationTask> GetTasks()
|
||||
{
|
||||
return _proxy.GetTasks(Settings).Where(v => v.Type == DownloadStationTaskType.BT.ToString());
|
||||
}
|
||||
|
||||
public override IEnumerable<DownloadClientItem> GetItems()
|
||||
{
|
||||
var torrents = _proxy.GetTasks(DownloadStationTaskType.BT, Settings);
|
||||
var torrents = GetTasks();
|
||||
var serialNumber = _serialNumberProvider.GetSerialNumber(Settings);
|
||||
|
||||
var items = new List<DownloadClientItem>();
|
||||
|
|
@ -145,7 +150,7 @@ protected override string AddFromMagnetLink(RemoteEpisode remoteEpisode, string
|
|||
|
||||
_proxy.AddTaskFromUrl(magnetLink, GetDownloadDirectory(), Settings);
|
||||
|
||||
var item = _proxy.GetTasks(DownloadStationTaskType.BT, Settings).SingleOrDefault(t => t.Additional.Detail["uri"] == magnetLink);
|
||||
var item = GetTasks().SingleOrDefault(t => t.Additional.Detail["uri"] == magnetLink);
|
||||
|
||||
if (item != null)
|
||||
{
|
||||
|
|
@ -164,7 +169,7 @@ protected override string AddFromTorrentFile(RemoteEpisode remoteEpisode, string
|
|||
|
||||
_proxy.AddTaskFromData(fileContent, filename, GetDownloadDirectory(), Settings);
|
||||
|
||||
var items = _proxy.GetTasks(DownloadStationTaskType.BT, Settings).Where(t => t.Additional.Detail["uri"] == Path.GetFileNameWithoutExtension(filename));
|
||||
var items = GetTasks().Where(t => t.Additional.Detail["uri"] == Path.GetFileNameWithoutExtension(filename));
|
||||
|
||||
var item = items.SingleOrDefault();
|
||||
|
||||
|
|
@ -354,7 +359,7 @@ protected ValidationFailure TestGetTorrents()
|
|||
{
|
||||
try
|
||||
{
|
||||
_proxy.GetTasks(DownloadStationTaskType.BT, Settings);
|
||||
GetItems();
|
||||
return null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
|||
|
|
@ -42,9 +42,14 @@ Logger logger
|
|||
|
||||
public override string Name => "Download Station";
|
||||
|
||||
protected IEnumerable<DownloadStationTask> GetTasks()
|
||||
{
|
||||
return _proxy.GetTasks(Settings).Where(v => v.Type == DownloadStationTaskType.NZB.ToString());
|
||||
}
|
||||
|
||||
public override IEnumerable<DownloadClientItem> GetItems()
|
||||
{
|
||||
var nzbTasks = _proxy.GetTasks(DownloadStationTaskType.NZB, Settings);
|
||||
var nzbTasks = GetTasks();
|
||||
var serialNumber = _serialNumberProvider.GetSerialNumber(Settings);
|
||||
|
||||
var items = new List<DownloadClientItem>();
|
||||
|
|
@ -158,7 +163,7 @@ protected override string AddFromNzbFile(RemoteEpisode remoteEpisode, string fil
|
|||
|
||||
_proxy.AddTaskFromData(fileContent, filename, GetDownloadDirectory(), Settings);
|
||||
|
||||
var items = _proxy.GetTasks(DownloadStationTaskType.NZB, Settings).Where(t => t.Additional.Detail["uri"] == filename);
|
||||
var items = GetTasks().Where(t => t.Additional.Detail["uri"] == filename);
|
||||
|
||||
var item = items.SingleOrDefault();
|
||||
|
||||
|
|
@ -353,7 +358,7 @@ protected ValidationFailure TestGetNZB()
|
|||
{
|
||||
try
|
||||
{
|
||||
_proxy.GetTasks(DownloadStationTaskType.NZB, Settings);
|
||||
GetItems();
|
||||
return null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
|||
Loading…
Reference in a new issue