2020-05-26 01:55:10 +00:00
|
|
|
using System.Collections.Generic;
|
2020-06-20 19:55:31 +00:00
|
|
|
using System.Linq;
|
2014-09-07 11:44:24 +00:00
|
|
|
using FluentAssertions;
|
2015-09-26 08:45:13 +00:00
|
|
|
using Moq;
|
2014-09-07 11:44:24 +00:00
|
|
|
using NUnit.Framework;
|
|
|
|
using NzbDrone.Core.Indexers.Newznab;
|
|
|
|
using NzbDrone.Core.IndexerSearch.Definitions;
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.IndexerTests.NewznabTests
|
|
|
|
{
|
|
|
|
public class NewznabRequestGeneratorFixture : CoreTest<NewznabRequestGenerator>
|
|
|
|
{
|
2017-03-06 21:23:25 +00:00
|
|
|
private MovieSearchCriteria _movieSearchCriteria;
|
2015-09-26 08:45:13 +00:00
|
|
|
private NewznabCapabilities _capabilities;
|
2014-09-07 11:44:24 +00:00
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void SetUp()
|
|
|
|
{
|
|
|
|
Subject.Settings = new NewznabSettings()
|
|
|
|
{
|
2019-12-22 22:08:53 +00:00
|
|
|
BaseUrl = "http://127.0.0.1:1234/",
|
|
|
|
Categories = new[] { 1, 2 },
|
|
|
|
ApiKey = "abcd",
|
2014-09-07 11:44:24 +00:00
|
|
|
};
|
|
|
|
|
2017-03-06 21:23:25 +00:00
|
|
|
_movieSearchCriteria = new MovieSearchCriteria
|
2015-09-26 08:45:13 +00:00
|
|
|
{
|
2020-05-26 01:55:10 +00:00
|
|
|
Movie = new Movies.Movie { ImdbId = "tt0076759", Title = "Star Wars", Year = 1977, TmdbId = 11 },
|
|
|
|
SceneTitles = new List<string> { "Star Wars" }
|
2014-09-07 11:44:24 +00:00
|
|
|
};
|
2015-09-26 08:45:13 +00:00
|
|
|
|
|
|
|
_capabilities = new NewznabCapabilities();
|
|
|
|
|
|
|
|
Mocker.GetMock<INewznabCapabilitiesProvider>()
|
|
|
|
.Setup(v => v.GetCapabilities(It.IsAny<NewznabSettings>()))
|
|
|
|
.Returns(_capabilities);
|
2014-09-07 11:44:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_use_all_categories_for_feed()
|
|
|
|
{
|
|
|
|
var results = Subject.GetRecentRequests();
|
|
|
|
|
2015-10-09 18:56:40 +00:00
|
|
|
results.GetAllTiers().Should().HaveCount(1);
|
2014-09-07 11:44:24 +00:00
|
|
|
|
2015-10-09 18:56:40 +00:00
|
|
|
var page = results.GetAllTiers().First().First();
|
2014-09-07 11:44:24 +00:00
|
|
|
|
2020-06-20 19:55:31 +00:00
|
|
|
page.Url.Query.Should().Contain("&cat=1,2&");
|
2014-09-07 11:44:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_not_have_duplicate_categories()
|
|
|
|
{
|
2020-06-20 19:55:31 +00:00
|
|
|
Subject.Settings.Categories = new[] { 1, 2, 2, 3 };
|
2014-09-07 11:44:24 +00:00
|
|
|
|
|
|
|
var results = Subject.GetRecentRequests();
|
|
|
|
|
2015-10-09 18:56:40 +00:00
|
|
|
results.GetAllTiers().Should().HaveCount(1);
|
2014-09-07 11:44:24 +00:00
|
|
|
|
2015-10-09 18:56:40 +00:00
|
|
|
var page = results.GetAllTiers().First().First();
|
2014-09-07 11:44:24 +00:00
|
|
|
|
2020-06-20 19:55:31 +00:00
|
|
|
page.Url.FullUri.Should().Contain("&cat=1,2,3&");
|
2014-09-07 11:44:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_return_subsequent_pages()
|
|
|
|
{
|
2017-03-06 21:23:25 +00:00
|
|
|
var results = Subject.GetSearchRequests(_movieSearchCriteria);
|
2014-09-07 11:44:24 +00:00
|
|
|
|
2020-05-26 01:55:10 +00:00
|
|
|
results.GetAllTiers().Should().HaveCount(2);
|
2014-09-07 11:44:24 +00:00
|
|
|
|
2015-10-09 18:56:40 +00:00
|
|
|
var pages = results.GetAllTiers().First().Take(3).ToList();
|
2014-09-07 11:44:24 +00:00
|
|
|
|
2016-02-29 23:33:28 +00:00
|
|
|
pages[0].Url.FullUri.Should().Contain("&offset=0&");
|
|
|
|
pages[1].Url.FullUri.Should().Contain("&offset=100&");
|
|
|
|
pages[2].Url.FullUri.Should().Contain("&offset=200&");
|
2014-09-07 11:44:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_not_get_unlimited_pages()
|
|
|
|
{
|
2017-03-06 21:23:25 +00:00
|
|
|
var results = Subject.GetSearchRequests(_movieSearchCriteria);
|
2014-09-07 11:44:24 +00:00
|
|
|
|
2020-05-26 01:55:10 +00:00
|
|
|
results.GetAllTiers().Should().HaveCount(2);
|
2014-09-07 11:44:24 +00:00
|
|
|
|
2015-10-09 18:56:40 +00:00
|
|
|
var pages = results.GetAllTiers().First().Take(500).ToList();
|
2014-09-07 11:44:24 +00:00
|
|
|
|
|
|
|
pages.Count.Should().BeLessThan(500);
|
|
|
|
}
|
2015-09-26 08:45:13 +00:00
|
|
|
|
|
|
|
[Test]
|
2017-03-06 21:23:25 +00:00
|
|
|
public void should_not_search_by_imdbid_if_not_supported()
|
2015-09-26 08:45:13 +00:00
|
|
|
{
|
2017-03-06 21:23:25 +00:00
|
|
|
_capabilities.SupportedMovieSearchParameters = new[] { "q" };
|
2015-09-26 08:45:13 +00:00
|
|
|
|
2017-03-06 21:23:25 +00:00
|
|
|
var results = Subject.GetSearchRequests(_movieSearchCriteria);
|
2015-09-26 08:45:13 +00:00
|
|
|
|
2015-10-09 18:56:40 +00:00
|
|
|
results.GetAllTiers().Should().HaveCount(1);
|
2015-09-26 08:45:13 +00:00
|
|
|
|
2015-10-09 18:56:40 +00:00
|
|
|
var page = results.GetAllTiers().First().First();
|
2015-09-26 08:45:13 +00:00
|
|
|
|
2017-03-06 21:23:25 +00:00
|
|
|
page.Url.Query.Should().NotContain("imdbid=0076759");
|
2020-05-26 01:55:10 +00:00
|
|
|
page.Url.Query.Should().Contain("q=Star");
|
2015-09-26 08:45:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2017-03-06 21:23:25 +00:00
|
|
|
public void should_search_by_imdbid_if_supported()
|
2015-09-26 08:45:13 +00:00
|
|
|
{
|
2019-12-22 21:24:10 +00:00
|
|
|
_capabilities.SupportedMovieSearchParameters = new[] { "q", "imdbid" };
|
2015-09-26 08:45:13 +00:00
|
|
|
|
2017-03-06 21:23:25 +00:00
|
|
|
var results = Subject.GetSearchRequests(_movieSearchCriteria);
|
2015-10-09 18:56:40 +00:00
|
|
|
results.GetTier(0).Should().HaveCount(1);
|
2015-09-26 08:45:13 +00:00
|
|
|
|
2015-10-09 18:56:40 +00:00
|
|
|
var page = results.GetAllTiers().First().First();
|
2015-09-26 08:45:13 +00:00
|
|
|
|
2017-03-06 21:23:25 +00:00
|
|
|
page.Url.Query.Should().Contain("imdbid=0076759");
|
2015-09-26 08:45:13 +00:00
|
|
|
}
|
2020-05-26 01:55:10 +00:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_search_by_tmdbid_if_supported()
|
|
|
|
{
|
|
|
|
_capabilities.SupportedMovieSearchParameters = new[] { "q", "tmdbid" };
|
|
|
|
|
|
|
|
var results = Subject.GetSearchRequests(_movieSearchCriteria);
|
|
|
|
results.GetTier(0).Should().HaveCount(1);
|
|
|
|
|
|
|
|
var page = results.GetAllTiers().First().First();
|
|
|
|
|
|
|
|
page.Url.Query.Should().Contain("tmdbid=11");
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_prefer_search_by_tmdbid_if_rid_supported()
|
|
|
|
{
|
|
|
|
_capabilities.SupportedMovieSearchParameters = new[] { "q", "tmdbid", "imdbid" };
|
|
|
|
|
|
|
|
var results = Subject.GetSearchRequests(_movieSearchCriteria);
|
|
|
|
results.GetTier(0).Should().HaveCount(1);
|
|
|
|
|
|
|
|
var page = results.GetAllTiers().First().First();
|
|
|
|
|
|
|
|
page.Url.Query.Should().Contain("tmdbid=11");
|
|
|
|
page.Url.Query.Should().NotContain("imdbid=0076759");
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_use_aggregrated_id_search_if_supported()
|
|
|
|
{
|
|
|
|
_capabilities.SupportedMovieSearchParameters = new[] { "q", "tmdbid", "imdbid" };
|
|
|
|
_capabilities.SupportsAggregateIdSearch = true;
|
|
|
|
|
|
|
|
var results = Subject.GetSearchRequests(_movieSearchCriteria);
|
|
|
|
results.GetTier(0).Should().HaveCount(1);
|
|
|
|
|
|
|
|
var page = results.GetTier(0).First().First();
|
|
|
|
|
|
|
|
page.Url.Query.Should().Contain("tmdbid=11");
|
|
|
|
page.Url.Query.Should().Contain("imdbid=0076759");
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_not_use_aggregrated_id_search_if_no_ids_supported()
|
|
|
|
{
|
|
|
|
_capabilities.SupportedMovieSearchParameters = new[] { "q" };
|
|
|
|
_capabilities.SupportsAggregateIdSearch = true; // Turns true if indexer supplies supportedParams.
|
|
|
|
|
|
|
|
var results = Subject.GetSearchRequests(_movieSearchCriteria);
|
|
|
|
results.Tiers.Should().Be(1);
|
|
|
|
results.GetTier(0).Should().HaveCount(1);
|
|
|
|
|
|
|
|
var page = results.GetTier(0).First().First();
|
|
|
|
|
|
|
|
page.Url.Query.Should().Contain("q=");
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_not_use_aggregrated_id_search_if_no_ids_are_known()
|
|
|
|
{
|
|
|
|
_capabilities.SupportedMovieSearchParameters = new[] { "q", "imdbid" };
|
|
|
|
_capabilities.SupportsAggregateIdSearch = true; // Turns true if indexer supplies supportedParams.
|
|
|
|
|
|
|
|
_movieSearchCriteria.Movie.ImdbId = null;
|
|
|
|
|
|
|
|
var results = Subject.GetSearchRequests(_movieSearchCriteria);
|
|
|
|
|
|
|
|
var page = results.GetTier(0).First().First();
|
|
|
|
|
|
|
|
page.Url.Query.Should().Contain("q=");
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_fallback_to_q()
|
|
|
|
{
|
|
|
|
_capabilities.SupportedMovieSearchParameters = new[] { "q", "tmdbid", "imdbid" };
|
|
|
|
_capabilities.SupportsAggregateIdSearch = true;
|
|
|
|
|
|
|
|
var results = Subject.GetSearchRequests(_movieSearchCriteria);
|
|
|
|
results.Tiers.Should().Be(2);
|
|
|
|
|
|
|
|
var pageTier2 = results.GetTier(1).First().First();
|
|
|
|
|
|
|
|
pageTier2.Url.Query.Should().NotContain("tmdbid=11");
|
|
|
|
pageTier2.Url.Query.Should().NotContain("imdbid=0076759");
|
|
|
|
pageTier2.Url.Query.Should().Contain("q=");
|
|
|
|
}
|
2014-09-07 11:44:24 +00:00
|
|
|
}
|
|
|
|
}
|