|
|
@ -9,6 +9,7 @@ using NzbDrone.Core.MediaFiles.TorrentInfo;
|
|
|
|
using NzbDrone.Core.Download;
|
|
|
|
using NzbDrone.Core.Download;
|
|
|
|
using NzbDrone.Core.Download.Clients.QBittorrent;
|
|
|
|
using NzbDrone.Core.Download.Clients.QBittorrent;
|
|
|
|
using NzbDrone.Test.Common;
|
|
|
|
using NzbDrone.Test.Common;
|
|
|
|
|
|
|
|
using NzbDrone.Core.Exceptions;
|
|
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
|
|
|
|
namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -99,15 +100,18 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
|
|
|
|
Subject.Definition.Settings.As<QBittorrentSettings>().RecentTvPriority = (int)QBittorrentPriority.First;
|
|
|
|
Subject.Definition.Settings.As<QBittorrentSettings>().RecentTvPriority = (int)QBittorrentPriority.First;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected void GivenMaxRatio(float maxRatio, bool removeOnMaxRatio = true)
|
|
|
|
protected void GivenGlobalSeedLimits(float maxRatio, int maxSeedingTime = -1, bool removeOnMaxRatio = false)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Mocker.GetMock<IQBittorrentProxy>()
|
|
|
|
Mocker.GetMock<IQBittorrentProxy>()
|
|
|
|
.Setup(s => s.GetConfig(It.IsAny<QBittorrentSettings>()))
|
|
|
|
.Setup(s => s.GetConfig(It.IsAny<QBittorrentSettings>()))
|
|
|
|
.Returns(new QBittorrentPreferences
|
|
|
|
.Returns(new QBittorrentPreferences
|
|
|
|
{
|
|
|
|
{
|
|
|
|
RemoveOnMaxRatio = removeOnMaxRatio,
|
|
|
|
RemoveOnMaxRatio = removeOnMaxRatio,
|
|
|
|
MaxRatio = maxRatio
|
|
|
|
MaxRatio = maxRatio,
|
|
|
|
});
|
|
|
|
MaxRatioEnabled = maxRatio >= 0,
|
|
|
|
|
|
|
|
MaxSeedingTime = maxSeedingTime,
|
|
|
|
|
|
|
|
MaxSeedingTimeEnabled = maxSeedingTime >= 0
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual void GivenTorrents(List<QBittorrentTorrent> torrents)
|
|
|
|
protected virtual void GivenTorrents(List<QBittorrentTorrent> torrents)
|
|
|
@ -277,17 +281,33 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
|
|
|
|
id.Should().Be(expectedHash);
|
|
|
|
id.Should().Be(expectedHash);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Download_should_refuse_magnet_if_dht_is_disabled()
|
|
|
|
[Test]
|
|
|
|
|
|
|
|
public void Download_should_refuse_magnet_if_no_trackers_provided_and_dht_is_disabled()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
Mocker.GetMock<IQBittorrentProxy>()
|
|
|
|
|
|
|
|
.Setup(s => s.GetConfig(It.IsAny<QBittorrentSettings>()))
|
|
|
|
|
|
|
|
.Returns(new QBittorrentPreferences() { DhtEnabled = false });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var remoteEpisode = CreateRemoteEpisode();
|
|
|
|
|
|
|
|
remoteEpisode.Release.DownloadUrl = "magnet:?xt=urn:btih:ZPBPA2P6ROZPKRHK44D5OW6NHXU5Z6KR";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.Throws<ReleaseDownloadException>(() => Subject.Download(remoteEpisode));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
|
|
public void Download_should_accept_magnet_if_trackers_provided_and_dht_is_disabled()
|
|
|
|
|
|
|
|
{
|
|
|
|
Mocker.GetMock<IQBittorrentProxy>()
|
|
|
|
Mocker.GetMock<IQBittorrentProxy>()
|
|
|
|
.Setup(s => s.GetConfig(It.IsAny<QBittorrentSettings>()))
|
|
|
|
.Setup(s => s.GetConfig(It.IsAny<QBittorrentSettings>()))
|
|
|
|
.Returns(new QBittorrentPreferences() { DhtEnabled = false });
|
|
|
|
.Returns(new QBittorrentPreferences() { DhtEnabled = false });
|
|
|
|
|
|
|
|
|
|
|
|
var remoteEpisode = CreateRemoteEpisode();
|
|
|
|
var remoteEpisode = CreateRemoteEpisode();
|
|
|
|
remoteEpisode.Release.DownloadUrl = "magnet:?xt=urn:btih:ZPBPA2P6ROZPKRHK44D5OW6NHXU5Z6KR&tr=udp";
|
|
|
|
remoteEpisode.Release.DownloadUrl = "magnet:?xt=urn:btih:ZPBPA2P6ROZPKRHK44D5OW6NHXU5Z6KR&tr=udp://abc";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.DoesNotThrow(() => Subject.Download(remoteEpisode));
|
|
|
|
|
|
|
|
|
|
|
|
Assert.Throws<NotSupportedException>(() => Subject.Download(remoteEpisode));
|
|
|
|
Mocker.GetMock<IQBittorrentProxy>()
|
|
|
|
|
|
|
|
.Verify(s => s.AddTorrentFromUrl(It.IsAny<string>(), It.IsAny<QBittorrentSettings>()), Times.Once());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
[Test]
|
|
|
@ -371,7 +391,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
|
|
|
|
[Test]
|
|
|
|
[Test]
|
|
|
|
public void should_not_be_removable_and_should_not_allow_move_files_if_max_ratio_not_reached()
|
|
|
|
public void should_not_be_removable_and_should_not_allow_move_files_if_max_ratio_not_reached()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
GivenMaxRatio(1.0f);
|
|
|
|
GivenGlobalSeedLimits(1.0f);
|
|
|
|
|
|
|
|
|
|
|
|
var torrent = new QBittorrentTorrent
|
|
|
|
var torrent = new QBittorrentTorrent
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -392,11 +412,11 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
|
|
|
|
item.CanMoveFiles.Should().BeFalse();
|
|
|
|
item.CanMoveFiles.Should().BeFalse();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
protected virtual QBittorrentTorrent GivenCompletedTorrent(
|
|
|
|
public void should_not_be_removable_and_should_not_allow_move_files_if_max_ratio_reached_and_not_paused()
|
|
|
|
string state = "pausedUP",
|
|
|
|
|
|
|
|
float ratio = 0.1f, float ratioLimit = -2,
|
|
|
|
|
|
|
|
int seedingTime = 1, int seedingTimeLimit = -2)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
GivenMaxRatio(1.0f);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var torrent = new QBittorrentTorrent
|
|
|
|
var torrent = new QBittorrentTorrent
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Hash = "HASH",
|
|
|
|
Hash = "HASH",
|
|
|
@ -404,12 +424,32 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
|
|
|
|
Size = 1000,
|
|
|
|
Size = 1000,
|
|
|
|
Progress = 1.0,
|
|
|
|
Progress = 1.0,
|
|
|
|
Eta = 8640000,
|
|
|
|
Eta = 8640000,
|
|
|
|
State = "uploading",
|
|
|
|
State = state,
|
|
|
|
Label = "",
|
|
|
|
Label = "",
|
|
|
|
SavePath = "",
|
|
|
|
SavePath = "",
|
|
|
|
Ratio = 1.0f
|
|
|
|
Ratio = ratio,
|
|
|
|
|
|
|
|
RatioLimit = ratioLimit,
|
|
|
|
|
|
|
|
SeedingTimeLimit = seedingTimeLimit
|
|
|
|
};
|
|
|
|
};
|
|
|
|
GivenTorrents(new List<QBittorrentTorrent> { torrent });
|
|
|
|
|
|
|
|
|
|
|
|
GivenTorrents(new List<QBittorrentTorrent>() { torrent });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IQBittorrentProxy>()
|
|
|
|
|
|
|
|
.Setup(s => s.GetTorrentProperties("HASH", It.IsAny<QBittorrentSettings>()))
|
|
|
|
|
|
|
|
.Returns(new QBittorrentTorrentProperties
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Hash = "HASH",
|
|
|
|
|
|
|
|
SeedingTime = seedingTime
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return torrent;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
|
|
public void should_not_be_removable_and_should_not_allow_move_files_if_max_ratio_reached_and_not_paused()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
GivenGlobalSeedLimits(1.0f);
|
|
|
|
|
|
|
|
GivenCompletedTorrent("uploading", ratio: 1.0f);
|
|
|
|
|
|
|
|
|
|
|
|
var item = Subject.GetItems().Single();
|
|
|
|
var item = Subject.GetItems().Single();
|
|
|
|
item.CanBeRemoved.Should().BeFalse();
|
|
|
|
item.CanBeRemoved.Should().BeFalse();
|
|
|
@ -419,21 +459,8 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
|
|
|
|
[Test]
|
|
|
|
[Test]
|
|
|
|
public void should_not_be_removable_and_should_not_allow_move_files_if_max_ratio_is_not_set()
|
|
|
|
public void should_not_be_removable_and_should_not_allow_move_files_if_max_ratio_is_not_set()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
GivenMaxRatio(1.0f, false);
|
|
|
|
GivenGlobalSeedLimits(-1);
|
|
|
|
|
|
|
|
GivenCompletedTorrent("pausedUP", ratio: 1.0f);
|
|
|
|
var torrent = new QBittorrentTorrent
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Hash = "HASH",
|
|
|
|
|
|
|
|
Name = _title,
|
|
|
|
|
|
|
|
Size = 1000,
|
|
|
|
|
|
|
|
Progress = 1.0,
|
|
|
|
|
|
|
|
Eta = 8640000,
|
|
|
|
|
|
|
|
State = "uploading",
|
|
|
|
|
|
|
|
Label = "",
|
|
|
|
|
|
|
|
SavePath = "",
|
|
|
|
|
|
|
|
Ratio = 1.0f
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
GivenTorrents(new List<QBittorrentTorrent> { torrent });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var item = Subject.GetItems().Single();
|
|
|
|
var item = Subject.GetItems().Single();
|
|
|
|
item.CanBeRemoved.Should().BeFalse();
|
|
|
|
item.CanBeRemoved.Should().BeFalse();
|
|
|
@ -443,21 +470,8 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
|
|
|
|
[Test]
|
|
|
|
[Test]
|
|
|
|
public void should_be_removable_and_should_allow_move_files_if_max_ratio_reached_and_paused()
|
|
|
|
public void should_be_removable_and_should_allow_move_files_if_max_ratio_reached_and_paused()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
GivenMaxRatio(1.0f);
|
|
|
|
GivenGlobalSeedLimits(1.0f);
|
|
|
|
|
|
|
|
GivenCompletedTorrent("pausedUP", ratio: 1.0f);
|
|
|
|
var torrent = new QBittorrentTorrent
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Hash = "HASH",
|
|
|
|
|
|
|
|
Name = _title,
|
|
|
|
|
|
|
|
Size = 1000,
|
|
|
|
|
|
|
|
Progress = 1.0,
|
|
|
|
|
|
|
|
Eta = 8640000,
|
|
|
|
|
|
|
|
State = "pausedUP",
|
|
|
|
|
|
|
|
Label = "",
|
|
|
|
|
|
|
|
SavePath = "",
|
|
|
|
|
|
|
|
Ratio = 1.0f
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
GivenTorrents(new List<QBittorrentTorrent> { torrent });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var item = Subject.GetItems().Single();
|
|
|
|
var item = Subject.GetItems().Single();
|
|
|
|
item.CanBeRemoved.Should().BeTrue();
|
|
|
|
item.CanBeRemoved.Should().BeTrue();
|
|
|
@ -467,22 +481,8 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
|
|
|
|
[Test]
|
|
|
|
[Test]
|
|
|
|
public void should_be_removable_and_should_allow_move_files_if_overridden_max_ratio_reached_and_paused()
|
|
|
|
public void should_be_removable_and_should_allow_move_files_if_overridden_max_ratio_reached_and_paused()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
GivenMaxRatio(2.0f);
|
|
|
|
GivenGlobalSeedLimits(2.0f);
|
|
|
|
|
|
|
|
GivenCompletedTorrent("pausedUP", ratio: 1.0f, ratioLimit: 0.8f);
|
|
|
|
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<QBittorrentTorrent> { torrent });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var item = Subject.GetItems().Single();
|
|
|
|
var item = Subject.GetItems().Single();
|
|
|
|
item.CanBeRemoved.Should().BeTrue();
|
|
|
|
item.CanBeRemoved.Should().BeTrue();
|
|
|
@ -492,33 +492,75 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
|
|
|
|
[Test]
|
|
|
|
[Test]
|
|
|
|
public void should_not_be_removable_if_overridden_max_ratio_not_reached_and_paused()
|
|
|
|
public void should_not_be_removable_if_overridden_max_ratio_not_reached_and_paused()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
GivenMaxRatio(0.2f);
|
|
|
|
GivenGlobalSeedLimits(0.2f);
|
|
|
|
|
|
|
|
GivenCompletedTorrent("pausedUP", ratio: 0.5f, ratioLimit: 0.8f);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var item = Subject.GetItems().Single();
|
|
|
|
|
|
|
|
item.CanBeRemoved.Should().BeFalse();
|
|
|
|
|
|
|
|
item.CanMoveFiles.Should().BeFalse();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var torrent = new QBittorrentTorrent
|
|
|
|
|
|
|
|
{
|
|
|
|
[Test]
|
|
|
|
Hash = "HASH",
|
|
|
|
public void should_not_be_removable_and_should_not_allow_move_files_if_max_seedingtime_reached_and_not_paused()
|
|
|
|
Name = _title,
|
|
|
|
{
|
|
|
|
Size = 1000,
|
|
|
|
GivenGlobalSeedLimits(-1, 20);
|
|
|
|
Progress = 1.0,
|
|
|
|
GivenCompletedTorrent("uploading", ratio: 2.0f, seedingTime: 30);
|
|
|
|
Eta = 8640000,
|
|
|
|
|
|
|
|
State = "pausedUP",
|
|
|
|
|
|
|
|
Label = "",
|
|
|
|
|
|
|
|
SavePath = "",
|
|
|
|
|
|
|
|
Ratio = 0.5f,
|
|
|
|
|
|
|
|
RatioLimit = 0.8f
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
GivenTorrents(new List<QBittorrentTorrent> { torrent });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var item = Subject.GetItems().Single();
|
|
|
|
var item = Subject.GetItems().Single();
|
|
|
|
item.CanBeRemoved.Should().BeFalse();
|
|
|
|
item.CanBeRemoved.Should().BeFalse();
|
|
|
|
item.CanMoveFiles.Should().BeFalse();
|
|
|
|
item.CanMoveFiles.Should().BeFalse();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
|
|
public void should_be_removable_and_should_allow_move_files_if_max_seedingtime_reached_and_paused()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
GivenGlobalSeedLimits(-1, 20);
|
|
|
|
|
|
|
|
GivenCompletedTorrent("pausedUP", ratio: 2.0f, seedingTime: 20);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var item = Subject.GetItems().Single();
|
|
|
|
|
|
|
|
item.CanBeRemoved.Should().BeTrue();
|
|
|
|
|
|
|
|
item.CanMoveFiles.Should().BeTrue();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
|
|
public void should_be_removable_and_should_allow_move_files_if_overridden_max_seedingtime_reached_and_paused()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
GivenGlobalSeedLimits(-1, 40);
|
|
|
|
|
|
|
|
GivenCompletedTorrent("pausedUP", ratio: 2.0f, seedingTime: 20, seedingTimeLimit: 10);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var item = Subject.GetItems().Single();
|
|
|
|
|
|
|
|
item.CanBeRemoved.Should().BeTrue();
|
|
|
|
|
|
|
|
item.CanMoveFiles.Should().BeTrue();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
|
|
public void should_not_be_removable_if_overridden_max_seedingtime_not_reached_and_paused()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
GivenGlobalSeedLimits(-1, 20);
|
|
|
|
|
|
|
|
GivenCompletedTorrent("pausedUP", ratio: 2.0f, seedingTime: 30, seedingTimeLimit: 40);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var item = Subject.GetItems().Single();
|
|
|
|
|
|
|
|
item.CanBeRemoved.Should().BeFalse();
|
|
|
|
|
|
|
|
item.CanMoveFiles.Should().BeFalse();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
|
|
public void should_be_removable_and_should_allow_move_files_if_max_seedingtime_reached_but_ratio_not_and_paused()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
GivenGlobalSeedLimits(2.0f, 20);
|
|
|
|
|
|
|
|
GivenCompletedTorrent("pausedUP", ratio: 1.0f, seedingTime: 30);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var item = Subject.GetItems().Single();
|
|
|
|
|
|
|
|
item.CanBeRemoved.Should().BeTrue();
|
|
|
|
|
|
|
|
item.CanMoveFiles.Should().BeTrue();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
[Test]
|
|
|
|
public void should_get_category_from_the_category_if_set()
|
|
|
|
public void should_get_category_from_the_category_if_set()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const string category = "tv-sonarr";
|
|
|
|
const string category = "tv-sonarr";
|
|
|
|
GivenMaxRatio(1.0f);
|
|
|
|
GivenGlobalSeedLimits(1.0f);
|
|
|
|
|
|
|
|
|
|
|
|
var torrent = new QBittorrentTorrent
|
|
|
|
var torrent = new QBittorrentTorrent
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -543,7 +585,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
|
|
|
|
public void should_get_category_from_the_label_if_the_category_is_not_available()
|
|
|
|
public void should_get_category_from_the_label_if_the_category_is_not_available()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const string category = "tv-sonarr";
|
|
|
|
const string category = "tv-sonarr";
|
|
|
|
GivenMaxRatio(1.0f);
|
|
|
|
GivenGlobalSeedLimits(1.0f);
|
|
|
|
|
|
|
|
|
|
|
|
var torrent = new QBittorrentTorrent
|
|
|
|
var torrent = new QBittorrentTorrent
|
|
|
|
{
|
|
|
|
{
|
|
|
|