1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-26 17:59:14 +00:00

fixed AllowedReleaseGroupSpecification

This commit is contained in:
kay.one 2013-04-16 20:52:43 -07:00 committed by Keivan Beigi
parent a4d69cc5ce
commit 67995a5cf6
4 changed files with 21 additions and 17 deletions

View file

@ -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 @@
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 @@ public void Setup()
[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 @@ public void should_be_true_when_allowedReleaseGroups_is_nzbs_releaseGroup()
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();
} }
} }

View file

@ -479,6 +479,12 @@ public string NzbRestrictions
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);

View file

@ -78,6 +78,7 @@ public interface IConfigService
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);

View file

@ -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 @@ public virtual bool IsSatisfiedBy(RemoteEpisode subject)
//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;
} }
} }
} }