Fixed: DownloadStation proxy failing if non-bt/nzb downloads exist.

pull/6/head
Taloth Saldono 8 years ago
parent 3501e33722
commit 6d9a952bd1

@ -304,7 +304,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
_settings.TvDirectory = _tvDirectory; _settings.TvDirectory = _tvDirectory;
} }
protected virtual void GivenTorrents(List<DownloadStationTask> torrents) protected virtual void GivenTasks(List<DownloadStationTask> torrents)
{ {
if (torrents == null) if (torrents == null)
{ {
@ -312,13 +312,13 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
} }
Mocker.GetMock<IDownloadStationProxy>() Mocker.GetMock<IDownloadStationProxy>()
.Setup(s => s.GetTasks(DownloadStationTaskType.BT, It.IsAny<DownloadStationSettings>())) .Setup(s => s.GetTasks(It.IsAny<DownloadStationSettings>()))
.Returns(torrents); .Returns(torrents);
} }
protected void PrepareClientToReturnQueuedItem() protected void PrepareClientToReturnQueuedItem()
{ {
GivenTorrents(new List<DownloadStationTask> GivenTasks(new List<DownloadStationTask>
{ {
_queued _queued
}); });
@ -353,7 +353,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
var tasks = new List<DownloadStationTask>() { _queued, _completed, _failed, _downloading, _seeding }; var tasks = new List<DownloadStationTask>() { _queued, _completed, _failed, _downloading, _seeding };
Mocker.GetMock<IDownloadStationProxy>() Mocker.GetMock<IDownloadStationProxy>()
.Setup(d => d.GetTasks(DownloadStationTaskType.BT, _settings)) .Setup(d => d.GetTasks(_settings))
.Returns(tasks); .Returns(tasks);
return tasks.Count; return tasks.Count;
@ -409,6 +409,28 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
.Verify(v => v.AddTaskFromUrl(It.IsAny<string>(), null, It.IsAny<DownloadStationSettings>()), Times.Once()); .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] [Test]
public void GetItems_should_ignore_downloads_in_wrong_folder() public void GetItems_should_ignore_downloads_in_wrong_folder()
{ {
@ -416,7 +438,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
GivenSerialNumber(); GivenSerialNumber();
GivenSharedFolder(); GivenSharedFolder();
GivenTorrents(new List<DownloadStationTask> { _completed }); GivenTasks(new List<DownloadStationTask> { _completed });
Subject.GetItems().Should().BeEmpty(); Subject.GetItems().Should().BeEmpty();
} }
@ -470,7 +492,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
GivenSerialNumber(); GivenSerialNumber();
GivenSharedFolder(); GivenSharedFolder();
GivenTorrents(new List<DownloadStationTask>() { _singleFile }); GivenTasks(new List<DownloadStationTask>() { _singleFile });
var items = Subject.GetItems(); var items = Subject.GetItems();
@ -484,7 +506,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
GivenSerialNumber(); GivenSerialNumber();
GivenSharedFolder(); GivenSharedFolder();
GivenTorrents(new List<DownloadStationTask>() { _multipleFiles }); GivenTasks(new List<DownloadStationTask>() { _multipleFiles });
var items = Subject.GetItems(); var items = Subject.GetItems();
@ -498,7 +520,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
GivenSerialNumber(); GivenSerialNumber();
GivenSharedFolder(); GivenSharedFolder();
GivenTorrents(new List<DownloadStationTask>() { _singleFileCompleted }); GivenTasks(new List<DownloadStationTask>() { _singleFileCompleted });
var items = Subject.GetItems(); var items = Subject.GetItems();
@ -512,7 +534,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
GivenSerialNumber(); GivenSerialNumber();
GivenSharedFolder(); GivenSharedFolder();
GivenTorrents(new List<DownloadStationTask>() { _multipleFilesCompleted }); GivenTasks(new List<DownloadStationTask>() { _multipleFilesCompleted });
var items = Subject.GetItems(); var items = Subject.GetItems();
@ -526,7 +548,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
GivenSerialNumber(); GivenSerialNumber();
GivenSharedFolder(); GivenSharedFolder();
GivenTorrents(new List<DownloadStationTask> GivenTasks(new List<DownloadStationTask>
{ {
_queued, _downloading _queued, _downloading
}); });
@ -543,7 +565,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
GivenSerialNumber(); GivenSerialNumber();
GivenSharedFolder(); GivenSharedFolder();
GivenTorrents(new List<DownloadStationTask> GivenTasks(new List<DownloadStationTask>
{ {
_completed, _failed, _seeding _completed, _failed, _seeding
}); });
@ -565,7 +587,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
_queued.Status = apiStatus; _queued.Status = apiStatus;
GivenTorrents(new List<DownloadStationTask>() { _queued }); GivenTasks(new List<DownloadStationTask>() { _queued });
var items = Subject.GetItems(); var items = Subject.GetItems();
@ -589,7 +611,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
_queued.Status = apiStatus; _queued.Status = apiStatus;
GivenTorrents(new List<DownloadStationTask>() { _queued }); GivenTasks(new List<DownloadStationTask>() { _queued });
var items = Subject.GetItems(); var items = Subject.GetItems();
items.Should().HaveCount(1); items.Should().HaveCount(1);

@ -206,7 +206,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
_settings.TvDirectory = _tvDirectory; _settings.TvDirectory = _tvDirectory;
} }
protected virtual void GivenNZBs(List<DownloadStationTask> nzbs) protected virtual void GivenTasks(List<DownloadStationTask> nzbs)
{ {
if (nzbs == null) if (nzbs == null)
{ {
@ -214,13 +214,13 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
} }
Mocker.GetMock<IDownloadStationProxy>() Mocker.GetMock<IDownloadStationProxy>()
.Setup(s => s.GetTasks(DownloadStationTaskType.NZB, It.IsAny<DownloadStationSettings>())) .Setup(s => s.GetTasks(It.IsAny<DownloadStationSettings>()))
.Returns(nzbs); .Returns(nzbs);
} }
protected void PrepareClientToReturnQueuedItem() protected void PrepareClientToReturnQueuedItem()
{ {
GivenNZBs(new List<DownloadStationTask> GivenTasks(new List<DownloadStationTask>
{ {
_queued _queued
}); });
@ -243,7 +243,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
var tasks = new List<DownloadStationTask>() { _queued, _completed, _failed, _downloading, _seeding }; var tasks = new List<DownloadStationTask>() { _queued, _completed, _failed, _downloading, _seeding };
Mocker.GetMock<IDownloadStationProxy>() Mocker.GetMock<IDownloadStationProxy>()
.Setup(d => d.GetTasks(DownloadStationTaskType.NZB, _settings)) .Setup(d => d.GetTasks(_settings))
.Returns(tasks); .Returns(tasks);
} }
@ -300,11 +300,21 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
[Test] [Test]
public void GetItems_should_return_empty_list_if_no_tasks_available() public void GetItems_should_return_empty_list_if_no_tasks_available()
{ {
_settings.TvDirectory = @"/shared/folder/sub"; GivenSerialNumber();
GivenSharedFolder();
GivenTasks(new List<DownloadStationTask>());
Subject.GetItems().Should().BeEmpty();
}
[Test]
public void GetItems_should_return_ignore_tasks_of_unknown_type()
{
GivenSerialNumber(); GivenSerialNumber();
GivenSharedFolder(); GivenSharedFolder();
GivenNZBs(new List<DownloadStationTask>()); GivenTasks(new List<DownloadStationTask> { _completed });
_completed.Type = "ipfs";
Subject.GetItems().Should().BeEmpty(); Subject.GetItems().Should().BeEmpty();
} }
@ -316,7 +326,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
GivenSerialNumber(); GivenSerialNumber();
GivenSharedFolder(); GivenSharedFolder();
GivenNZBs(new List<DownloadStationTask> { _completed }); GivenTasks(new List<DownloadStationTask> { _completed });
Subject.GetItems().Should().BeEmpty(); Subject.GetItems().Should().BeEmpty();
} }
@ -350,7 +360,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
} }
[Test] [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(); var remoteEpisode = CreateRemoteEpisode();
@ -370,7 +380,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
GivenSerialNumber(); GivenSerialNumber();
GivenSharedFolder(); GivenSharedFolder();
GivenNZBs(new List<DownloadStationTask> GivenTasks(new List<DownloadStationTask>
{ {
_queued, _downloading _queued, _downloading
}); });
@ -387,7 +397,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
GivenSerialNumber(); GivenSerialNumber();
GivenSharedFolder(); GivenSharedFolder();
GivenNZBs(new List<DownloadStationTask> GivenTasks(new List<DownloadStationTask>
{ {
_completed, _failed, _seeding _completed, _failed, _seeding
}); });
@ -408,7 +418,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
_queued.Status = apiStatus; _queued.Status = apiStatus;
GivenNZBs(new List<DownloadStationTask>() { _queued }); GivenTasks(new List<DownloadStationTask>() { _queued });
var items = Subject.GetItems(); var items = Subject.GetItems();
@ -431,7 +441,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
_queued.Status = apiStatus; _queued.Status = apiStatus;
GivenNZBs(new List<DownloadStationTask>() { _queued }); GivenTasks(new List<DownloadStationTask>() { _queued });
var items = Subject.GetItems(); var items = Subject.GetItems();
items.Should().HaveCount(1); items.Should().HaveCount(1);

@ -10,7 +10,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation.Proxies
{ {
public interface IDownloadStationProxy public interface IDownloadStationProxy
{ {
IEnumerable<DownloadStationTask> GetTasks(DownloadStationTaskType type, DownloadStationSettings settings); IEnumerable<DownloadStationTask> GetTasks(DownloadStationSettings settings);
Dictionary<string, object> GetConfig(DownloadStationSettings settings); Dictionary<string, object> GetConfig(DownloadStationSettings settings);
void RemoveTask(string downloadId, DownloadStationSettings settings); void RemoveTask(string downloadId, DownloadStationSettings settings);
void AddTaskFromUrl(string url, string downloadDirectory, DownloadStationSettings settings); void AddTaskFromUrl(string url, string downloadDirectory, DownloadStationSettings settings);
@ -40,8 +40,8 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation.Proxies
} }
arguments.Add("file", new Dictionary<string, object>() { { "name", filename }, { "data", data } }); 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) public void AddTaskFromUrl(string url, string downloadDirectory, DownloadStationSettings settings)
@ -62,7 +62,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation.Proxies
var response = ProcessRequest(DiskStationApi.DownloadStationTask, arguments, settings, $"add task from url {url}"); 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> var arguments = new Dictionary<string, object>
{ {
@ -76,7 +76,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation.Proxies
{ {
var response = ProcessRequest<DownloadStationTaskInfoResponse>(DiskStationApi.DownloadStationTask, arguments, settings, "get tasks"); 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) catch (DownloadClientException e)
{ {

@ -45,9 +45,14 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
public override string Name => "Download Station"; 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() public override IEnumerable<DownloadClientItem> GetItems()
{ {
var torrents = _proxy.GetTasks(DownloadStationTaskType.BT, Settings); var torrents = GetTasks();
var serialNumber = _serialNumberProvider.GetSerialNumber(Settings); var serialNumber = _serialNumberProvider.GetSerialNumber(Settings);
var items = new List<DownloadClientItem>(); var items = new List<DownloadClientItem>();
@ -145,7 +150,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
_proxy.AddTaskFromUrl(magnetLink, GetDownloadDirectory(), Settings); _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) if (item != null)
{ {
@ -164,7 +169,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
_proxy.AddTaskFromData(fileContent, filename, GetDownloadDirectory(), Settings); _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(); var item = items.SingleOrDefault();
@ -354,7 +359,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
{ {
try try
{ {
_proxy.GetTasks(DownloadStationTaskType.BT, Settings); GetItems();
return null; return null;
} }
catch (Exception ex) catch (Exception ex)

@ -42,9 +42,14 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
public override string Name => "Download Station"; 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() public override IEnumerable<DownloadClientItem> GetItems()
{ {
var nzbTasks = _proxy.GetTasks(DownloadStationTaskType.NZB, Settings); var nzbTasks = GetTasks();
var serialNumber = _serialNumberProvider.GetSerialNumber(Settings); var serialNumber = _serialNumberProvider.GetSerialNumber(Settings);
var items = new List<DownloadClientItem>(); var items = new List<DownloadClientItem>();
@ -158,7 +163,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
_proxy.AddTaskFromData(fileContent, filename, GetDownloadDirectory(), Settings); _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(); var item = items.SingleOrDefault();
@ -353,7 +358,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
{ {
try try
{ {
_proxy.GetTasks(DownloadStationTaskType.NZB, Settings); GetItems();
return null; return null;
} }
catch (Exception ex) catch (Exception ex)

Loading…
Cancel
Save