From 91c5e6f12292e522ceb9094825525fb3684b97c6 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sun, 24 Nov 2024 15:20:44 -0800 Subject: [PATCH] Fixed: Custom Format upgrading not respecting 'Upgrades Allowed' --- .../UpgradeDiskSpecificationFixture.cs | 34 +++++++++++++++++++ .../Specifications/UpgradableSpecification.cs | 3 +- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/NzbDrone.Core.Test/DecisionEngineTests/UpgradeDiskSpecificationFixture.cs b/src/NzbDrone.Core.Test/DecisionEngineTests/UpgradeDiskSpecificationFixture.cs index 66a38f076..658810bbc 100644 --- a/src/NzbDrone.Core.Test/DecisionEngineTests/UpgradeDiskSpecificationFixture.cs +++ b/src/NzbDrone.Core.Test/DecisionEngineTests/UpgradeDiskSpecificationFixture.cs @@ -11,6 +11,7 @@ using NzbDrone.Core.Languages; using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Parser; using NzbDrone.Core.Parser.Model; +using NzbDrone.Core.Profiles; using NzbDrone.Core.Profiles.Qualities; using NzbDrone.Core.Qualities; using NzbDrone.Core.Test.CustomFormats; @@ -365,5 +366,38 @@ namespace NzbDrone.Core.Test.DecisionEngineTests Subject.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeFalse(); } + + [Test] + public void should_return_false_if_quality_profile_does_not_allow_upgrades_but_format_cutoff_is_above_current_score() + { + var customFormat = new CustomFormat("My Format", new ResolutionSpecification { Value = (int)Resolution.R1080p }) { Id = 1 }; + + GivenProfile(new QualityProfile + { + Cutoff = Quality.SDTV.Id, + MinFormatScore = 0, + CutoffFormatScore = 10000, + Items = Qualities.QualityFixture.GetDefaultQualities(), + FormatItems = CustomFormatsTestHelpers.GetSampleFormatItems("My Format"), + UpgradeAllowed = false + }); + + _parseResultSingle.Series.QualityProfile.Value.FormatItems = new List + { + new ProfileFormatItem + { + Format = customFormat, + Score = 50 + } + }; + + GivenFileQuality(new QualityModel(Quality.WEBDL1080p)); + GivenNewQuality(new QualityModel(Quality.WEBDL1080p)); + + GivenOldCustomFormats(new List()); + GivenNewCustomFormats(new List { customFormat }); + + Subject.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeFalse(); + } } } diff --git a/src/NzbDrone.Core/DecisionEngine/Specifications/UpgradableSpecification.cs b/src/NzbDrone.Core/DecisionEngine/Specifications/UpgradableSpecification.cs index 916560f8c..ceaf3815c 100644 --- a/src/NzbDrone.Core/DecisionEngine/Specifications/UpgradableSpecification.cs +++ b/src/NzbDrone.Core/DecisionEngine/Specifications/UpgradableSpecification.cs @@ -135,8 +135,9 @@ namespace NzbDrone.Core.DecisionEngine.Specifications private bool CustomFormatCutoffNotMet(QualityProfile profile, List currentFormats) { var score = profile.CalculateCustomFormatScore(currentFormats); + var cutoff = profile.UpgradeAllowed ? profile.CutoffFormatScore : profile.MinFormatScore; - return score < profile.CutoffFormatScore; + return score < cutoff; } public bool CutoffNotMet(QualityProfile profile, QualityModel currentQuality, List currentFormats, QualityModel newQuality = null)