From f0d10fe1cd5f67e040dcd01bee5280bd9d2b9dd5 Mon Sep 17 00:00:00 2001 From: Qstick Date: Sun, 8 Jan 2023 20:24:13 -0600 Subject: [PATCH] Fixed: Correct messaging when release is not upgrade Fixes #7963 --- .../UpgradeAllowedSpecificationFixture.cs | 211 ++++++++++++++++++ .../Specifications/UpgradableSpecification.cs | 8 +- 2 files changed, 218 insertions(+), 1 deletion(-) create mode 100644 src/NzbDrone.Core.Test/DecisionEngineTests/UpgradeAllowedSpecificationFixture.cs diff --git a/src/NzbDrone.Core.Test/DecisionEngineTests/UpgradeAllowedSpecificationFixture.cs b/src/NzbDrone.Core.Test/DecisionEngineTests/UpgradeAllowedSpecificationFixture.cs new file mode 100644 index 000000000..202f4bd8b --- /dev/null +++ b/src/NzbDrone.Core.Test/DecisionEngineTests/UpgradeAllowedSpecificationFixture.cs @@ -0,0 +1,211 @@ +using System.Collections.Generic; +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Core.CustomFormats; +using NzbDrone.Core.DecisionEngine.Specifications; +using NzbDrone.Core.Profiles; +using NzbDrone.Core.Qualities; +using NzbDrone.Core.Test.Framework; + +namespace NzbDrone.Core.Test.DecisionEngineTests +{ + [TestFixture] + public class UpgradeAllowedSpecificationFixture : CoreTest + { + private CustomFormat _customFormatOne; + private CustomFormat _customFormatTwo; + private Profile _qualityProfile; + + [SetUp] + public void Setup() + { + _customFormatOne = new CustomFormat + { + Id = 1, + Name = "One" + }; + _customFormatTwo = new CustomFormat + { + Id = 2, + Name = "Two" + }; + + _qualityProfile = new Profile + { + Cutoff = Quality.Bluray1080p.Id, + Items = Qualities.QualityFixture.GetDefaultQualities(), + UpgradeAllowed = false, + CutoffFormatScore = 100, + FormatItems = new List + { + new ProfileFormatItem + { + Id = 1, + Format = _customFormatOne, + Score = 50 + }, + new ProfileFormatItem + { + Id = 1, + Format = _customFormatTwo, + Score = 100 + } + } + }; + } + + [Test] + public void should_return_false_when_quality_is_better_custom_formats_are_the_same_and_upgrading_is_not_allowed() + { + _qualityProfile.UpgradeAllowed = false; + + Subject.IsUpgradeAllowed( + _qualityProfile, + new QualityModel(Quality.DVD), + new List(), + new QualityModel(Quality.Bluray1080p), + new List()) + .Should().BeFalse(); + } + + [Test] + public void should_return_false_when_quality_is_same_and_custom_format_is_upgrade_and_upgrading_is_not_allowed() + { + _qualityProfile.UpgradeAllowed = false; + + Subject.IsUpgradeAllowed( + _qualityProfile, + new QualityModel(Quality.DVD), + new List { _customFormatOne }, + new QualityModel(Quality.DVD), + new List { _customFormatTwo }) + .Should().BeFalse(); + } + + [Test] + public void should_return_true_for_custom_format_upgrade_when_upgrading_is_allowed() + { + _qualityProfile.UpgradeAllowed = true; + + Subject.IsUpgradeAllowed( + _qualityProfile, + new QualityModel(Quality.DVD), + new List { _customFormatOne }, + new QualityModel(Quality.DVD), + new List { _customFormatTwo }) + .Should().BeTrue(); + } + + [Test] + public void should_return_true_for_same_custom_format_score_when_upgrading_is_not_allowed() + { + _qualityProfile.UpgradeAllowed = false; + + Subject.IsUpgradeAllowed( + _qualityProfile, + new QualityModel(Quality.DVD), + new List { _customFormatOne }, + new QualityModel(Quality.DVD), + new List { _customFormatOne }) + .Should().BeTrue(); + } + + [Test] + public void should_return_true_for_lower_custom_format_score_when_upgrading_is_allowed() + { + _qualityProfile.UpgradeAllowed = true; + + Subject.IsUpgradeAllowed( + _qualityProfile, + new QualityModel(Quality.DVD), + new List { _customFormatTwo }, + new QualityModel(Quality.DVD), + new List { _customFormatOne }) + .Should().BeTrue(); + } + + [Test] + public void should_return_true_for_lower_language_when_upgrading_is_not_allowed() + { + _qualityProfile.UpgradeAllowed = false; + + Subject.IsUpgradeAllowed( + _qualityProfile, + new QualityModel(Quality.DVD), + new List { _customFormatTwo }, + new QualityModel(Quality.DVD), + new List { _customFormatOne }) + .Should().BeTrue(); + } + + [Test] + public void should_return_true_for_quality_upgrade_when_upgrading_is_allowed() + { + _qualityProfile.UpgradeAllowed = true; + + Subject.IsUpgradeAllowed( + _qualityProfile, + new QualityModel(Quality.DVD), + new List(), + new QualityModel(Quality.Bluray1080p), + new List()) + .Should().BeTrue(); + } + + [Test] + public void should_return_true_for_same_quality_when_upgrading_is_allowed() + { + _qualityProfile.UpgradeAllowed = true; + + Subject.IsUpgradeAllowed( + _qualityProfile, + new QualityModel(Quality.DVD), + new List(), + new QualityModel(Quality.DVD), + new List()) + .Should().BeTrue(); + } + + [Test] + public void should_return_true_for_same_quality_when_upgrading_is_not_allowed() + { + _qualityProfile.UpgradeAllowed = false; + + Subject.IsUpgradeAllowed( + _qualityProfile, + new QualityModel(Quality.DVD), + new List(), + new QualityModel(Quality.DVD), + new List()) + .Should().BeTrue(); + } + + [Test] + public void should_return_true_for_lower_quality_when_upgrading_is_allowed() + { + _qualityProfile.UpgradeAllowed = true; + + Subject.IsUpgradeAllowed( + _qualityProfile, + new QualityModel(Quality.DVD), + new List(), + new QualityModel(Quality.SDTV), + new List()) + .Should().BeTrue(); + } + + [Test] + public void should_return_true_for_lower_quality_when_upgrading_is_not_allowed() + { + _qualityProfile.UpgradeAllowed = false; + + Subject.IsUpgradeAllowed( + _qualityProfile, + new QualityModel(Quality.DVD), + new List(), + new QualityModel(Quality.SDTV), + new List()) + .Should().BeTrue(); + } + } +} diff --git a/src/NzbDrone.Core/DecisionEngine/Specifications/UpgradableSpecification.cs b/src/NzbDrone.Core/DecisionEngine/Specifications/UpgradableSpecification.cs index aaaa9c342..782559e80 100644 --- a/src/NzbDrone.Core/DecisionEngine/Specifications/UpgradableSpecification.cs +++ b/src/NzbDrone.Core/DecisionEngine/Specifications/UpgradableSpecification.cs @@ -144,7 +144,13 @@ namespace NzbDrone.Core.DecisionEngine.Specifications return true; } - return false; + if ((isQualityUpgrade || isCustomFormatUpgrade) && !qualityProfile.UpgradeAllowed) + { + _logger.Debug("Quality profile does not allow upgrades, skipping"); + return false; + } + + return true; } } }