mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-24 22:35:39 -04:00
New: Drone now uses the Download Client API to determine if a download is ready for import. (User configuration is required to replace the drone factory with this feature)
This commit is contained in:
+118
@@ -0,0 +1,118 @@
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Linq;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using FluentAssertions;
|
||||
using NzbDrone.Test.Common;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.Download.Clients;
|
||||
using NzbDrone.Core.Download.Clients.UsenetBlackhole;
|
||||
|
||||
namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
|
||||
{
|
||||
|
||||
[TestFixture]
|
||||
public class UsenetBlackholeFixture : DownloadClientFixtureBase<UsenetBlackhole>
|
||||
{
|
||||
protected string _completedDownloadFolder;
|
||||
protected string _blackholeFolder;
|
||||
protected string _filePath;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_completedDownloadFolder = @"c:\blackhole\completed".AsOsAgnostic();
|
||||
_blackholeFolder = @"c:\blackhole\nzb".AsOsAgnostic();
|
||||
_filePath = (@"c:\blackhole\nzb\" + _title + ".nzb").AsOsAgnostic();
|
||||
|
||||
Subject.Definition = new DownloadClientDefinition();
|
||||
Subject.Definition.Settings = new UsenetBlackholeSettings
|
||||
{
|
||||
NzbFolder = _blackholeFolder,
|
||||
WatchFolder = _completedDownloadFolder
|
||||
};
|
||||
}
|
||||
|
||||
protected void WithSuccessfulDownload()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected void WithFailedDownload()
|
||||
{
|
||||
Mocker.GetMock<IHttpProvider>()
|
||||
.Setup(c => c.DownloadFile(It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Throws(new WebException());
|
||||
}
|
||||
|
||||
protected void GivenCompletedItem()
|
||||
{
|
||||
var targetDir = Path.Combine(_completedDownloadFolder, _title);
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(c => c.GetDirectories(_completedDownloadFolder))
|
||||
.Returns(new[] { targetDir });
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(c => c.GetFiles(targetDir, SearchOption.AllDirectories))
|
||||
.Returns(new[] { Path.Combine(_completedDownloadFolder, "somefile.mkv") });
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(c => c.GetFileSize(It.IsAny<string>()))
|
||||
.Returns(1000000);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void completed_download_should_have_required_properties()
|
||||
{
|
||||
GivenCompletedItem();
|
||||
|
||||
var result = Subject.GetItems().Single();
|
||||
|
||||
VerifyCompleted(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Download_should_download_file_if_it_doesnt_exist()
|
||||
{
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
Subject.Download(remoteEpisode);
|
||||
|
||||
Mocker.GetMock<IHttpProvider>().Verify(c => c.DownloadFile(_downloadUrl, _filePath), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Download_should_replace_illegal_characters_in_title()
|
||||
{
|
||||
var illegalTitle = "Saturday Night Live - S38E08 - Jeremy Renner/Maroon 5 [SDTV]";
|
||||
var expectedFilename = Path.Combine(_blackholeFolder, "Saturday Night Live - S38E08 - Jeremy Renner+Maroon 5 [SDTV]" + Path.GetExtension(_filePath));
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
remoteEpisode.Release.Title = illegalTitle;
|
||||
|
||||
Subject.Download(remoteEpisode);
|
||||
|
||||
Mocker.GetMock<IHttpProvider>().Verify(c => c.DownloadFile(It.IsAny<string>(), expectedFilename), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetItems_should_considered_locked_files_downloading()
|
||||
{
|
||||
GivenCompletedItem();
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(c => c.IsFileLocked(It.IsAny<string>()))
|
||||
.Returns(true);
|
||||
|
||||
var result = Subject.GetItems().Single();
|
||||
|
||||
result.Status.Should().Be(DownloadItemStatus.Downloading);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.Download.Clients;
|
||||
using NzbDrone.Core.Download.Clients.Blackhole;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.Download.DownloadClientTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class BlackholeProviderFixture : CoreTest<Blackhole>
|
||||
{
|
||||
private const string _nzbUrl = "http://www.nzbs.com/url";
|
||||
private const string _title = "some_nzb_title";
|
||||
private string _blackHoleFolder;
|
||||
private string _nzbPath;
|
||||
private RemoteEpisode _remoteEpisode;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_blackHoleFolder = @"c:\nzb\blackhole\".AsOsAgnostic();
|
||||
_nzbPath = @"c:\nzb\blackhole\some_nzb_title.nzb".AsOsAgnostic();
|
||||
|
||||
_remoteEpisode = new RemoteEpisode();
|
||||
_remoteEpisode.Release = new ReleaseInfo();
|
||||
_remoteEpisode.Release.Title = _title;
|
||||
_remoteEpisode.Release.DownloadUrl = _nzbUrl;
|
||||
|
||||
Subject.Definition = new DownloadClientDefinition();
|
||||
Subject.Definition.Settings = new FolderSettings
|
||||
{
|
||||
Folder = _blackHoleFolder
|
||||
};
|
||||
}
|
||||
|
||||
private void WithExistingFile()
|
||||
{
|
||||
Mocker.GetMock<IDiskProvider>().Setup(c => c.FileExists(_nzbPath)).Returns(true);
|
||||
}
|
||||
|
||||
private void WithFailedDownload()
|
||||
{
|
||||
Mocker.GetMock<IHttpProvider>().Setup(c => c.DownloadFile(It.IsAny<string>(), It.IsAny<string>())).Throws(new WebException());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DownloadNzb_should_download_file_if_it_doesnt_exist()
|
||||
{
|
||||
Subject.DownloadNzb(_remoteEpisode);
|
||||
|
||||
Mocker.GetMock<IHttpProvider>().Verify(c => c.DownloadFile(_nzbUrl, _nzbPath), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_replace_illegal_characters_in_title()
|
||||
{
|
||||
var illegalTitle = "Saturday Night Live - S38E08 - Jeremy Renner/Maroon 5 [SDTV]";
|
||||
var expectedFilename = Path.Combine(_blackHoleFolder, "Saturday Night Live - S38E08 - Jeremy Renner+Maroon 5 [SDTV].nzb");
|
||||
_remoteEpisode.Release.Title = illegalTitle;
|
||||
|
||||
Subject.DownloadNzb(_remoteEpisode);
|
||||
|
||||
Mocker.GetMock<IHttpProvider>().Verify(c => c.DownloadFile(It.IsAny<string>(), expectedFilename), Times.Once());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using FluentAssertions;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Download;
|
||||
|
||||
namespace NzbDrone.Core.Test.Download.DownloadClientTests
|
||||
{
|
||||
public abstract class DownloadClientFixtureBase<TSubject> : CoreTest<TSubject>
|
||||
where TSubject : class, IDownloadClient
|
||||
{
|
||||
protected readonly string _title = "Droned.S01E01.Pilot.1080p.WEB-DL-DRONE";
|
||||
protected readonly string _downloadUrl = "http://somewhere.com/Droned.S01E01.Pilot.1080p.WEB-DL-DRONE.ext";
|
||||
|
||||
[SetUp]
|
||||
public void SetupBase()
|
||||
{
|
||||
Mocker.GetMock<IParsingService>()
|
||||
.Setup(s => s.Map(It.IsAny<ParsedEpisodeInfo>(), It.IsAny<int>(), null))
|
||||
.Returns(CreateRemoteEpisode());
|
||||
}
|
||||
|
||||
protected virtual RemoteEpisode CreateRemoteEpisode()
|
||||
{
|
||||
var remoteEpisode = new RemoteEpisode();
|
||||
remoteEpisode.Release = new ReleaseInfo();
|
||||
remoteEpisode.Release.Title = _title;
|
||||
remoteEpisode.Release.DownloadUrl = _downloadUrl;
|
||||
remoteEpisode.Release.DownloadProtocol = Subject.Protocol;
|
||||
|
||||
remoteEpisode.ParsedEpisodeInfo = new ParsedEpisodeInfo();
|
||||
remoteEpisode.ParsedEpisodeInfo.FullSeason = false;
|
||||
|
||||
remoteEpisode.Episodes = new List<Episode>();
|
||||
|
||||
remoteEpisode.Series = new Series();
|
||||
|
||||
return remoteEpisode;
|
||||
}
|
||||
|
||||
protected void VerifyIdentifiable(DownloadClientItem downloadClientItem)
|
||||
{
|
||||
downloadClientItem.DownloadClient.Should().Be(Subject.Definition.Name);
|
||||
downloadClientItem.DownloadClientId.Should().NotBeNullOrEmpty();
|
||||
|
||||
downloadClientItem.Title.Should().NotBeNullOrEmpty();
|
||||
|
||||
downloadClientItem.RemoteEpisode.Should().NotBeNull();
|
||||
|
||||
}
|
||||
|
||||
protected void VerifyQueued(DownloadClientItem downloadClientItem)
|
||||
{
|
||||
VerifyIdentifiable(downloadClientItem);
|
||||
downloadClientItem.RemainingSize.Should().NotBe(0);
|
||||
//downloadClientItem.RemainingTime.Should().NotBe(TimeSpan.Zero);
|
||||
//downloadClientItem.OutputPath.Should().NotBeNullOrEmpty();
|
||||
downloadClientItem.Status.Should().Be(DownloadItemStatus.Queued);
|
||||
}
|
||||
|
||||
protected void VerifyPaused(DownloadClientItem downloadClientItem)
|
||||
{
|
||||
VerifyIdentifiable(downloadClientItem);
|
||||
|
||||
downloadClientItem.RemainingSize.Should().NotBe(0);
|
||||
//downloadClientItem.RemainingTime.Should().NotBe(TimeSpan.Zero);
|
||||
//downloadClientItem.OutputPath.Should().NotBeNullOrEmpty();
|
||||
downloadClientItem.Status.Should().Be(DownloadItemStatus.Paused);
|
||||
}
|
||||
|
||||
protected void VerifyDownloading(DownloadClientItem downloadClientItem)
|
||||
{
|
||||
VerifyIdentifiable(downloadClientItem);
|
||||
|
||||
downloadClientItem.RemainingSize.Should().NotBe(0);
|
||||
//downloadClientItem.RemainingTime.Should().NotBe(TimeSpan.Zero);
|
||||
//downloadClientItem.OutputPath.Should().NotBeNullOrEmpty();
|
||||
downloadClientItem.Status.Should().Be(DownloadItemStatus.Downloading);
|
||||
}
|
||||
|
||||
protected void VerifyCompleted(DownloadClientItem downloadClientItem)
|
||||
{
|
||||
VerifyIdentifiable(downloadClientItem);
|
||||
|
||||
downloadClientItem.Title.Should().NotBeNullOrEmpty();
|
||||
downloadClientItem.RemainingSize.Should().Be(0);
|
||||
downloadClientItem.RemainingTime.Should().Be(TimeSpan.Zero);
|
||||
//downloadClientItem.OutputPath.Should().NotBeNullOrEmpty();
|
||||
downloadClientItem.Status.Should().Be(DownloadItemStatus.Completed);
|
||||
}
|
||||
|
||||
protected void VerifyFailed(DownloadClientItem downloadClientItem)
|
||||
{
|
||||
VerifyIdentifiable(downloadClientItem);
|
||||
|
||||
downloadClientItem.Status.Should().Be(DownloadItemStatus.Failed);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.Download.Clients.Nzbget;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests
|
||||
{
|
||||
public class DownloadNzbFixture : CoreTest<Nzbget>
|
||||
{
|
||||
private const string _url = "http://www.nzbdrone.com";
|
||||
private const string _title = "30.Rock.S01E01.Pilot.720p.hdtv";
|
||||
private RemoteEpisode _remoteEpisode;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_remoteEpisode = new RemoteEpisode();
|
||||
_remoteEpisode.Release = new ReleaseInfo();
|
||||
_remoteEpisode.Release.Title = _title;
|
||||
_remoteEpisode.Release.DownloadUrl = _url;
|
||||
|
||||
_remoteEpisode.Episodes = Builder<Episode>.CreateListOfSize(1)
|
||||
.All()
|
||||
.With(e => e.AirDate = DateTime.Today.ToString(Episode.AIR_DATE_FORMAT))
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
Subject.Definition = new DownloadClientDefinition();
|
||||
Subject.Definition.Settings = new NzbgetSettings
|
||||
{
|
||||
Host = "localhost",
|
||||
Port = 6789,
|
||||
Username = "nzbget",
|
||||
Password = "pass",
|
||||
TvCategory = "tv",
|
||||
RecentTvPriority = (int)NzbgetPriority.High
|
||||
};
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_add_item_to_queue()
|
||||
{
|
||||
Mocker.GetMock<INzbgetProxy>()
|
||||
.Setup(s => s.DownloadNzb(It.IsAny<Stream>(), It.IsAny<String>(), It.IsAny<String>(), It.IsAny<Int32>(), It.IsAny<NzbgetSettings>()))
|
||||
.Returns("id");
|
||||
|
||||
Subject.DownloadNzb(_remoteEpisode);
|
||||
|
||||
Mocker.GetMock<INzbgetProxy>()
|
||||
.Verify(v => v.DownloadNzb(It.IsAny<Stream>(), It.IsAny<String>(), It.IsAny<String>(), It.IsAny<Int32>(), It.IsAny<NzbgetSettings>()), Times.Once());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.Download.Clients.Nzbget;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class NzbgetFixture : DownloadClientFixtureBase<Nzbget>
|
||||
{
|
||||
private NzbgetQueueItem _queued;
|
||||
private NzbgetHistoryItem _failed;
|
||||
private NzbgetHistoryItem _completed;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
Subject.Definition = new DownloadClientDefinition();
|
||||
Subject.Definition.Settings = new NzbgetSettings
|
||||
{
|
||||
Host = "192.168.5.55",
|
||||
Port = 2222,
|
||||
Username = "admin",
|
||||
Password = "pass",
|
||||
TvCategory = "tv",
|
||||
RecentTvPriority = (int)NzbgetPriority.High
|
||||
};
|
||||
|
||||
_queued = new NzbgetQueueItem
|
||||
{
|
||||
FileSizeLo = 1000,
|
||||
RemainingSizeLo = 10,
|
||||
Category = "tv",
|
||||
NzbName = "Droned.S01E01.Pilot.1080p.WEB-DL-DRONE",
|
||||
Parameters = new List<NzbgetParameter> { new NzbgetParameter { Name = "drone", Value = "id" } }
|
||||
};
|
||||
|
||||
_failed = new NzbgetHistoryItem
|
||||
{
|
||||
FileSizeLo = 1000,
|
||||
Category = "tv",
|
||||
Name = "Droned.S01E01.Pilot.1080p.WEB-DL-DRONE",
|
||||
DestDir = "somedirectory",
|
||||
Parameters = new List<NzbgetParameter> { new NzbgetParameter { Name = "drone", Value = "id" } },
|
||||
ParStatus = "Some Error"
|
||||
};
|
||||
|
||||
_completed = new NzbgetHistoryItem
|
||||
{
|
||||
FileSizeLo = 1000,
|
||||
Category = "tv",
|
||||
Name = "Droned.S01E01.Pilot.1080p.WEB-DL-DRONE",
|
||||
DestDir = "somedirectory",
|
||||
Parameters = new List<NzbgetParameter> { new NzbgetParameter { Name = "drone", Value = "id" } },
|
||||
ParStatus = "SUCCESS",
|
||||
ScriptStatus = "NONE"
|
||||
};
|
||||
}
|
||||
|
||||
protected void WithFailedDownload()
|
||||
{
|
||||
Mocker.GetMock<INzbgetProxy>()
|
||||
.Setup(s => s.DownloadNzb(It.IsAny<Stream>(), It.IsAny<String>(), It.IsAny<String>(), It.IsAny<int>(), It.IsAny<NzbgetSettings>()))
|
||||
.Returns((String)null);
|
||||
}
|
||||
|
||||
protected void WithSuccessfulDownload()
|
||||
{
|
||||
Mocker.GetMock<INzbgetProxy>()
|
||||
.Setup(s => s.DownloadNzb(It.IsAny<Stream>(), It.IsAny<String>(), It.IsAny<String>(), It.IsAny<int>(), It.IsAny<NzbgetSettings>()))
|
||||
.Returns(Guid.NewGuid().ToString().Replace("-", ""));
|
||||
}
|
||||
|
||||
protected virtual void WithQueue(NzbgetQueueItem queue)
|
||||
{
|
||||
var list = new List<NzbgetQueueItem>();
|
||||
|
||||
if (queue != null)
|
||||
{
|
||||
list.Add(queue);
|
||||
}
|
||||
|
||||
Mocker.GetMock<INzbgetProxy>()
|
||||
.Setup(s => s.GetQueue(It.IsAny<NzbgetSettings>()))
|
||||
.Returns(list);
|
||||
}
|
||||
|
||||
protected virtual void WithHistory(NzbgetHistoryItem history)
|
||||
{
|
||||
var list = new List<NzbgetHistoryItem>();
|
||||
|
||||
if (history != null)
|
||||
{
|
||||
list.Add(history);
|
||||
}
|
||||
|
||||
Mocker.GetMock<INzbgetProxy>()
|
||||
.Setup(s => s.GetHistory(It.IsAny<NzbgetSettings>()))
|
||||
.Returns(list);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetItems_should_return_no_items_when_queue_is_empty()
|
||||
{
|
||||
WithQueue(null);
|
||||
WithHistory(null);
|
||||
|
||||
Subject.GetItems().Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void queued_item_should_have_required_properties()
|
||||
{
|
||||
_queued.ActiveDownloads = 0;
|
||||
|
||||
WithQueue(_queued);
|
||||
WithHistory(null);
|
||||
|
||||
var result = Subject.GetItems().Single();
|
||||
|
||||
VerifyQueued(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void paused_item_should_have_required_properties()
|
||||
{
|
||||
_queued.PausedSizeLo = _queued.FileSizeLo;
|
||||
|
||||
WithQueue(_queued);
|
||||
WithHistory(null);
|
||||
|
||||
var result = Subject.GetItems().Single();
|
||||
|
||||
VerifyPaused(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void downloading_item_should_have_required_properties()
|
||||
{
|
||||
_queued.ActiveDownloads = 1;
|
||||
|
||||
WithQueue(_queued);
|
||||
WithHistory(null);
|
||||
|
||||
var result = Subject.GetItems().Single();
|
||||
|
||||
VerifyDownloading(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void completed_download_should_have_required_properties()
|
||||
{
|
||||
WithQueue(null);
|
||||
WithHistory(_completed);
|
||||
|
||||
var result = Subject.GetItems().Single();
|
||||
|
||||
VerifyCompleted(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void failed_item_should_have_required_properties()
|
||||
{
|
||||
WithQueue(null);
|
||||
WithHistory(_failed);
|
||||
|
||||
var result = Subject.GetItems().Single();
|
||||
|
||||
VerifyFailed(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Download_should_return_unique_id()
|
||||
{
|
||||
WithSuccessfulDownload();
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetItems_should_ignore_downloads_from_other_categories()
|
||||
{
|
||||
_completed.Category = "mycat";
|
||||
|
||||
WithQueue(null);
|
||||
WithHistory(_completed);
|
||||
|
||||
var items = Subject.GetItems();
|
||||
|
||||
items.Should().BeEmpty();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.Download.Clients.Nzbget;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests
|
||||
{
|
||||
public class QueueFixture : CoreTest<Nzbget>
|
||||
{
|
||||
private List<NzbgetQueueItem> _queue;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_queue = Builder<NzbgetQueueItem>.CreateListOfSize(5)
|
||||
.All()
|
||||
.With(q => q.NzbName = "30.Rock.S01E01.Pilot.720p.hdtv.nzb")
|
||||
.With(q => q.Parameters = new List<NzbgetParameter>
|
||||
{
|
||||
new NzbgetParameter { Name = "drone", Value = "id" }
|
||||
})
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
Subject.Definition = new DownloadClientDefinition();
|
||||
Subject.Definition.Settings = new NzbgetSettings
|
||||
{
|
||||
Host = "localhost",
|
||||
Port = 6789,
|
||||
Username = "nzbget",
|
||||
Password = "pass",
|
||||
TvCategory = "tv",
|
||||
RecentTvPriority = (int)NzbgetPriority.High
|
||||
};
|
||||
}
|
||||
|
||||
private void WithFullQueue()
|
||||
{
|
||||
Mocker.GetMock<INzbgetProxy>()
|
||||
.Setup(s => s.GetQueue(It.IsAny<NzbgetSettings>()))
|
||||
.Returns(_queue);
|
||||
}
|
||||
|
||||
private void WithEmptyQueue()
|
||||
{
|
||||
Mocker.GetMock<INzbgetProxy>()
|
||||
.Setup(s => s.GetQueue(It.IsAny<NzbgetSettings>()))
|
||||
.Returns(new List<NzbgetQueueItem>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_no_items_when_queue_is_empty()
|
||||
{
|
||||
WithEmptyQueue();
|
||||
|
||||
Subject.GetQueue()
|
||||
.Should()
|
||||
.BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_item_when_queue_has_item()
|
||||
{
|
||||
WithFullQueue();
|
||||
|
||||
Mocker.GetMock<IParsingService>()
|
||||
.Setup(s => s.Map(It.IsAny<ParsedEpisodeInfo>(), 0, null))
|
||||
.Returns(new RemoteEpisode {Series = new Series()});
|
||||
|
||||
Subject.GetQueue()
|
||||
.Should()
|
||||
.HaveCount(_queue.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,7 +64,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests
|
||||
[Test]
|
||||
public void should_download_file_if_it_doesnt_exist()
|
||||
{
|
||||
Subject.DownloadNzb(_remoteEpisode);
|
||||
Subject.Download(_remoteEpisode);
|
||||
|
||||
Mocker.GetMock<IHttpProvider>().Verify(c => c.DownloadFile(_nzbUrl, _nzbPath), Times.Once());
|
||||
}
|
||||
@@ -75,7 +75,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests
|
||||
{
|
||||
WithFailedDownload();
|
||||
|
||||
Assert.Throws<WebException>(() => Subject.DownloadNzb(_remoteEpisode));
|
||||
Assert.Throws<WebException>(() => Subject.Download(_remoteEpisode));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -84,7 +84,13 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests
|
||||
_remoteEpisode.Release.Title = "30 Rock - Season 1";
|
||||
_remoteEpisode.ParsedEpisodeInfo.FullSeason = true;
|
||||
|
||||
Assert.Throws<NotImplementedException>(() => Subject.DownloadNzb(_remoteEpisode));
|
||||
Assert.Throws<NotSupportedException>(() => Subject.Download(_remoteEpisode));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_throw_item_is_removed()
|
||||
{
|
||||
Assert.Throws<NotSupportedException>(() => Subject.RemoveItem(""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -94,7 +100,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests
|
||||
var expectedFilename = Path.Combine(_pneumaticFolder, "Saturday Night Live - S38E08 - Jeremy Renner+Maroon 5 [SDTV].nzb");
|
||||
_remoteEpisode.Release.Title = illegalTitle;
|
||||
|
||||
Subject.DownloadNzb(_remoteEpisode);
|
||||
Subject.Download(_remoteEpisode);
|
||||
|
||||
Mocker.GetMock<IHttpProvider>().Verify(c => c.DownloadFile(It.IsAny<string>(), expectedFilename), Times.Once());
|
||||
}
|
||||
|
||||
+210
-17
@@ -12,30 +12,20 @@ using NzbDrone.Core.Download.Clients.Sabnzbd.Responses;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class SabnzbdFixture : CoreTest<Sabnzbd>
|
||||
public class SabnzbdFixture : DownloadClientFixtureBase<Sabnzbd>
|
||||
{
|
||||
private const string URL = "http://www.nzbclub.com/nzb_download.aspx?mid=1950232";
|
||||
private const string TITLE = "My Series Name - 5x2-5x3 - My title [Bluray720p] [Proper]";
|
||||
private RemoteEpisode _remoteEpisode;
|
||||
private SabnzbdQueue _queued;
|
||||
private SabnzbdHistory _failed;
|
||||
private SabnzbdHistory _completed;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_remoteEpisode = new RemoteEpisode();
|
||||
_remoteEpisode.Release = new ReleaseInfo();
|
||||
_remoteEpisode.Release.Title = TITLE;
|
||||
_remoteEpisode.Release.DownloadUrl = URL;
|
||||
|
||||
_remoteEpisode.Episodes = Builder<Episode>.CreateListOfSize(1)
|
||||
.All()
|
||||
.With(e => e.AirDate = DateTime.Today.ToString(Episode.AIR_DATE_FORMAT))
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
Subject.Definition = new DownloadClientDefinition();
|
||||
Subject.Definition.Settings = new SabnzbdSettings
|
||||
{
|
||||
@@ -47,16 +37,219 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests
|
||||
TvCategory = "tv",
|
||||
RecentTvPriority = (int)SabnzbdPriority.High
|
||||
};
|
||||
_queued = new SabnzbdQueue
|
||||
{
|
||||
Paused = false,
|
||||
Items = new List<SabnzbdQueueItem>()
|
||||
{
|
||||
new SabnzbdQueueItem
|
||||
{
|
||||
Status = SabnzbdDownloadStatus.Downloading,
|
||||
Size = 1000,
|
||||
Sizeleft = 10,
|
||||
Timeleft = TimeSpan.FromSeconds(10),
|
||||
Category = "tv",
|
||||
Id = "sabnzbd_nzb12345",
|
||||
Title = "Droned.S01E01.Pilot.1080p.WEB-DL-DRONE"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_failed = new SabnzbdHistory
|
||||
{
|
||||
Items = new List<SabnzbdHistoryItem>()
|
||||
{
|
||||
new SabnzbdHistoryItem
|
||||
{
|
||||
Status = SabnzbdDownloadStatus.Failed,
|
||||
Size = 1000,
|
||||
Category = "tv",
|
||||
Id = "sabnzbd_nzb12345",
|
||||
Title = "Droned.S01E01.Pilot.1080p.WEB-DL-DRONE"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_completed = new SabnzbdHistory
|
||||
{
|
||||
Items = new List<SabnzbdHistoryItem>()
|
||||
{
|
||||
new SabnzbdHistoryItem
|
||||
{
|
||||
Status = SabnzbdDownloadStatus.Completed,
|
||||
Size = 1000,
|
||||
Category = "tv",
|
||||
Id = "sabnzbd_nzb12345",
|
||||
Title = "Droned.S01E01.Pilot.1080p.WEB-DL-DRONE",
|
||||
Storage = "somedirectory"
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected void WithFailedDownload()
|
||||
{
|
||||
Mocker.GetMock<ISabnzbdProxy>()
|
||||
.Setup(s => s.DownloadNzb(It.IsAny<Stream>(), It.IsAny<String>(), It.IsAny<String>(), It.IsAny<int>(), It.IsAny<SabnzbdSettings>()))
|
||||
.Returns((SabnzbdAddResponse)null);
|
||||
}
|
||||
|
||||
protected void WithSuccessfulDownload()
|
||||
{
|
||||
Mocker.GetMock<ISabnzbdProxy>()
|
||||
.Setup(s => s.DownloadNzb(It.IsAny<Stream>(), It.IsAny<String>(), It.IsAny<String>(), It.IsAny<int>(), It.IsAny<SabnzbdSettings>()))
|
||||
.Returns(new SabnzbdAddResponse()
|
||||
{
|
||||
Status = true,
|
||||
Ids = new List<string> { "sabznbd_nzo12345" }
|
||||
});
|
||||
}
|
||||
|
||||
protected virtual void WithQueue(SabnzbdQueue queue)
|
||||
{
|
||||
if (queue == null)
|
||||
{
|
||||
queue = new SabnzbdQueue() { Items = new List<SabnzbdQueueItem>() };
|
||||
}
|
||||
|
||||
Mocker.GetMock<ISabnzbdProxy>()
|
||||
.Setup(s => s.GetQueue(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<SabnzbdSettings>()))
|
||||
.Returns(queue);
|
||||
}
|
||||
|
||||
protected virtual void WithHistory(SabnzbdHistory history)
|
||||
{
|
||||
if (history == null)
|
||||
history = new SabnzbdHistory() { Items = new List<SabnzbdHistoryItem>() };
|
||||
|
||||
Mocker.GetMock<ISabnzbdProxy>()
|
||||
.Setup(s => s.GetHistory(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<SabnzbdSettings>()))
|
||||
.Returns(history);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void downloadNzb_should_use_sabRecentTvPriority_when_recentEpisode_is_true()
|
||||
public void GetItems_should_return_no_items_when_queue_is_empty()
|
||||
{
|
||||
WithQueue(null);
|
||||
WithHistory(null);
|
||||
|
||||
Subject.GetItems().Should().BeEmpty();
|
||||
}
|
||||
|
||||
[TestCase(SabnzbdDownloadStatus.Grabbing)]
|
||||
[TestCase(SabnzbdDownloadStatus.Queued)]
|
||||
public void queued_item_should_have_required_properties(SabnzbdDownloadStatus status)
|
||||
{
|
||||
_queued.Items.First().Status = status;
|
||||
|
||||
WithQueue(_queued);
|
||||
WithHistory(null);
|
||||
|
||||
var result = Subject.GetItems().Single();
|
||||
|
||||
VerifyQueued(result);
|
||||
result.RemainingTime.Should().NotBe(TimeSpan.Zero);
|
||||
}
|
||||
|
||||
[TestCase(SabnzbdDownloadStatus.Paused)]
|
||||
public void paused_item_should_have_required_properties(SabnzbdDownloadStatus status)
|
||||
{
|
||||
_queued.Items.First().Status = status;
|
||||
|
||||
WithQueue(_queued);
|
||||
WithHistory(null);
|
||||
|
||||
var result = Subject.GetItems().Single();
|
||||
|
||||
VerifyPaused(result);
|
||||
}
|
||||
|
||||
[TestCase(SabnzbdDownloadStatus.Checking)]
|
||||
[TestCase(SabnzbdDownloadStatus.Downloading)]
|
||||
[TestCase(SabnzbdDownloadStatus.QuickCheck)]
|
||||
[TestCase(SabnzbdDownloadStatus.Verifying)]
|
||||
[TestCase(SabnzbdDownloadStatus.Repairing)]
|
||||
[TestCase(SabnzbdDownloadStatus.Fetching)]
|
||||
[TestCase(SabnzbdDownloadStatus.Extracting)]
|
||||
[TestCase(SabnzbdDownloadStatus.Moving)]
|
||||
[TestCase(SabnzbdDownloadStatus.Running)]
|
||||
public void downloading_item_should_have_required_properties(SabnzbdDownloadStatus status)
|
||||
{
|
||||
_queued.Items.First().Status = status;
|
||||
|
||||
WithQueue(_queued);
|
||||
WithHistory(null);
|
||||
|
||||
var result = Subject.GetItems().Single();
|
||||
|
||||
VerifyDownloading(result);
|
||||
result.RemainingTime.Should().NotBe(TimeSpan.Zero);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void completed_download_should_have_required_properties()
|
||||
{
|
||||
WithQueue(null);
|
||||
WithHistory(_completed);
|
||||
|
||||
var result = Subject.GetItems().Single();
|
||||
|
||||
VerifyCompleted(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void failed_item_should_have_required_properties()
|
||||
{
|
||||
_completed.Items.First().Status = SabnzbdDownloadStatus.Failed;
|
||||
|
||||
WithQueue(null);
|
||||
WithHistory(_completed);
|
||||
|
||||
var result = Subject.GetItems().Single();
|
||||
|
||||
VerifyFailed(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Download_should_return_unique_id()
|
||||
{
|
||||
WithSuccessfulDownload();
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetItems_should_ignore_downloads_from_other_categories()
|
||||
{
|
||||
_completed.Items.First().Category = "myowncat";
|
||||
|
||||
WithQueue(null);
|
||||
WithHistory(_completed);
|
||||
|
||||
var items = Subject.GetItems();
|
||||
|
||||
items.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Download_should_use_sabRecentTvPriority_when_recentEpisode_is_true()
|
||||
{
|
||||
Mocker.GetMock<ISabnzbdProxy>()
|
||||
.Setup(s => s.DownloadNzb(It.IsAny<Stream>(), It.IsAny<String>(), It.IsAny<String>(), (int)SabnzbdPriority.High, It.IsAny<SabnzbdSettings>()))
|
||||
.Returns(new SabnzbdAddResponse());
|
||||
|
||||
Subject.DownloadNzb(_remoteEpisode);
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
remoteEpisode.Episodes = Builder<Episode>.CreateListOfSize(1)
|
||||
.All()
|
||||
.With(e => e.AirDate = DateTime.Today.ToString(Episode.AIR_DATE_FORMAT))
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
Subject.Download(remoteEpisode);
|
||||
|
||||
Mocker.GetMock<ISabnzbdProxy>()
|
||||
.Verify(v => v.DownloadNzb(It.IsAny<Stream>(), It.IsAny<String>(), It.IsAny<String>(), (int)SabnzbdPriority.High, It.IsAny<SabnzbdSettings>()), Times.Once());
|
||||
|
||||
Reference in New Issue
Block a user