mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-21 22:04:31 -04:00
Implement Release Parsing, Decision Engine, and Downloading (#35)
* Implement Parsing, Decision Engine, and Downloading
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
@@ -12,7 +12,7 @@ using NzbDrone.Core.Exceptions;
|
||||
using NzbDrone.Core.Indexers;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.Download
|
||||
@@ -20,7 +20,7 @@ namespace NzbDrone.Core.Test.Download
|
||||
[TestFixture]
|
||||
public class DownloadServiceFixture : CoreTest<DownloadService>
|
||||
{
|
||||
private RemoteEpisode _parseResult;
|
||||
private RemoteAlbum _parseResult;
|
||||
private List<IDownloadClient> _downloadClients;
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
@@ -35,10 +35,10 @@ namespace NzbDrone.Core.Test.Download
|
||||
.Setup(v => v.GetDownloadClient(It.IsAny<DownloadProtocol>()))
|
||||
.Returns<DownloadProtocol>(v => _downloadClients.FirstOrDefault(d => d.Protocol == v));
|
||||
|
||||
var episodes = Builder<Episode>.CreateListOfSize(2)
|
||||
var episodes = Builder<Album>.CreateListOfSize(2)
|
||||
.TheFirst(1).With(s => s.Id = 12)
|
||||
.TheNext(1).With(s => s.Id = 99)
|
||||
.All().With(s => s.SeriesId = 5)
|
||||
.All().With(s => s.ArtistId = 5)
|
||||
.Build().ToList();
|
||||
|
||||
var releaseInfo = Builder<ReleaseInfo>.CreateNew()
|
||||
@@ -46,10 +46,10 @@ namespace NzbDrone.Core.Test.Download
|
||||
.With(v => v.DownloadUrl = "http://test.site/download1.ext")
|
||||
.Build();
|
||||
|
||||
_parseResult = Builder<RemoteEpisode>.CreateNew()
|
||||
.With(c => c.Series = Builder<Series>.CreateNew().Build())
|
||||
_parseResult = Builder<RemoteAlbum>.CreateNew()
|
||||
.With(c => c.Artist = Builder<Artist>.CreateNew().Build())
|
||||
.With(c => c.Release = releaseInfo)
|
||||
.With(c => c.Episodes = episodes)
|
||||
.With(c => c.Albums = episodes)
|
||||
.Build();
|
||||
}
|
||||
|
||||
@@ -81,42 +81,42 @@ namespace NzbDrone.Core.Test.Download
|
||||
public void Download_report_should_publish_on_grab_event()
|
||||
{
|
||||
var mock = WithUsenetClient();
|
||||
mock.Setup(s => s.Download(It.IsAny<RemoteEpisode>()));
|
||||
mock.Setup(s => s.Download(It.IsAny<RemoteAlbum>()));
|
||||
|
||||
Subject.DownloadReport(_parseResult);
|
||||
|
||||
VerifyEventPublished<EpisodeGrabbedEvent>();
|
||||
VerifyEventPublished<AlbumGrabbedEvent>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Download_report_should_grab_using_client()
|
||||
{
|
||||
var mock = WithUsenetClient();
|
||||
mock.Setup(s => s.Download(It.IsAny<RemoteEpisode>()));
|
||||
mock.Setup(s => s.Download(It.IsAny<RemoteAlbum>()));
|
||||
|
||||
Subject.DownloadReport(_parseResult);
|
||||
|
||||
mock.Verify(s => s.Download(It.IsAny<RemoteEpisode>()), Times.Once());
|
||||
mock.Verify(s => s.Download(It.IsAny<RemoteAlbum>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Download_report_should_not_publish_on_failed_grab_event()
|
||||
{
|
||||
var mock = WithUsenetClient();
|
||||
mock.Setup(s => s.Download(It.IsAny<RemoteEpisode>()))
|
||||
mock.Setup(s => s.Download(It.IsAny<RemoteAlbum>()))
|
||||
.Throws(new WebException());
|
||||
|
||||
Assert.Throws<WebException>(() => Subject.DownloadReport(_parseResult));
|
||||
|
||||
VerifyEventNotPublished<EpisodeGrabbedEvent>();
|
||||
VerifyEventNotPublished<AlbumGrabbedEvent>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Download_report_should_trigger_indexer_backoff_on_indexer_error()
|
||||
{
|
||||
var mock = WithUsenetClient();
|
||||
mock.Setup(s => s.Download(It.IsAny<RemoteEpisode>()))
|
||||
.Callback<RemoteEpisode>(v => {
|
||||
mock.Setup(s => s.Download(It.IsAny<RemoteAlbum>()))
|
||||
.Callback<RemoteAlbum>(v => {
|
||||
throw new ReleaseDownloadException(v.Release, "Error", new WebException());
|
||||
});
|
||||
|
||||
@@ -134,8 +134,8 @@ namespace NzbDrone.Core.Test.Download
|
||||
response.Headers["Retry-After"] = "300";
|
||||
|
||||
var mock = WithUsenetClient();
|
||||
mock.Setup(s => s.Download(It.IsAny<RemoteEpisode>()))
|
||||
.Callback<RemoteEpisode>(v => {
|
||||
mock.Setup(s => s.Download(It.IsAny<RemoteAlbum>()))
|
||||
.Callback<RemoteAlbum>(v => {
|
||||
throw new ReleaseDownloadException(v.Release, "Error", new TooManyRequestsException(request, response));
|
||||
});
|
||||
|
||||
@@ -153,8 +153,8 @@ namespace NzbDrone.Core.Test.Download
|
||||
response.Headers["Retry-After"] = DateTime.UtcNow.AddSeconds(300).ToString("r");
|
||||
|
||||
var mock = WithUsenetClient();
|
||||
mock.Setup(s => s.Download(It.IsAny<RemoteEpisode>()))
|
||||
.Callback<RemoteEpisode>(v =>
|
||||
mock.Setup(s => s.Download(It.IsAny<RemoteAlbum>()))
|
||||
.Callback<RemoteAlbum>(v =>
|
||||
{
|
||||
throw new ReleaseDownloadException(v.Release, "Error", new TooManyRequestsException(request, response));
|
||||
});
|
||||
@@ -170,7 +170,7 @@ namespace NzbDrone.Core.Test.Download
|
||||
public void Download_report_should_not_trigger_indexer_backoff_on_downloadclient_error()
|
||||
{
|
||||
var mock = WithUsenetClient();
|
||||
mock.Setup(s => s.Download(It.IsAny<RemoteEpisode>()))
|
||||
mock.Setup(s => s.Download(It.IsAny<RemoteAlbum>()))
|
||||
.Throws(new DownloadClientException("Some Error"));
|
||||
|
||||
Assert.Throws<DownloadClientException>(() => Subject.DownloadReport(_parseResult));
|
||||
@@ -184,7 +184,7 @@ namespace NzbDrone.Core.Test.Download
|
||||
{
|
||||
Subject.DownloadReport(_parseResult);
|
||||
|
||||
Mocker.GetMock<IDownloadClient>().Verify(c => c.Download(It.IsAny<RemoteEpisode>()), Times.Never());
|
||||
Mocker.GetMock<IDownloadClient>().Verify(c => c.Download(It.IsAny<RemoteAlbum>()), Times.Never());
|
||||
VerifyEventNotPublished<EpisodeGrabbedEvent>();
|
||||
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
@@ -198,8 +198,8 @@ namespace NzbDrone.Core.Test.Download
|
||||
|
||||
Subject.DownloadReport(_parseResult);
|
||||
|
||||
mockTorrent.Verify(c => c.Download(It.IsAny<RemoteEpisode>()), Times.Never());
|
||||
mockUsenet.Verify(c => c.Download(It.IsAny<RemoteEpisode>()), Times.Once());
|
||||
mockTorrent.Verify(c => c.Download(It.IsAny<RemoteAlbum>()), Times.Never());
|
||||
mockUsenet.Verify(c => c.Download(It.IsAny<RemoteAlbum>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -212,8 +212,8 @@ namespace NzbDrone.Core.Test.Download
|
||||
|
||||
Subject.DownloadReport(_parseResult);
|
||||
|
||||
mockTorrent.Verify(c => c.Download(It.IsAny<RemoteEpisode>()), Times.Once());
|
||||
mockUsenet.Verify(c => c.Download(It.IsAny<RemoteEpisode>()), Times.Never());
|
||||
mockTorrent.Verify(c => c.Download(It.IsAny<RemoteAlbum>()), Times.Once());
|
||||
mockUsenet.Verify(c => c.Download(It.IsAny<RemoteAlbum>()), Times.Never());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user