From 56ecbf4a31e105ccf970ff6f70102b14d18d6637 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Sun, 26 Mar 2017 17:00:59 +0200 Subject: [PATCH] Fixed: Sabnzbd error when tv sorting enabled for all categories. --- .../SabnzbdTests/SabnzbdFixture.cs | 72 +++++++++++++++++++ .../Download/Clients/Sabnzbd/Sabnzbd.cs | 63 ++++++++-------- 2 files changed, 102 insertions(+), 33 deletions(-) diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs index 51b0161a8..e58e4b9a8 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs @@ -101,6 +101,10 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests } }; + Mocker.GetMock() + .Setup(v => v.GetVersion(It.IsAny())) + .Returns("1.2.3"); + Mocker.GetMock() .Setup(s => s.GetConfig(It.IsAny())) .Returns(_config); @@ -490,5 +494,73 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests result.IsValid.Should().BeTrue(); result.HasWarnings.Should().BeTrue(); } + + [Test] + public void should_test_success_if_tv_sorting_disabled() + { + _config.Misc.enable_tv_sorting = false; + _config.Misc.tv_categories = null; + + var result = new NzbDroneValidationResult(Subject.Test()); + + result.IsValid.Should().BeTrue(); + } + + [Test] + public void should_test_failed_if_tv_sorting_null() + { + _config.Misc.enable_tv_sorting = true; + _config.Misc.tv_categories = null; + + var result = new NzbDroneValidationResult(Subject.Test()); + + result.IsValid.Should().BeFalse(); + } + + [Test] + public void should_test_failed_if_tv_sorting_empty() + { + _config.Misc.enable_tv_sorting = true; + _config.Misc.tv_categories = new string[0]; + + var result = new NzbDroneValidationResult(Subject.Test()); + + result.IsValid.Should().BeFalse(); + } + + [Test] + public void should_test_success_if_tv_sorting_contains_different_category() + { + _config.Misc.enable_tv_sorting = true; + _config.Misc.tv_categories = new[] { "tv-custom" }; + + var result = new NzbDroneValidationResult(Subject.Test()); + + result.IsValid.Should().BeTrue(); + } + + [Test] + public void should_test_failed_if_tv_sorting_contains_category() + { + _config.Misc.enable_tv_sorting = true; + _config.Misc.tv_categories = new[] { "tv" }; + + var result = new NzbDroneValidationResult(Subject.Test()); + + result.IsValid.Should().BeFalse(); + } + + [Test] + public void should_test_failed_if_tv_sorting_default_category() + { + Subject.Definition.Settings.As().TvCategory = null; + + _config.Misc.enable_tv_sorting = true; + _config.Misc.tv_categories = new[] { "Default" }; + + var result = new NzbDroneValidationResult(Subject.Test()); + + result.IsValid.Should().BeFalse(); + } } } diff --git a/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs b/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs index a214fae74..70ae19373 100644 --- a/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs +++ b/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs @@ -451,50 +451,47 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd }; } } - - if (config.Misc.enable_tv_sorting) + if (config.Misc.enable_tv_sorting && ContainsCategory(config.Misc.tv_categories, Settings.TvCategory)) { - if (!config.Misc.tv_categories.Any() || - config.Misc.tv_categories.Contains(Settings.TvCategory) || - (Settings.TvCategory.IsNullOrWhiteSpace() && config.Misc.tv_categories.Contains("Default"))) + return new NzbDroneValidationFailure("TvCategory", "Disable TV Sorting") { - return new NzbDroneValidationFailure("TvCategory", "Disable TV Sorting") - { - InfoLink = string.Format("http://{0}:{1}/sabnzbd/config/sorting/", Settings.Host, Settings.Port), - DetailedDescription = "You must disable Sabnzbd TV Sorting for the category Sonarr uses to prevent import issues. Go to Sabnzbd to fix it." - }; - } + InfoLink = string.Format("http://{0}:{1}/sabnzbd/config/sorting/", Settings.Host, Settings.Port), + DetailedDescription = "You must disable Sabnzbd TV Sorting for the category Sonarr uses to prevent import issues. Go to Sabnzbd to fix it." + }; } - - if (config.Misc.enable_movie_sorting) + if (config.Misc.enable_movie_sorting && ContainsCategory(config.Misc.movie_categories, Settings.TvCategory)) { - if (!config.Misc.movie_categories.Any() || - config.Misc.movie_categories.Contains(Settings.TvCategory) || - (Settings.TvCategory.IsNullOrWhiteSpace() && config.Misc.movie_categories.Contains("Default"))) + return new NzbDroneValidationFailure("TvCategory", "Disable Movie Sorting") { - return new NzbDroneValidationFailure("TvCategory", "Disable Movie Sorting") - { - InfoLink = string.Format("http://{0}:{1}/sabnzbd/config/sorting/", Settings.Host, Settings.Port), - DetailedDescription = "You must disable Sabnzbd Movie Sorting for the category Sonarr uses to prevent import issues. Go to Sabnzbd to fix it." - }; - } + InfoLink = string.Format("http://{0}:{1}/sabnzbd/config/sorting/", Settings.Host, Settings.Port), + DetailedDescription = "You must disable Sabnzbd Movie Sorting for the category Sonarr uses to prevent import issues. Go to Sabnzbd to fix it." + }; } - - if (config.Misc.enable_date_sorting) + if (config.Misc.enable_date_sorting && ContainsCategory(config.Misc.date_categories, Settings.TvCategory)) { - if (!config.Misc.date_categories.Any() || - config.Misc.date_categories.Contains(Settings.TvCategory) || - (Settings.TvCategory.IsNullOrWhiteSpace() && config.Misc.date_categories.Contains("Default"))) + return new NzbDroneValidationFailure("TvCategory", "Disable Date Sorting") { - return new NzbDroneValidationFailure("TvCategory", "Disable Date Sorting") - { - InfoLink = string.Format("http://{0}:{1}/sabnzbd/config/sorting/", Settings.Host, Settings.Port), - DetailedDescription = "You must disable Sabnzbd Date Sorting for the category Sonarr uses to prevent import issues. Go to Sabnzbd to fix it." - }; - } + InfoLink = string.Format("http://{0}:{1}/sabnzbd/config/sorting/", Settings.Host, Settings.Port), + DetailedDescription = "You must disable Sabnzbd Date Sorting for the category Sonarr uses to prevent import issues. Go to Sabnzbd to fix it." + }; } return null; } + + private bool ContainsCategory(IEnumerable categories, string category) + { + if (categories == null || categories.Empty()) + { + return true; + } + + if (category.IsNullOrWhiteSpace()) + { + category = "Default"; + } + + return categories.Contains(category); + } } }