mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-23 22:25:09 -04:00
New: Add Headphones VIP Indexer (#147)
* New: Add Headphones VIP Indexer * fixup! String Format Invalid * fixup! Remove hyphen from search string * Add Tests for Headphones Indexer
This commit is contained in:
+98
@@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using System.Xml;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.Indexers.Headphones;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.IndexerTests.HeadphonesTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class HeadphonesCapabilitiesProviderFixture : CoreTest<HeadphonesCapabilitiesProvider>
|
||||
{
|
||||
private HeadphonesSettings _settings;
|
||||
private string _caps;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_settings = new HeadphonesSettings();
|
||||
|
||||
_caps = ReadAllText("Files/Indexers/Newznab/newznab_caps.xml");
|
||||
}
|
||||
|
||||
private void GivenCapsResponse(string caps)
|
||||
{
|
||||
Mocker.GetMock<IHttpClient>()
|
||||
.Setup(o => o.Get(It.IsAny<HttpRequest>()))
|
||||
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), caps));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_request_same_caps_twice()
|
||||
{
|
||||
GivenCapsResponse(_caps);
|
||||
|
||||
Subject.GetCapabilities(_settings);
|
||||
Subject.GetCapabilities(_settings);
|
||||
|
||||
Mocker.GetMock<IHttpClient>()
|
||||
.Verify(o => o.Get(It.IsAny<HttpRequest>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_report_pagesize()
|
||||
{
|
||||
GivenCapsResponse(_caps);
|
||||
|
||||
var caps = Subject.GetCapabilities(_settings);
|
||||
|
||||
caps.DefaultPageSize.Should().Be(25);
|
||||
caps.MaxPageSize.Should().Be(60);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_use_default_pagesize_if_missing()
|
||||
{
|
||||
GivenCapsResponse(_caps.Replace("<limits", "<abclimits"));
|
||||
|
||||
var caps = Subject.GetCapabilities(_settings);
|
||||
|
||||
caps.DefaultPageSize.Should().Be(100);
|
||||
caps.MaxPageSize.Should().Be(100);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_throw_if_failed_to_get()
|
||||
{
|
||||
Mocker.GetMock<IHttpClient>()
|
||||
.Setup(o => o.Get(It.IsAny<HttpRequest>()))
|
||||
.Throws<Exception>();
|
||||
|
||||
Assert.Throws<Exception>(() => Subject.GetCapabilities(_settings));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_throw_if_xml_invalid()
|
||||
{
|
||||
GivenCapsResponse(_caps.Replace("<limits", "<>"));
|
||||
|
||||
Assert.Throws<XmlException>(() => Subject.GetCapabilities(_settings));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_throw_on_xml_data_unexpected()
|
||||
{
|
||||
GivenCapsResponse(_caps.Replace("3040", "asdf"));
|
||||
|
||||
var result = Subject.GetCapabilities(_settings);
|
||||
|
||||
result.Should().NotBeNull();
|
||||
|
||||
ExceptionVerification.ExpectedErrors(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.Indexers;
|
||||
using NzbDrone.Core.Indexers.Headphones;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.IndexerTests.HeadphonesTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class HeadphonesFixture : CoreTest<Headphones>
|
||||
{
|
||||
private HeadphonesCapabilities _caps;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
Subject.Definition = new IndexerDefinition()
|
||||
{
|
||||
Name = "Headphones VIP",
|
||||
Settings = new HeadphonesSettings()
|
||||
{
|
||||
Categories = new int[] { 3000 }
|
||||
}
|
||||
};
|
||||
|
||||
_caps = new HeadphonesCapabilities();
|
||||
Mocker.GetMock<IHeadphonesCapabilitiesProvider>()
|
||||
.Setup(v => v.GetCapabilities(It.IsAny<HeadphonesSettings>()))
|
||||
.Returns(_caps);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_parse_recent_feed_from_headphones()
|
||||
{
|
||||
var recentFeed = ReadAllText(@"Files/Indexers/Headphones/Headphones.xml");
|
||||
|
||||
Mocker.GetMock<IHttpClient>()
|
||||
.Setup(o => o.Execute(It.Is<HttpRequest>(v => v.Method == HttpMethod.GET)))
|
||||
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), recentFeed));
|
||||
|
||||
var releases = Subject.FetchRecent();
|
||||
|
||||
releases.Should().HaveCount(16);
|
||||
|
||||
releases.First().Should().BeOfType<ReleaseInfo>();
|
||||
var releaseInfo = releases.First() as ReleaseInfo;
|
||||
|
||||
releaseInfo.Title.Should().Be("Lady Gaga Born This Way 2CD FLAC 2011 WRE");
|
||||
releaseInfo.DownloadProtocol.Should().Be(DownloadProtocol.Usenet);
|
||||
releaseInfo.DownloadUrl.Should().Be("https://indexer.codeshy.com/api?t=g&guid=123456&apikey=123456789");
|
||||
releaseInfo.Indexer.Should().Be(Subject.Definition.Name);
|
||||
releaseInfo.PublishDate.Should().Be(DateTime.Parse("2013/06/02 08:58:54"));
|
||||
releaseInfo.Size.Should().Be(917347414);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_use_pagesize_reported_by_caps()
|
||||
{
|
||||
_caps.MaxPageSize = 30;
|
||||
_caps.DefaultPageSize = 25;
|
||||
|
||||
Subject.PageSize.Should().Be(25);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user