mirror of
https://github.com/Radarr/Radarr.git
synced 2026-04-23 22:25:14 -04:00
New: uTorrent differential api support to handle larger lists of torrents without hogging the api.
Fixes #1109
This commit is contained in:
+51
-10
@@ -84,7 +84,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.UTorrentTests
|
||||
DownloadUrl = _downloadUrl,
|
||||
RootDownloadPath = "somepath"
|
||||
};
|
||||
|
||||
|
||||
Mocker.GetMock<ITorrentFileInfoReader>()
|
||||
.Setup(s => s.GetHashFromTorrentFile(It.IsAny<byte[]>()))
|
||||
.Returns("CBC2F069FE8BB2F544EAE707D75BCD3DE9DCF951");
|
||||
@@ -130,8 +130,8 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.UTorrentTests
|
||||
PrepareClientToReturnQueuedItem();
|
||||
});
|
||||
}
|
||||
|
||||
protected virtual void GivenTorrents(List<UTorrentTorrent> torrents)
|
||||
|
||||
protected virtual void GivenTorrents(List<UTorrentTorrent> torrents, string cacheNumber = null)
|
||||
{
|
||||
if (torrents == null)
|
||||
{
|
||||
@@ -139,13 +139,30 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.UTorrentTests
|
||||
}
|
||||
|
||||
Mocker.GetMock<IUTorrentProxy>()
|
||||
.Setup(s => s.GetTorrents(It.IsAny<UTorrentSettings>()))
|
||||
.Returns(torrents);
|
||||
.Setup(s => s.GetTorrents(It.IsAny<string>(), It.IsAny<UTorrentSettings>()))
|
||||
.Returns(new UTorrentResponse { Torrents = torrents, CacheNumber = cacheNumber });
|
||||
}
|
||||
|
||||
protected virtual void GivenDifferentialTorrents(string oldCacheNumber, List<UTorrentTorrent> changed, List<string> removed, string cacheNumber)
|
||||
{
|
||||
if (changed == null)
|
||||
{
|
||||
changed = new List<UTorrentTorrent>();
|
||||
}
|
||||
|
||||
if (removed == null)
|
||||
{
|
||||
removed = new List<string>();
|
||||
}
|
||||
|
||||
Mocker.GetMock<IUTorrentProxy>()
|
||||
.Setup(s => s.GetTorrents(oldCacheNumber, It.IsAny<UTorrentSettings>()))
|
||||
.Returns(new UTorrentResponse { TorrentsChanged = changed, TorrentsRemoved = removed, CacheNumber = cacheNumber });
|
||||
}
|
||||
|
||||
protected void PrepareClientToReturnQueuedItem()
|
||||
{
|
||||
GivenTorrents(new List<UTorrentTorrent>
|
||||
GivenTorrents(new List<UTorrentTorrent>
|
||||
{
|
||||
_queued
|
||||
});
|
||||
@@ -153,7 +170,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.UTorrentTests
|
||||
|
||||
protected void PrepareClientToReturnDownloadingItem()
|
||||
{
|
||||
GivenTorrents(new List<UTorrentTorrent>
|
||||
GivenTorrents(new List<UTorrentTorrent>
|
||||
{
|
||||
_downloading
|
||||
});
|
||||
@@ -161,7 +178,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.UTorrentTests
|
||||
|
||||
protected void PrepareClientToReturnFailedItem()
|
||||
{
|
||||
GivenTorrents(new List<UTorrentTorrent>
|
||||
GivenTorrents(new List<UTorrentTorrent>
|
||||
{
|
||||
_failed
|
||||
});
|
||||
@@ -296,13 +313,13 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.UTorrentTests
|
||||
public void should_return_status_with_outputdirs()
|
||||
{
|
||||
var configItems = new Dictionary<string, string>();
|
||||
|
||||
|
||||
configItems.Add("dir_active_download_flag", "true");
|
||||
configItems.Add("dir_active_download", @"C:\Downloads\Downloading\utorrent".AsOsAgnostic());
|
||||
configItems.Add("dir_completed_download", @"C:\Downloads\Finished\utorrent".AsOsAgnostic());
|
||||
configItems.Add("dir_completed_download_flag", "true");
|
||||
configItems.Add("dir_add_label", "true");
|
||||
|
||||
|
||||
Mocker.GetMock<IUTorrentProxy>()
|
||||
.Setup(v => v.GetConfig(It.IsAny<UTorrentSettings>()))
|
||||
.Returns(configItems);
|
||||
@@ -353,5 +370,29 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.UTorrentTests
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetItems_should_query_with_cache_id_if_available()
|
||||
{
|
||||
_downloading.Status = UTorrentTorrentStatus.Started;
|
||||
|
||||
GivenTorrents(new List<UTorrentTorrent> { _downloading }, "abc");
|
||||
|
||||
var item1 = Subject.GetItems().Single();
|
||||
|
||||
Mocker.GetMock<IUTorrentProxy>().Verify(v => v.GetTorrents(null, It.IsAny<UTorrentSettings>()), Times.Once());
|
||||
|
||||
GivenTorrents(new List<UTorrentTorrent> { _downloading, _queued }, "abc2");
|
||||
GivenDifferentialTorrents("abc", new List<UTorrentTorrent> { _queued }, new List<string>(), "abc2");
|
||||
GivenDifferentialTorrents("abc2", new List<UTorrentTorrent>(), new List<string>(), "abc2");
|
||||
|
||||
var item2 = Subject.GetItems().Single();
|
||||
|
||||
Mocker.GetMock<IUTorrentProxy>().Verify(v => v.GetTorrents("abc", It.IsAny<UTorrentSettings>()), Times.Once());
|
||||
|
||||
var item3 = Subject.GetItems().Single();
|
||||
|
||||
Mocker.GetMock<IUTorrentProxy>().Verify(v => v.GetTorrents("abc2", It.IsAny<UTorrentSettings>()), Times.Once());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user