fixed AllowedReleaseGroupSpecification

pull/2/head
kay.one 12 years ago committed by Keivan Beigi
parent a4d69cc5ce
commit 67995a5cf6

@ -1,5 +1,6 @@
using FluentAssertions; using FluentAssertions;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.DecisionEngine.Specifications; using NzbDrone.Core.DecisionEngine.Specifications;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
@ -7,7 +8,6 @@ using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.DecisionEngineTests namespace NzbDrone.Core.Test.DecisionEngineTests
{ {
[TestFixture] [TestFixture]
public class AllowedReleaseGroupSpecificationFixture : CoreTest<AllowedReleaseGroupSpecification> public class AllowedReleaseGroupSpecificationFixture : CoreTest<AllowedReleaseGroupSpecification>
{ {
private RemoteEpisode _parseResult; private RemoteEpisode _parseResult;
@ -27,6 +27,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
[Test] [Test]
public void should_be_true_when_allowedReleaseGroups_is_empty() public void should_be_true_when_allowedReleaseGroups_is_empty()
{ {
Subject.IsSatisfiedBy(_parseResult).Should().BeTrue(); Subject.IsSatisfiedBy(_parseResult).Should().BeTrue();
} }
@ -36,15 +37,21 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
Subject.IsSatisfiedBy(_parseResult).Should().BeTrue(); Subject.IsSatisfiedBy(_parseResult).Should().BeTrue();
} }
[Test] [TestCase("2HD")]
public void should_be_true_when_allowedReleaseGroups_contains_nzbs_releaseGroup() [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(); Subject.IsSatisfiedBy(_parseResult).Should().BeTrue();
} }
[Test] [Test]
public void should_be_false_when_allowedReleaseGroups_does_not_contain_nzbs_releaseGroup() 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(); Subject.IsSatisfiedBy(_parseResult).Should().BeFalse();
} }
} }

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

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

@ -1,4 +1,5 @@
using System; using System;
using System.Linq;
using NLog; using NLog;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.Model; using NzbDrone.Core.Model;
@ -33,25 +34,14 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
//Todo: Make this use NzbRestrictions - How should whitelist be used? Will it override blacklist or vice-versa? //Todo: Make this use NzbRestrictions - How should whitelist be used? Will it override blacklist or vice-versa?
//var allowed = _configService.AllowedReleaseGroups; var allowed = _configService.AllowedReleaseGroups;
const string allowed = "";
if (string.IsNullOrWhiteSpace(allowed)) if (string.IsNullOrWhiteSpace(allowed))
return true; return true;
var releaseGroup = subject.Report.ReleaseGroup; var reportReleaseGroup = subject.Report.ReleaseGroup.ToLower();
foreach (var group in allowed.Trim(',', ' ').Split(',')) return allowed.ToLower().Split(',').Any(allowedGroup => allowedGroup.Trim() == reportReleaseGroup);
{
if (releaseGroup.Equals(group.Trim(' '), StringComparison.CurrentCultureIgnoreCase))
{
_logger.Trace("Item: {0}'s release group is wanted: {1}", subject, releaseGroup);
return true;
}
}
_logger.Trace("Item: {0}'s release group is not wanted: {1}", subject, releaseGroup);
return false;
} }
} }
} }

Loading…
Cancel
Save