NzbRestrictions are now used, no more allowed release groups

This commit is contained in:
Mark McDowall 2013-07-01 19:34:38 -07:00
parent 244d3a8a58
commit 8bb4b06d28
8 changed files with 110 additions and 114 deletions

View File

@ -1,58 +0,0 @@
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.DecisionEngine.Specifications;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.DecisionEngineTests
{
[TestFixture]
public class AllowedReleaseGroupSpecificationFixture : CoreTest<AllowedReleaseGroupSpecification>
{
private RemoteEpisode _parseResult;
[SetUp]
public void Setup()
{
_parseResult = new RemoteEpisode
{
Report = new ReportInfo
{
ReleaseGroup = "2HD"
}
};
}
[Test]
public void should_be_true_when_allowedReleaseGroups_is_empty()
{
Subject.IsSatisfiedBy(_parseResult).Should().BeTrue();
}
[Test]
public void should_be_true_when_allowedReleaseGroups_is_nzbs_releaseGroup()
{
Subject.IsSatisfiedBy(_parseResult).Should().BeTrue();
}
[TestCase("2HD")]
[TestCase("2hd")]
[TestCase("other, 2hd, next")]
[TestCase("other,2hd,next")]
[TestCase("other,2hd,next,")]
public void should_be_true_when_allowedReleaseGroups_contains_nzbs_releaseGroup(string allowedList)
{
Mocker.GetMock<IConfigService>().SetupGet(c => c.AllowedReleaseGroups).Returns(allowedList);
Subject.IsSatisfiedBy(_parseResult).Should().BeTrue();
}
[Test]
public void should_be_false_when_allowedReleaseGroups_does_not_contain_nzbs_releaseGroup()
{
Mocker.GetMock<IConfigService>().SetupGet(c => c.AllowedReleaseGroups).Returns("other");
Subject.IsSatisfiedBy(_parseResult).Should().BeFalse();
}
}
}

View File

@ -0,0 +1,51 @@
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.DecisionEngine.Specifications;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.DecisionEngineTests
{
[TestFixture]
public class NotRestrictedNzbSpecificationFixture : CoreTest<NotRestrictedNzbSpecification>
{
private RemoteEpisode _parseResult;
[SetUp]
public void Setup()
{
_parseResult = new RemoteEpisode
{
Report = new ReportInfo
{
Title = "Dexter.S08E01.EDITED.WEBRip.x264-KYR"
}
};
}
[Test]
public void should_be_true_when_restrictions_are_empty()
{
Subject.IsSatisfiedBy(_parseResult).Should().BeTrue();
}
[TestCase("KYR")]
[TestCase("EDITED")]
[TestCase("2HD\nKYR")]
public void should_be_false_when_nzb_contains_a_restricted_term(string restrictions)
{
Mocker.GetMock<IConfigService>().SetupGet(c => c.NzbRestrictions).Returns(restrictions);
Subject.IsSatisfiedBy(_parseResult).Should().BeFalse();
}
[TestCase("NotReal")]
[TestCase("LoL")]
[TestCase("Hello\nWorld")]
public void should_be_true_when_nzb_does_not_contain_a_restricted_term(string restrictions)
{
Mocker.GetMock<IConfigService>().SetupGet(c => c.NzbRestrictions).Returns(restrictions);
Subject.IsSatisfiedBy(_parseResult).Should().BeTrue();
}
}
}

View File

@ -124,6 +124,7 @@
<Compile Include="Datastore\PagingSpecExtenstionsTests\ToSortDirectionFixture.cs" />
<Compile Include="Datastore\PagingSpecExtenstionsTests\PagingOffsetFixture.cs" />
<Compile Include="Datastore\ReflectionStrategyFixture\Benchmarks.cs" />
<Compile Include="DecisionEngineTests\NotRestrictedNzbSpecificationFixture.cs" />
<Compile Include="Download\DownloadApprovedReportsTests\DownloadApprovedFixture.cs" />
<Compile Include="Download\DownloadApprovedReportsTests\GetQualifiedReportsFixture.cs" />
<Compile Include="Download\DownloadClientTests\BlackholeProviderFixture.cs" />
@ -167,7 +168,6 @@
<Compile Include="EpisodeParseResultTest.cs" />
<Compile Include="ParserTests\QualityParserFixture.cs" />
<Compile Include="Configuration\ConfigCachingFixture.cs" />
<Compile Include="DecisionEngineTests\AllowedReleaseGroupSpecificationFixture.cs" />
<Compile Include="DecisionEngineTests\CustomStartDateSpecificationFixture.cs" />
<Compile Include="ProviderTests\DiskScanProviderTests\GetVideoFilesFixture.cs" />
<Compile Include="ProviderTests\RecycleBinProviderTests\CleanupFixture.cs" />

View File

@ -277,12 +277,6 @@ namespace NzbDrone.Core.Configuration
set { SetValue("NzbRestrictions", value); }
}
public string AllowedReleaseGroups
{
get { return GetValue("AllowedReleaseGroups", String.Empty); }
set { SetValue("AllowedReleaseGroups", value); }
}
private string GetValue(string key)
{
return GetValue(key, String.Empty);

View File

@ -43,7 +43,6 @@ namespace NzbDrone.Core.Configuration
PriorityType NzbgetBacklogTvPriority { get; set; }
PriorityType NzbgetRecentTvPriority { get; set; }
string NzbRestrictions { get; set; }
string AllowedReleaseGroups { get; set; }
string GetValue(string key, object defaultValue, bool persist = false);
void SetValue(string key, string value);
void SaveValues(Dictionary<string, object> configValues);

View File

@ -1,47 +0,0 @@
using System;
using System.Linq;
using NLog;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Model;
using NzbDrone.Core.Parser;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.DecisionEngine.Specifications
{
public class AllowedReleaseGroupSpecification : IDecisionEngineSpecification
{
private readonly IConfigService _configService;
private readonly Logger _logger;
public AllowedReleaseGroupSpecification(IConfigService configService, Logger logger)
{
_configService = configService;
_logger = logger;
}
public string RejectionReason
{
get
{
return "Release group is blacklisted.";
}
}
public virtual bool IsSatisfiedBy(RemoteEpisode subject)
{
_logger.Trace("Beginning release group check for: {0}", subject);
//Todo: Make this use NzbRestrictions - How should whitelist be used? Will it override blacklist or vice-versa?
var allowed = _configService.AllowedReleaseGroups;
if (string.IsNullOrWhiteSpace(allowed))
return true;
var reportReleaseGroup = subject.Report.ReleaseGroup.ToLower();
return allowed.ToLower().Split(',').Any(allowedGroup => allowedGroup.Trim() == reportReleaseGroup);
}
}
}

View File

@ -0,0 +1,57 @@
using System;
using System.Linq;
using NLog;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Model;
using NzbDrone.Core.Parser;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.DecisionEngine.Specifications
{
public class NotRestrictedNzbSpecification : IDecisionEngineSpecification
{
private readonly IConfigService _configService;
private readonly Logger _logger;
public NotRestrictedNzbSpecification(IConfigService configService, Logger logger)
{
_configService = configService;
_logger = logger;
}
public string RejectionReason
{
get
{
return "Contrains restricted term.";
}
}
public virtual bool IsSatisfiedBy(RemoteEpisode subject)
{
_logger.Trace("Checking if Nzb contains any restrictions: {0}", subject);
var restrictionsString = _configService.NzbRestrictions;
if (String.IsNullOrWhiteSpace(restrictionsString))
{
_logger.Trace("No restrictions configured, allowing: {0}", subject);
return true;
}
var restrictions = restrictionsString.Split('\n');
foreach (var restriction in restrictions)
{
if (subject.Report.Title.Contains(restriction))
{
_logger.Trace("{0} is restricted: {1}", subject, restriction);
return false;
}
}
_logger.Trace("No restrictions apply, allowing: {0}", subject);
return true;
}
}
}

View File

@ -227,12 +227,12 @@
<Compile Include="DecisionEngine\DownloadDecision.cs" />
<Compile Include="DecisionEngine\IRejectWithReason.cs" />
<Compile Include="DecisionEngine\IDecisionEngineSpecification.cs" />
<Compile Include="DecisionEngine\Specifications\NotRestrictedNzbSpecification.cs" />
<Compile Include="DecisionEngine\Specifications\Search\SeasonMatchSpecification.cs" />
<Compile Include="DecisionEngine\Specifications\Search\DailyEpisodeMatchSpecification.cs" />
<Compile Include="DecisionEngine\Specifications\Search\IDecisionEngineSearchSpecification.cs" />
<Compile Include="DecisionEngine\Specifications\AcceptableSizeSpecification.cs" />
<Compile Include="DecisionEngine\DownloadDecisionMaker.cs" />
<Compile Include="DecisionEngine\Specifications\AllowedReleaseGroupSpecification.cs" />
<Compile Include="DecisionEngine\Specifications\NotInQueueSpecification.cs" />
<Compile Include="DecisionEngine\Specifications\CustomStartDateSpecification.cs" />
<Compile Include="DecisionEngine\Specifications\LanguageSpecification.cs" />