From 08ba2730898d443d3ce6fa19adafbf3bee10294d Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Sun, 3 Mar 2019 21:19:25 +0100 Subject: [PATCH] fixed qbittorrent tests failing due to incorrect test setup. And http tests failed due to httpbin changing their output. --- .../Http/HttpClientFixture.cs | 8 +- .../QBittorrentTests/QBittorrentFixture.cs | 94 ++++++++++++++++--- .../Clients/QBittorrent/QBittorrent.cs | 4 +- 3 files changed, 86 insertions(+), 20 deletions(-) diff --git a/src/NzbDrone.Common.Test/Http/HttpClientFixture.cs b/src/NzbDrone.Common.Test/Http/HttpClientFixture.cs index bf890a81b..4bcd23222 100644 --- a/src/NzbDrone.Common.Test/Http/HttpClientFixture.cs +++ b/src/NzbDrone.Common.Test/Http/HttpClientFixture.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Globalization; using System.IO; @@ -130,11 +130,12 @@ namespace NzbDrone.Common.Test.Http [Test] public void should_execute_typed_get() { - var request = new HttpRequest($"http://{_httpBinHost}/get"); + var request = new HttpRequest($"http://{_httpBinHost}/get?test=1"); var response = Subject.Get(request); - response.Resource.Url.Should().Be(request.Url.FullUri); + response.Resource.Url.EndsWith("/get?test=1"); + response.Resource.Args.Should().Contain("test", "1"); } [Test] @@ -706,6 +707,7 @@ namespace NzbDrone.Common.Test.Http public class HttpBinResource { + public Dictionary Args { get; set; } public Dictionary Headers { get; set; } public string Origin { get; set; } public string Url { get; set; } diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/QBittorrentTests/QBittorrentFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/QBittorrentTests/QBittorrentFixture.cs index cc36a447b..94ce08bba 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/QBittorrentTests/QBittorrentFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/QBittorrentTests/QBittorrentFixture.cs @@ -20,13 +20,13 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests { Subject.Definition = new DownloadClientDefinition(); Subject.Definition.Settings = new QBittorrentSettings - { - Host = "127.0.0.1", - Port = 2222, - Username = "admin", - Password = "pass", - TvCategory = "tv" - }; + { + Host = "127.0.0.1", + Port = 2222, + Username = "admin", + Password = "pass", + TvCategory = "tv" + }; Mocker.GetMock() .Setup(s => s.GetHashFromTorrentFile(It.IsAny())) @@ -38,7 +38,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests Mocker.GetMock() .Setup(s => s.GetConfig(It.IsAny())) - .Returns(new QBittorrentPreferences()); + .Returns(new QBittorrentPreferences() { DhtEnabled = true }); Mocker.GetMock() .Setup(s => s.GetProxy(It.IsAny(), It.IsAny())) @@ -104,10 +104,10 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests Mocker.GetMock() .Setup(s => s.GetConfig(It.IsAny())) .Returns(new QBittorrentPreferences - { - RemoveOnMaxRatio = removeOnMaxRatio, - MaxRatio = maxRatio - }); + { + RemoveOnMaxRatio = removeOnMaxRatio, + MaxRatio = maxRatio + }); } protected virtual void GivenTorrents(List torrents) @@ -158,7 +158,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests var item = Subject.GetItems().Single(); VerifyPaused(item); - item.RemainingTime.Should().NotBe(TimeSpan.Zero); + item.RemainingTime.Should().NotHaveValue(); } [TestCase("pausedUP")] @@ -189,6 +189,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests [TestCase("queuedDL")] [TestCase("checkingDL")] + [TestCase("metaDL")] public void queued_item_should_have_required_properties(string state) { var torrent = new QBittorrentTorrent @@ -206,7 +207,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests var item = Subject.GetItems().Single(); VerifyQueued(item); - item.RemainingTime.Should().NotBe(TimeSpan.Zero); + item.RemainingTime.Should().NotHaveValue(); } [Test] @@ -248,7 +249,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests var item = Subject.GetItems().Single(); VerifyWarning(item); - item.RemainingTime.Should().NotBe(TimeSpan.Zero); + item.RemainingTime.Should().NotHaveValue(); } [Test] @@ -276,6 +277,19 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests id.Should().Be(expectedHash); } + public void Download_should_refuse_magnet_if_dht_is_disabled() + { + + Mocker.GetMock() + .Setup(s => s.GetConfig(It.IsAny())) + .Returns(new QBittorrentPreferences() { DhtEnabled = false }); + + var remoteEpisode = CreateRemoteEpisode(); + remoteEpisode.Release.DownloadUrl = "magnet:?xt=urn:btih:ZPBPA2P6ROZPKRHK44D5OW6NHXU5Z6KR&tr=udp"; + + Assert.Throws(() => Subject.Download(remoteEpisode)); + } + [Test] public void Download_should_set_top_priority() { @@ -450,6 +464,56 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests item.CanMoveFiles.Should().BeTrue(); } + [Test] + public void should_be_removable_and_should_allow_move_files_if_overridden_max_ratio_reached_and_paused() + { + GivenMaxRatio(2.0f); + + var torrent = new QBittorrentTorrent + { + Hash = "HASH", + Name = _title, + Size = 1000, + Progress = 1.0, + Eta = 8640000, + State = "pausedUP", + Label = "", + SavePath = "", + Ratio = 1.0f, + RatioLimit = 0.8f + }; + GivenTorrents(new List { torrent }); + + var item = Subject.GetItems().Single(); + item.CanBeRemoved.Should().BeTrue(); + item.CanMoveFiles.Should().BeTrue(); + } + + [Test] + public void should_not_be_removable_if_overridden_max_ratio_not_reached_and_paused() + { + GivenMaxRatio(0.2f); + + var torrent = new QBittorrentTorrent + { + Hash = "HASH", + Name = _title, + Size = 1000, + Progress = 1.0, + Eta = 8640000, + State = "pausedUP", + Label = "", + SavePath = "", + Ratio = 0.5f, + RatioLimit = 0.8f + }; + GivenTorrents(new List { torrent }); + + var item = Subject.GetItems().Single(); + item.CanBeRemoved.Should().BeFalse(); + item.CanMoveFiles.Should().BeFalse(); + } + [Test] public void should_get_category_from_the_category_if_set() { diff --git a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs index af43aac9a..05ae7bdad 100644 --- a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs @@ -57,7 +57,7 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent SetInitialState(hash.ToLower()); - if (remoteEpisode.SeedConfiguration.Ratio.HasValue || remoteEpisode.SeedConfiguration.SeedTime.HasValue) + if (remoteEpisode.SeedConfiguration != null && (remoteEpisode.SeedConfiguration.Ratio.HasValue || remoteEpisode.SeedConfiguration.SeedTime.HasValue)) { Proxy.SetTorrentSeedingConfiguration(hash.ToLower(), remoteEpisode.SeedConfiguration, Settings); } @@ -98,7 +98,7 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent SetInitialState(hash.ToLower()); - if (remoteEpisode.SeedConfiguration.Ratio.HasValue || remoteEpisode.SeedConfiguration.SeedTime.HasValue) + if (remoteEpisode.SeedConfiguration != null && (remoteEpisode.SeedConfiguration.Ratio.HasValue || remoteEpisode.SeedConfiguration.SeedTime.HasValue)) { Proxy.SetTorrentSeedingConfiguration(hash.ToLower(), remoteEpisode.SeedConfiguration, Settings); }