New: Use Goodreads directly, allow multiple editions of a book (new DB required)

This commit is contained in:
ta264
2020-06-30 21:46:01 +01:00
parent d83d2548e5
commit 45d49117ca
178 changed files with 3332 additions and 1786 deletions
@@ -0,0 +1,114 @@
using System;
using System.Collections.Generic;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Books;
using NzbDrone.Core.Exceptions;
using NzbDrone.Core.MetadataSource.Goodreads;
using NzbDrone.Core.Profiles.Metadata;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.MetadataSource.Goodreads
{
[TestFixture]
public class GoodreadsProxyFixture : CoreTest<GoodreadsProxy>
{
private MetadataProfile _metadataProfile;
[SetUp]
public void Setup()
{
UseRealHttp();
_metadataProfile = new MetadataProfile();
Mocker.GetMock<IMetadataProfileService>()
.Setup(s => s.Get(It.IsAny<int>()))
.Returns(_metadataProfile);
Mocker.GetMock<IMetadataProfileService>()
.Setup(s => s.Exists(It.IsAny<int>()))
.Returns(true);
}
[TestCase("1654", "Terry Pratchett")]
[TestCase("575", "Robert Harris")]
public void should_be_able_to_get_author_detail(string mbId, string name)
{
var details = Subject.GetAuthorInfo(mbId);
ValidateAuthor(details);
details.Name.Should().Be(name);
}
[TestCase("64216", "Guards! Guards!")]
public void should_be_able_to_get_book_detail(string mbId, string name)
{
var details = Subject.GetBookInfo(mbId);
ValidateAlbums(new List<Book> { details.Item2 });
details.Item2.Title.Should().Be(name);
}
[Test]
public void getting_details_of_invalid_artist()
{
Assert.Throws<AuthorNotFoundException>(() => Subject.GetAuthorInfo("66c66aaa-6e2f-4930-8610-912e24c63ed1"));
}
[Test]
public void getting_details_of_invalid_album()
{
Assert.Throws<BookNotFoundException>(() => Subject.GetBookInfo("66c66aaa-6e2f-4930-8610-912e24c63ed1"));
}
private void ValidateAuthor(Author author)
{
author.Should().NotBeNull();
author.Name.Should().NotBeNullOrWhiteSpace();
author.CleanName.Should().Be(Parser.Parser.CleanAuthorName(author.Name));
author.SortName.Should().Be(Parser.Parser.NormalizeTitle(author.Name));
author.Metadata.Value.TitleSlug.Should().NotBeNullOrWhiteSpace();
author.Metadata.Value.Overview.Should().NotBeNullOrWhiteSpace();
author.Metadata.Value.Images.Should().NotBeEmpty();
author.ForeignAuthorId.Should().NotBeNullOrWhiteSpace();
}
private void ValidateAlbums(List<Book> albums, bool idOnly = false)
{
albums.Should().NotBeEmpty();
foreach (var album in albums)
{
album.ForeignBookId.Should().NotBeNullOrWhiteSpace();
if (!idOnly)
{
ValidateAlbum(album);
}
}
//if atleast one album has title it means parse it working.
if (!idOnly)
{
albums.Should().Contain(c => !string.IsNullOrWhiteSpace(c.Title));
}
}
private void ValidateAlbum(Book album)
{
album.Should().NotBeNull();
album.Title.Should().NotBeNullOrWhiteSpace();
album.Should().NotBeNull();
if (album.ReleaseDate.HasValue)
{
album.ReleaseDate.Value.Kind.Should().Be(DateTimeKind.Utc);
}
}
}
}
@@ -0,0 +1,101 @@
using System;
using System.Collections.Generic;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Books;
using NzbDrone.Core.MetadataSource.Goodreads;
using NzbDrone.Core.Profiles.Metadata;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.MetadataSource.Goodreads
{
[TestFixture]
public class GoodreadsProxySearchFixture : CoreTest<GoodreadsProxy>
{
[SetUp]
public void Setup()
{
UseRealHttp();
var metadataProfile = new MetadataProfile();
Mocker.GetMock<IMetadataProfileService>()
.Setup(s => s.All())
.Returns(new List<MetadataProfile> { metadataProfile });
Mocker.GetMock<IMetadataProfileService>()
.Setup(s => s.Get(It.IsAny<int>()))
.Returns(metadataProfile);
}
[TestCase("Robert Harris", "Robert Harris")]
[TestCase("Terry Pratchett", "Terry Pratchett")]
[TestCase("Charlotte Brontë", "Charlotte Brontë")]
public void successful_artist_search(string title, string expected)
{
var result = Subject.SearchForNewAuthor(title);
result.Should().NotBeEmpty();
result[0].Name.Should().Be(expected);
ExceptionVerification.IgnoreWarns();
}
[TestCase("Harry Potter and the sorcerer's stone", null, "Harry Potter and the Sorcerer's Stone")]
[TestCase("readarr:3", null, "Harry Potter and the Philosopher's Stone")]
[TestCase("readarr: 3", null, "Harry Potter and the Philosopher's Stone")]
[TestCase("readarrid:3", null, "Harry Potter and the Philosopher's Stone")]
[TestCase("goodreads:3", null, "Harry Potter and the Philosopher's Stone")]
[TestCase("asin:B0192CTMYG", null, "Harry Potter and the Sorcerer's Stone")]
[TestCase("isbn:9780439554930", null, "Harry Potter and the Sorcerer's Stone")]
public void successful_album_search(string title, string artist, string expected)
{
var result = Subject.SearchForNewBook(title, artist);
result.Should().NotBeEmpty();
result[0].Title.Should().Be(expected);
ExceptionVerification.IgnoreWarns();
}
[TestCase("readarrid:")]
[TestCase("readarrid: 99999999999999999999")]
[TestCase("readarrid: 0")]
[TestCase("readarrid: -12")]
[TestCase("readarrid: aaaa")]
[TestCase("adjalkwdjkalwdjklawjdlKAJD")]
public void no_artist_search_result(string term)
{
var result = Subject.SearchForNewAuthor(term);
result.Should().BeEmpty();
ExceptionVerification.IgnoreWarns();
}
[TestCase("Robert Harris", 0, typeof(Author), "Robert Harris")]
[TestCase("Robert Harris", 1, typeof(Book), "Fatherland")]
public void successful_combined_search(string query, int position, Type resultType, string expected)
{
var result = Subject.SearchForNewEntity(query);
result.Should().NotBeEmpty();
result[position].GetType().Should().Be(resultType);
if (resultType == typeof(Author))
{
var cast = result[position] as Author;
cast.Should().NotBeNull();
cast.Name.Should().Be(expected);
}
else
{
var cast = result[position] as Book;
cast.Should().NotBeNull();
cast.Title.Should().Be(expected);
}
}
}
}