mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-23 22:25:09 -04:00
Implement Release Parsing, Decision Engine, and Downloading (#35)
* Implement Parsing, Decision Engine, and Downloading
This commit is contained in:
@@ -11,9 +11,8 @@ using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Profiles;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
@@ -23,13 +22,13 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
{
|
||||
private HistorySpecification _upgradeHistory;
|
||||
|
||||
private RemoteEpisode _parseResultMulti;
|
||||
private RemoteEpisode _parseResultSingle;
|
||||
private RemoteAlbum _parseResultMulti;
|
||||
private RemoteAlbum _parseResultSingle;
|
||||
private QualityModel _upgradableQuality;
|
||||
private QualityModel _notupgradableQuality;
|
||||
private Series _fakeSeries;
|
||||
private const int FIRST_EPISODE_ID = 1;
|
||||
private const int SECOND_EPISODE_ID = 2;
|
||||
private Artist _fakeArtist;
|
||||
private const int FIRST_ALBUM_ID = 1;
|
||||
private const int SECOND_ALBUM_ID = 2;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
@@ -37,29 +36,29 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
Mocker.Resolve<QualityUpgradableSpecification>();
|
||||
_upgradeHistory = Mocker.Resolve<HistorySpecification>();
|
||||
|
||||
var singleEpisodeList = new List<Episode> { new Episode { Id = FIRST_EPISODE_ID, SeasonNumber = 12, EpisodeNumber = 3 } };
|
||||
var doubleEpisodeList = new List<Episode> {
|
||||
new Episode {Id = FIRST_EPISODE_ID, SeasonNumber = 12, EpisodeNumber = 3 },
|
||||
new Episode {Id = SECOND_EPISODE_ID, SeasonNumber = 12, EpisodeNumber = 4 },
|
||||
new Episode {Id = 3, SeasonNumber = 12, EpisodeNumber = 5 }
|
||||
var singleAlbumList = new List<Album> { new Album { Id = FIRST_ALBUM_ID} };
|
||||
var doubleAlbumList = new List<Album> {
|
||||
new Album {Id = FIRST_ALBUM_ID },
|
||||
new Album {Id = SECOND_ALBUM_ID },
|
||||
new Album {Id = 3 }
|
||||
};
|
||||
|
||||
_fakeSeries = Builder<Series>.CreateNew()
|
||||
_fakeArtist = Builder<Artist>.CreateNew()
|
||||
.With(c => c.Profile = new Profile { Cutoff = Quality.MP3_512, Items = Qualities.QualityFixture.GetDefaultQualities() })
|
||||
.Build();
|
||||
|
||||
_parseResultMulti = new RemoteEpisode
|
||||
_parseResultMulti = new RemoteAlbum
|
||||
{
|
||||
Series = _fakeSeries,
|
||||
ParsedEpisodeInfo = new ParsedEpisodeInfo { Quality = new QualityModel(Quality.MP3_192, new Revision(version: 2)) },
|
||||
Episodes = doubleEpisodeList
|
||||
Artist = _fakeArtist,
|
||||
ParsedAlbumInfo = new ParsedAlbumInfo { Quality = new QualityModel(Quality.MP3_192, new Revision(version: 2)) },
|
||||
Albums = doubleAlbumList
|
||||
};
|
||||
|
||||
_parseResultSingle = new RemoteEpisode
|
||||
_parseResultSingle = new RemoteAlbum
|
||||
{
|
||||
Series = _fakeSeries,
|
||||
ParsedEpisodeInfo = new ParsedEpisodeInfo { Quality = new QualityModel(Quality.MP3_192, new Revision(version: 2)) },
|
||||
Episodes = singleEpisodeList
|
||||
Artist = _fakeArtist,
|
||||
ParsedAlbumInfo = new ParsedAlbumInfo { Quality = new QualityModel(Quality.MP3_192, new Revision(version: 2)) },
|
||||
Albums = singleAlbumList
|
||||
};
|
||||
|
||||
_upgradableQuality = new QualityModel(Quality.MP3_192, new Revision(version: 1));
|
||||
@@ -70,9 +69,9 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
.Returns(true);
|
||||
}
|
||||
|
||||
private void GivenMostRecentForEpisode(int episodeId, string downloadId, QualityModel quality, DateTime date, HistoryEventType eventType)
|
||||
private void GivenMostRecentForAlbum(int albumId, string downloadId, QualityModel quality, DateTime date, HistoryEventType eventType)
|
||||
{
|
||||
Mocker.GetMock<IHistoryService>().Setup(s => s.MostRecentForEpisode(episodeId))
|
||||
Mocker.GetMock<IHistoryService>().Setup(s => s.MostRecentForAlbum(albumId))
|
||||
.Returns(new History.History { DownloadId = downloadId, Quality = quality, Date = date, EventType = eventType });
|
||||
}
|
||||
|
||||
@@ -92,14 +91,14 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
[Test]
|
||||
public void should_return_true_if_latest_history_item_is_null()
|
||||
{
|
||||
Mocker.GetMock<IHistoryService>().Setup(s => s.MostRecentForEpisode(It.IsAny<int>())).Returns((History.History)null);
|
||||
Mocker.GetMock<IHistoryService>().Setup(s => s.MostRecentForAlbum(It.IsAny<int>())).Returns((History.History)null);
|
||||
_upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Accepted.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_latest_history_item_is_not_grabbed()
|
||||
{
|
||||
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow, HistoryEventType.DownloadFailed);
|
||||
GivenMostRecentForAlbum(FIRST_ALBUM_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow, HistoryEventType.DownloadFailed);
|
||||
_upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Accepted.Should().BeTrue();
|
||||
}
|
||||
|
||||
@@ -113,57 +112,57 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
[Test]
|
||||
public void should_return_true_if_latest_history_item_is_older_than_twelve_hours()
|
||||
{
|
||||
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow.AddHours(-13), HistoryEventType.Grabbed);
|
||||
GivenMostRecentForAlbum(FIRST_ALBUM_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow.AddHours(-12).AddMilliseconds(-1), HistoryEventType.Grabbed);
|
||||
_upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Accepted.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_upgradable_if_only_episode_is_upgradable()
|
||||
public void should_be_upgradable_if_only_album_is_upgradable()
|
||||
{
|
||||
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
|
||||
GivenMostRecentForAlbum(FIRST_ALBUM_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
|
||||
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_upgradable_if_both_episodes_are_upgradable()
|
||||
public void should_be_upgradable_if_both_albums_are_upgradable()
|
||||
{
|
||||
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
|
||||
GivenMostRecentForEpisode(SECOND_EPISODE_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
|
||||
GivenMostRecentForAlbum(FIRST_ALBUM_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
|
||||
GivenMostRecentForAlbum(SECOND_ALBUM_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
|
||||
_upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Accepted.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_be_upgradable_if_both_episodes_are_not_upgradable()
|
||||
public void should_not_be_upgradable_if_both_albums_are_not_upgradable()
|
||||
{
|
||||
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
|
||||
GivenMostRecentForEpisode(SECOND_EPISODE_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
|
||||
GivenMostRecentForAlbum(FIRST_ALBUM_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
|
||||
GivenMostRecentForAlbum(SECOND_ALBUM_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
|
||||
_upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Accepted.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_not_upgradable_if_only_first_episodes_is_upgradable()
|
||||
public void should_be_not_upgradable_if_only_first_albums_is_upgradable()
|
||||
{
|
||||
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
|
||||
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
|
||||
GivenMostRecentForAlbum(FIRST_ALBUM_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
|
||||
GivenMostRecentForAlbum(FIRST_ALBUM_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
|
||||
_upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Accepted.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_not_upgradable_if_only_second_episodes_is_upgradable()
|
||||
public void should_be_not_upgradable_if_only_second_albums_is_upgradable()
|
||||
{
|
||||
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
|
||||
GivenMostRecentForEpisode(SECOND_EPISODE_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
|
||||
GivenMostRecentForAlbum(FIRST_ALBUM_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
|
||||
GivenMostRecentForAlbum(SECOND_ALBUM_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
|
||||
_upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Accepted.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_be_upgradable_if_episode_is_of_same_quality_as_existing()
|
||||
public void should_not_be_upgradable_if_album_is_of_same_quality_as_existing()
|
||||
{
|
||||
_fakeSeries.Profile = new Profile { Cutoff = Quality.MP3_512, Items = Qualities.QualityFixture.GetDefaultQualities() };
|
||||
_parseResultSingle.ParsedEpisodeInfo.Quality = new QualityModel(Quality.MP3_512, new Revision(version: 1));
|
||||
_fakeArtist.Profile = new Profile { Cutoff = Quality.MP3_512, Items = Qualities.QualityFixture.GetDefaultQualities() };
|
||||
_parseResultSingle.ParsedAlbumInfo.Quality = new QualityModel(Quality.MP3_512, new Revision(version: 1));
|
||||
_upgradableQuality = new QualityModel(Quality.MP3_512, new Revision(version: 1));
|
||||
|
||||
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
|
||||
GivenMostRecentForAlbum(FIRST_ALBUM_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
|
||||
|
||||
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeFalse();
|
||||
}
|
||||
@@ -171,11 +170,11 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
[Test]
|
||||
public void should_not_be_upgradable_if_cutoff_already_met()
|
||||
{
|
||||
_fakeSeries.Profile = new Profile { Cutoff = Quality.MP3_512, Items = Qualities.QualityFixture.GetDefaultQualities() };
|
||||
_parseResultSingle.ParsedEpisodeInfo.Quality = new QualityModel(Quality.MP3_512, new Revision(version: 1));
|
||||
_fakeArtist.Profile = new Profile { Cutoff = Quality.MP3_512, Items = Qualities.QualityFixture.GetDefaultQualities() };
|
||||
_parseResultSingle.ParsedAlbumInfo.Quality = new QualityModel(Quality.MP3_512, new Revision(version: 1));
|
||||
_upgradableQuality = new QualityModel(Quality.MP3_512, new Revision(version: 1));
|
||||
|
||||
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
|
||||
GivenMostRecentForAlbum(FIRST_ALBUM_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
|
||||
|
||||
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeFalse();
|
||||
}
|
||||
@@ -183,7 +182,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
[Test]
|
||||
public void should_return_false_if_latest_history_item_is_only_one_hour_old()
|
||||
{
|
||||
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow.AddHours(-1), HistoryEventType.Grabbed);
|
||||
GivenMostRecentForAlbum(FIRST_ALBUM_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow.AddHours(-1), HistoryEventType.Grabbed);
|
||||
_upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Accepted.Should().BeFalse();
|
||||
}
|
||||
|
||||
@@ -191,7 +190,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
public void should_return_false_if_latest_history_has_a_download_id_and_cdh_is_disabled()
|
||||
{
|
||||
GivenCdhDisabled();
|
||||
GivenMostRecentForEpisode(FIRST_EPISODE_ID, "test", _upgradableQuality, DateTime.UtcNow.AddDays(-100), HistoryEventType.Grabbed);
|
||||
GivenMostRecentForAlbum(FIRST_ALBUM_ID, "test", _upgradableQuality, DateTime.UtcNow.AddDays(-100), HistoryEventType.Grabbed);
|
||||
_upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Accepted.Should().BeTrue();
|
||||
}
|
||||
|
||||
@@ -199,20 +198,20 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
public void should_return_false_if_cutoff_already_met_and_cdh_is_disabled()
|
||||
{
|
||||
GivenCdhDisabled();
|
||||
_fakeSeries.Profile = new Profile { Cutoff = Quality.MP3_512, Items = Qualities.QualityFixture.GetDefaultQualities() };
|
||||
_parseResultSingle.ParsedEpisodeInfo.Quality = new QualityModel(Quality.MP3_512, new Revision(version: 1));
|
||||
_fakeArtist.Profile = new Profile { Cutoff = Quality.MP3_512, Items = Qualities.QualityFixture.GetDefaultQualities() };
|
||||
_parseResultSingle.ParsedAlbumInfo.Quality = new QualityModel(Quality.MP3_512, new Revision(version: 1));
|
||||
_upgradableQuality = new QualityModel(Quality.MP3_512, new Revision(version: 1));
|
||||
|
||||
GivenMostRecentForEpisode(FIRST_EPISODE_ID, "test", _upgradableQuality, DateTime.UtcNow.AddDays(-100), HistoryEventType.Grabbed);
|
||||
GivenMostRecentForAlbum(FIRST_ALBUM_ID, "test", _upgradableQuality, DateTime.UtcNow.AddDays(-100), HistoryEventType.Grabbed);
|
||||
|
||||
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_only_episode_is_not_upgradable_and_cdh_is_disabled()
|
||||
public void should_return_false_if_only_album_is_not_upgradable_and_cdh_is_disabled()
|
||||
{
|
||||
GivenCdhDisabled();
|
||||
GivenMostRecentForEpisode(FIRST_EPISODE_ID, "test", _notupgradableQuality, DateTime.UtcNow.AddDays(-100), HistoryEventType.Grabbed);
|
||||
GivenMostRecentForAlbum(FIRST_ALBUM_ID, "test", _notupgradableQuality, DateTime.UtcNow.AddDays(-100), HistoryEventType.Grabbed);
|
||||
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeFalse();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user