Skip to content

Commit 37cb978

Browse files
xobustmarkolo25
andauthored
New: RQBit download client
Co-authored-by: Mark Mendoza <markolo25@gmail.com>
1 parent 7fdc4d6 commit 37cb978

File tree

12 files changed

+937
-0
lines changed

12 files changed

+937
-0
lines changed
Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using System.Threading.Tasks;
4+
using FluentAssertions;
5+
using Moq;
6+
using NUnit.Framework;
7+
using NzbDrone.Core.Download;
8+
using NzbDrone.Core.Download.Clients.RQBit;
9+
using NzbDrone.Core.MediaFiles.TorrentInfo;
10+
11+
namespace NzbDrone.Core.Test.Download.DownloadClientTests.RQBitTests
12+
{
13+
[TestFixture]
14+
public class RQBitFixture : DownloadClientFixtureBase<RQBit>
15+
{
16+
protected RQBitTorrent _queued;
17+
protected RQBitTorrent _downloading;
18+
protected RQBitTorrent _failed;
19+
protected RQBitTorrent _completed;
20+
21+
[SetUp]
22+
public void Setup()
23+
{
24+
Subject.Definition = new DownloadClientDefinition();
25+
Subject.Definition.Settings = new RQbitSettings
26+
{
27+
Host = "127.0.0.1",
28+
Port = 3030,
29+
UseSsl = false
30+
};
31+
32+
_queued = new RQBitTorrent
33+
{
34+
Hash = "HASH",
35+
IsFinished = false,
36+
IsActive = false,
37+
Name = _title,
38+
TotalSize = 1000,
39+
RemainingSize = 1000,
40+
Path = "somepath"
41+
};
42+
43+
_downloading = new RQBitTorrent
44+
{
45+
Hash = "HASH",
46+
IsFinished = false,
47+
IsActive = true,
48+
Name = _title,
49+
TotalSize = 1000,
50+
RemainingSize = 100,
51+
Path = "somepath"
52+
};
53+
54+
_failed = new RQBitTorrent
55+
{
56+
Hash = "HASH",
57+
IsFinished = false,
58+
IsActive = false,
59+
Name = _title,
60+
TotalSize = 1000,
61+
RemainingSize = 1000,
62+
Path = "somepath"
63+
};
64+
65+
_completed = new RQBitTorrent
66+
{
67+
Hash = "HASH",
68+
IsFinished = true,
69+
IsActive = false,
70+
Name = _title,
71+
TotalSize = 1000,
72+
RemainingSize = 0,
73+
Path = "somepath"
74+
};
75+
76+
Mocker.GetMock<ITorrentFileInfoReader>()
77+
.Setup(s => s.GetHashFromTorrentFile(It.IsAny<byte[]>()))
78+
.Returns("CBC2F069FE8BB2F544EAE707D75BCD3DE9DCF951");
79+
}
80+
81+
protected void GivenSuccessfulDownload()
82+
{
83+
Mocker.GetMock<IRQbitProxy>()
84+
.Setup(s => s.AddTorrentFromUrl(It.IsAny<string>(), It.IsAny<RQbitSettings>()))
85+
.Returns("CBC2F069FE8BB2F544EAE707D75BCD3DE9DCF951");
86+
Mocker.GetMock<IRQbitProxy>()
87+
.Setup(s => s.AddTorrentFromFile(It.IsAny<string>(), It.IsAny<byte[]>(), It.IsAny<RQbitSettings>()))
88+
.Returns("CBC2F069FE8BB2F544EAE707D75BCD3DE9DCF951");
89+
}
90+
91+
protected virtual void GivenTorrents(List<RQBitTorrent> torrents)
92+
{
93+
if (torrents == null)
94+
{
95+
torrents = new List<RQBitTorrent>();
96+
}
97+
98+
Mocker.GetMock<IRQbitProxy>()
99+
.Setup(s => s.GetTorrents(It.IsAny<RQbitSettings>()))
100+
.Returns(torrents);
101+
}
102+
103+
protected void PrepareClientToReturnQueuedItem()
104+
{
105+
GivenTorrents(new List<RQBitTorrent>
106+
{
107+
_queued
108+
});
109+
}
110+
111+
protected void PrepareClientToReturnDownloadingItem()
112+
{
113+
GivenTorrents(new List<RQBitTorrent>
114+
{
115+
_downloading
116+
});
117+
}
118+
119+
protected void PrepareClientToReturnFailedItem()
120+
{
121+
GivenTorrents(new List<RQBitTorrent>
122+
{
123+
_failed
124+
});
125+
}
126+
127+
protected void PrepareClientToReturnCompletedItem()
128+
{
129+
GivenTorrents(new List<RQBitTorrent>
130+
{
131+
_completed
132+
});
133+
}
134+
135+
[Test]
136+
public void queued_item_should_have_required_properties()
137+
{
138+
PrepareClientToReturnQueuedItem();
139+
var item = Subject.GetItems().Single();
140+
VerifyPaused(item);
141+
}
142+
143+
[Test]
144+
public void downloading_item_should_have_required_properties()
145+
{
146+
PrepareClientToReturnDownloadingItem();
147+
var item = Subject.GetItems().Single();
148+
VerifyDownloading(item);
149+
}
150+
151+
[Test]
152+
public void failed_item_should_have_required_properties()
153+
{
154+
PrepareClientToReturnFailedItem();
155+
var item = Subject.GetItems().Single();
156+
VerifyPaused(item);
157+
}
158+
159+
[Test]
160+
public void completed_download_should_have_required_properties()
161+
{
162+
PrepareClientToReturnCompletedItem();
163+
var item = Subject.GetItems().Single();
164+
VerifyCompleted(item);
165+
}
166+
167+
[Test]
168+
public async Task Download_should_return_unique_id()
169+
{
170+
GivenSuccessfulDownload();
171+
172+
var remoteEpisode = CreateRemoteEpisode();
173+
174+
var id = await Subject.Download(remoteEpisode, CreateIndexer());
175+
176+
id.Should().NotBeNullOrEmpty();
177+
}
178+
179+
[TestCase("magnet:?xt=urn:btih:ZPBPA2P6ROZPKRHK44D5OW6NHXU5Z6KR&tr=udp", "CBC2F069FE8BB2F544EAE707D75BCD3DE9DCF951")]
180+
public async Task Download_should_get_hash_from_magnet_url(string magnetUrl, string expectedHash)
181+
{
182+
GivenSuccessfulDownload();
183+
184+
var remoteEpisode = CreateRemoteEpisode();
185+
remoteEpisode.Release.DownloadUrl = magnetUrl;
186+
187+
var id = await Subject.Download(remoteEpisode, CreateIndexer());
188+
189+
id.Should().Be(expectedHash);
190+
}
191+
192+
[Test]
193+
public void should_return_status_with_outputdirs()
194+
{
195+
var result = Subject.GetStatus();
196+
197+
result.IsLocalhost.Should().BeTrue();
198+
}
199+
200+
[Test]
201+
public void GetItems_should_ignore_torrents_with_empty_path()
202+
{
203+
var torrents = new List<RQBitTorrent>
204+
{
205+
new RQBitTorrent { Name = "Test1", Hash = "Hash1", Path = "" },
206+
new RQBitTorrent { Name = "Test2", Hash = "Hash2", Path = "/valid/path" }
207+
};
208+
209+
GivenTorrents(torrents);
210+
211+
var items = Subject.GetItems();
212+
213+
items.Should().HaveCount(1);
214+
items.First().Title.Should().Be("Test2");
215+
}
216+
217+
[Test]
218+
public void GetItems_should_ignore_torrents_with_relative_path()
219+
{
220+
var torrents = new List<RQBitTorrent>
221+
{
222+
new RQBitTorrent { Name = "Test1", Hash = "Hash1", Path = "./relative/path" },
223+
new RQBitTorrent { Name = "Test2", Hash = "Hash2", Path = "/absolute/path" }
224+
};
225+
226+
GivenTorrents(torrents);
227+
228+
var items = Subject.GetItems();
229+
230+
items.Should().HaveCount(1);
231+
items.First().Title.Should().Be("Test2");
232+
}
233+
}
234+
}

0 commit comments

Comments
 (0)