Fixed: Only upgrade anime version when release group is the same

pull/3113/head
Mark McDowall 10 years ago
parent 9056bc1747
commit 485fa6a13d

@ -0,0 +1,111 @@
using System;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using Marr.Data;
using NUnit.Framework;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.DecisionEngine.Specifications;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.DecisionEngineTests
{
[TestFixture]
public class AnimeVersionUpgradeSpecificationFixture : CoreTest<AnimeVersionUpgradeSpecification>
{
private AnimeVersionUpgradeSpecification _subject;
private RemoteEpisode _remoteEpisode;
private EpisodeFile _episodeFile;
[SetUp]
public void Setup()
{
Mocker.Resolve<QualityUpgradableSpecification>();
_subject = Mocker.Resolve<AnimeVersionUpgradeSpecification>();
_episodeFile = new EpisodeFile
{
Quality = new QualityModel(Quality.HDTV720p, new Revision()),
ReleaseGroup = "DRONE2"
};
_remoteEpisode = new RemoteEpisode();
_remoteEpisode.Series = new Series { SeriesType = SeriesTypes.Anime };
_remoteEpisode.ParsedEpisodeInfo = new ParsedEpisodeInfo
{
Quality = new QualityModel(Quality.HDTV720p, new Revision(2)),
ReleaseGroup = "DRONE"
};
_remoteEpisode.Episodes = Builder<Episode>.CreateListOfSize(1)
.All()
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>(_episodeFile))
.Build()
.ToList();
}
private void GivenStandardSeries()
{
_remoteEpisode.Series.SeriesType = SeriesTypes.Standard;
}
private void GivenNoVersionUpgrade()
{
_remoteEpisode.ParsedEpisodeInfo.Quality.Revision = new Revision();
}
[Test]
public void should_be_true_when_no_existing_file()
{
_remoteEpisode.Episodes.First().EpisodeFileId = 0;
_subject.IsSatisfiedBy(_remoteEpisode, null).Should().BeTrue();
}
[Test]
public void should_be_true_if_series_is_not_anime()
{
GivenStandardSeries();
_subject.IsSatisfiedBy(_remoteEpisode, null).Should().BeTrue();
}
[Test]
public void should_be_true_if_is_not_a_version_upgrade_for_existing_file()
{
GivenNoVersionUpgrade();
_subject.IsSatisfiedBy(_remoteEpisode, null).Should().BeTrue();
}
[Test]
public void should_be_true_when_release_group_matches()
{
_episodeFile.ReleaseGroup = _remoteEpisode.ParsedEpisodeInfo.ReleaseGroup;
_subject.IsSatisfiedBy(_remoteEpisode, null).Should().BeTrue();
}
[Test]
public void should_be_false_when_existing_file_doesnt_have_a_release_group()
{
_episodeFile.ReleaseGroup = String.Empty;
_subject.IsSatisfiedBy(_remoteEpisode, null).Should().BeFalse();
}
[Test]
public void should_should_be_false_when_release_doesnt_have_a_release_group()
{
_remoteEpisode.ParsedEpisodeInfo.ReleaseGroup = String.Empty;
_subject.IsSatisfiedBy(_remoteEpisode, null).Should().BeFalse();
}
[Test]
public void should_be_false_when_release_group_does_not_match()
{
_subject.IsSatisfiedBy(_remoteEpisode, null).Should().BeFalse();
}
}
}

@ -10,7 +10,6 @@ using NzbDrone.Core.Profiles;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Queue;
namespace NzbDrone.Core.Test.DecisionEngineTests
{

@ -122,6 +122,7 @@
<Compile Include="Datastore\ReflectionStrategyFixture\Benchmarks.cs" />
<Compile Include="Datastore\SqliteSchemaDumperTests\SqliteSchemaDumperFixture.cs" />
<Compile Include="DecisionEngineTests\AcceptableSizeSpecificationFixture.cs" />
<Compile Include="DecisionEngineTests\AnimeVersionUpgradeSpecificationFixture.cs" />
<Compile Include="DecisionEngineTests\CutoffSpecificationFixture.cs" />
<Compile Include="DecisionEngineTests\DownloadDecisionMakerFixture.cs" />
<Compile Include="DecisionEngineTests\HistorySpecificationFixture.cs" />

@ -0,0 +1,67 @@
using System.Linq;
using NLog;
using NzbDrone.Common;
using NzbDrone.Core.IndexerSearch.Definitions;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.DecisionEngine.Specifications
{
public class AnimeVersionUpgradeSpecification : IDecisionEngineSpecification
{
private readonly QualityUpgradableSpecification _qualityUpgradableSpecification;
private readonly Logger _logger;
public AnimeVersionUpgradeSpecification(QualityUpgradableSpecification qualityUpgradableSpecification, Logger logger)
{
_qualityUpgradableSpecification = qualityUpgradableSpecification;
_logger = logger;
}
public string RejectionReason
{
get
{
return "Version upgrade for a different release group";
}
}
public RejectionType Type { get { return RejectionType.Permanent; } }
public virtual bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
{
var releaseGroup = subject.ParsedEpisodeInfo.ReleaseGroup;
if (subject.Series.SeriesType != SeriesTypes.Anime)
{
return true;
}
foreach (var file in subject.Episodes.Where(c => c.EpisodeFileId != 0).Select(c => c.EpisodeFile.Value))
{
if (_qualityUpgradableSpecification.IsRevisionUpgrade(file.Quality, subject.ParsedEpisodeInfo.Quality))
{
if (file.ReleaseGroup.IsNullOrWhiteSpace())
{
_logger.Debug("Unable to compare release group, existing file's release group is unknown");
return false;
}
if (releaseGroup.IsNullOrWhiteSpace())
{
_logger.Debug("Unable to compare release group, release's release group is unknown");
return false;
}
if (file.ReleaseGroup != releaseGroup)
{
_logger.Debug("Existing Release group is: {0} - release's release group is: {1}", file.ReleaseGroup, releaseGroup);
return false;
}
}
}
return true;
}
}
}

@ -5,7 +5,6 @@ using NzbDrone.Core.Download;
using NzbDrone.Core.IndexerSearch.Definitions;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Queue;
namespace NzbDrone.Core.DecisionEngine.Specifications
{

@ -254,6 +254,7 @@
<Compile Include="DecisionEngine\RejectionType.cs" />
<Compile Include="DecisionEngine\Specifications\AcceptableSizeSpecification.cs" />
<Compile Include="DecisionEngine\Specifications\BlacklistSpecification.cs" />
<Compile Include="DecisionEngine\Specifications\AnimeVersionUpgradeSpecification.cs" />
<Compile Include="DecisionEngine\Specifications\CutoffSpecification.cs" />
<Compile Include="DecisionEngine\Specifications\LanguageSpecification.cs" />
<Compile Include="DecisionEngine\Specifications\NotInQueueSpecification.cs" />

Loading…
Cancel
Save