Moved trakt search term tests to non-integration test. Added several more testcases for the camelCase conversion and adjusted the underlying logic accordingly.

pull/3113/head
Taloth Saldono 10 years ago
parent 6dc72713be
commit 7816499b52

@ -16,8 +16,6 @@ namespace NzbDrone.Core.Test.MetadataSourceTests
[IntegrationTest]
public class TraktProxyFixture : CoreTest<TraktProxy>
{
[SetUp]
public void Setup()
{
@ -31,20 +29,7 @@ namespace NzbDrone.Core.Test.MetadataSourceTests
[TestCase("Rob & Big", "Rob and Big")]
[TestCase("M*A*S*H", "M*A*S*H")]
[TestCase("imdb:tt0436992", "Doctor Who (2005)")]
[TestCase("imdb:0436992", "Doctor Who (2005)")]
[TestCase("IMDB:0436992", "Doctor Who (2005)")]
[TestCase("IMDB: 0436992 ", "Doctor Who (2005)")]
[TestCase("tvdb:78804", "Doctor Who (2005)")]
[TestCase("TVDB:78804", "Doctor Who (2005)")]
[TestCase("TVDB: 78804 ", "Doctor Who (2005)")]
[TestCase("TheBigBangTheory", "The Big Bang Theory")]
[TestCase("Agents of S.H.I.E.L.D.", "Marvel's Agents of S.H.I.E.L.D.")]
[TestCase("Marvel's Agents of S.H.I.E.L.D.", "Marvel's Agents of S.H.I.E.L.D.")]
[TestCase("Marvel'sAgentsOfS.H.I.E.L.D.", "Marvel's Agents of S.H.I.E.L.D.")]
[TestCase("Utopia (US) (2014)", "Utopia (US) (2014)")]
[TestCase("Utopia US 2014", "Utopia (US) (2014)")]
[TestCase("UtopiaUS2014", "Utopia (US) (2014)")]
[TestCase("@Midnight", "@midnight")]
public void successful_search(string title, string expected)
{
var result = Subject.SearchForNewSeries(title);
@ -61,15 +46,17 @@ namespace NzbDrone.Core.Test.MetadataSourceTests
result.Should().BeEmpty();
}
[TestCase(75978)]
[TestCase(83462)]
[TestCase(266189)]
public void should_be_able_to_get_series_detail(int tvdbId)
[TestCase(75978, "Family Guy")]
[TestCase(83462, "Castle (2009)")]
[TestCase(266189, "The Blacklist")]
public void should_be_able_to_get_series_detail(Int32 tvdbId, String title)
{
var details = Subject.GetSeriesInfo(tvdbId);
ValidateSeries(details.Item1);
ValidateEpisodes(details.Item2);
details.Item1.Title.Should().Be(title);
}
[Test]

@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common.Http;
using NzbDrone.Core.MetadataSource;
using NzbDrone.Core.MetadataSource.Trakt;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
using NzbDrone.Test.Common;
using NzbDrone.Test.Common.Categories;
namespace NzbDrone.Core.Test.MetadataSourceTests
{
[TestFixture]
public class TraktProxyQueryFixture : CoreTest<TraktProxy>
{
[TestCase("tvdb:78804", "/78804/")]
[TestCase("TVDB:78804", "/78804/")]
[TestCase("TVDB: 78804 ", "/78804/")]
public void search_by_lookup(string title, string expectedPartialQuery)
{
Assert.Throws<TraktException>(() => Subject.SearchForNewSeries(title));
Mocker.GetMock<IHttpClient>()
.Verify(v => v.Get<Show>(It.Is<HttpRequest>(d => d.Url.ToString().Contains(expectedPartialQuery))), Times.Once());
ExceptionVerification.ExpectedWarns(1);
}
[TestCase("imdb:tt0436992", "tt0436992")]
[TestCase("imdb:0436992", "tt0436992")]
[TestCase("IMDB:0436992", "tt0436992")]
[TestCase("IMDB: 0436992 ", "tt0436992")]
[TestCase("The BigBangTheory", "the+bigbangtheory")]
[TestCase("TheBigBangTheory", "the+big+bang+theory")]
[TestCase(" TheBigBangTheory", "the+big+bang+theory")]
[TestCase("Agents of S.H.I.E.L.D.", "agents+of+s.h.i.e.l.d.")]
[TestCase("Marvel's Agents of S.H.I.E.L.D.", "marvels+agents+of+s.h.i.e.l.d.")]
[TestCase("Marvel'sAgentsOfS.H.I.E.L.D.", "marvels+agents+of+s.h.i.e.l.d.")]
[TestCase("Utopia (US) (2014)", "utopia+us+2014")]
[TestCase("Utopia US 2014", "utopia+us+2014")]
[TestCase("UtopiaUS2014", "utopia+us+2014")]
[TestCase("@Midnight", "midnight")]
[TestCase("The4400", "the+4400")]
[TestCase("StargateSG-1", "stargate+sg-1")]
[TestCase("Warehouse13", "warehouse+13")]
[TestCase("Ben10AlienForce", "ben+10+alien+force")]
[TestCase("FridayThe13thTheSeries","friday+the+13th+the+series")]
[TestCase("W1A", "w1a")]
[TestCase("O2Be", "o2be")]
[TestCase("TeenMom2", "teen+mom+2")]
[TestCase("123-456-789", "123-456-789")]
[TestCase("BuckRodgersInThe25thCentury", "buck+rodgers+in+the+25th+century")]
[TestCase("EPDaily", "ep+daily")]
[TestCase("6ad072c8-d000-4ed5-97d5-324858c45774", "6ad072c8-d000-4ed5-97d5-324858c45774")]
[TestCase("6AD072C8-D000-4ED5-97D5-324858C45774", "6ad072c8-d000-4ed5-97d5-324858c45774")]
public void search_by_query(string title, string expectedPartialQuery)
{
expectedPartialQuery = String.Format("query={0}&", expectedPartialQuery);
Assert.Throws<TraktException>(() => Subject.SearchForNewSeries(title));
Mocker.GetMock<IHttpClient>()
.Verify(v => v.Get<List<Show>>(It.Is<HttpRequest>(d => d.Url.ToString().Contains(expectedPartialQuery))), Times.Once());
ExceptionVerification.ExpectedWarns(1);
}
}
}

@ -225,6 +225,7 @@
<Compile Include="Metadata\Consumers\Roksbox\FindMetadataFileFixture.cs" />
<Compile Include="Metadata\Consumers\Wdtv\FindMetadataFileFixture.cs" />
<Compile Include="MetadataSourceTests\TraktProxyFixture.cs" />
<Compile Include="MetadataSourceTests\TraktProxyQueryFixture.cs" />
<Compile Include="MetadataSourceTests\TvdbProxyFixture.cs" />
<Compile Include="NotificationTests\PlexProviderTest.cs" />
<Compile Include="NotificationTests\ProwlProviderTest.cs" />

@ -19,8 +19,8 @@ namespace NzbDrone.Core.MetadataSource
private readonly IHttpClient _httpClient;
private static readonly Regex CollapseSpaceRegex = new Regex(@"\s+", RegexOptions.Compiled);
private static readonly Regex InvalidSearchCharRegex = new Regex(@"(?:\*|\(|\)|'|!|@|\+)", RegexOptions.Compiled);
private static readonly Regex ExpandCamelCaseRegEx = new Regex(@"(?<!^|[A-Z]\.?|[^\w.])(?=[A-Z])", RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);
private static readonly Regex ExpandCamelCaseRegEx = new Regex(@"(?<!^|[A-Z]\.?|[^\w.])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|(?<!^|\d\.?|[^\w.])(?=\d)", RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);
private readonly HttpRequestBuilder _requestBuilder;
public TraktProxy(Logger logger, IHttpClient httpClient)
@ -230,12 +230,18 @@ namespace NzbDrone.Core.MetadataSource
}
private static string GetSearchTerm(string phrase)
{
{
phrase = phrase.RemoveAccent();
phrase = InvalidSearchCharRegex.Replace(phrase, "");
phrase = ExpandCamelCaseRegEx.Replace(phrase, " ");
if (!phrase.Any(char.IsWhiteSpace) && phrase.Any(char.IsUpper) && phrase.Any(char.IsLower) && phrase.Length > 4)
{
phrase = ExpandCamelCaseRegEx.Replace(phrase, " ");
}
phrase = CollapseSpaceRegex.Replace(phrase, " ").Trim();
phrase = phrase.Trim('-');
phrase = System.Web.HttpUtility.UrlEncode(phrase.ToLower());
return phrase;

Loading…
Cancel
Save