mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-20 21:54:25 -04:00
New: Readarr 0.1
This commit is contained in:
@@ -20,14 +20,14 @@ namespace NzbDrone.Core.Test.MetadataSource
|
||||
|
||||
Mocker.GetMock<IReadarrCloudRequestBuilder>()
|
||||
.Setup(s => s.Search)
|
||||
.Returns(new HttpRequestBuilder("https://api.readarr.audio/api/v0.4/{route}").CreateFactory());
|
||||
.Returns(new HttpRequestBuilder("https://api.readarr.com/api/v0.4/{route}").CreateFactory());
|
||||
}
|
||||
|
||||
private void WithCustomProvider()
|
||||
{
|
||||
Mocker.GetMock<IConfigService>()
|
||||
.Setup(s => s.MetadataSource)
|
||||
.Returns("http://api.readarr.audio/api/testing/");
|
||||
.Returns("http://api.readarr.com/api/testing/");
|
||||
}
|
||||
|
||||
[TestCase]
|
||||
|
||||
@@ -11,17 +11,17 @@ namespace NzbDrone.Core.Test.MetadataSource
|
||||
[TestFixture]
|
||||
public class SearchArtistComparerFixture : CoreTest
|
||||
{
|
||||
private List<Artist> _artist;
|
||||
private List<Author> _artist;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_artist = new List<Artist>();
|
||||
_artist = new List<Author>();
|
||||
}
|
||||
|
||||
private void WithSeries(string name)
|
||||
{
|
||||
_artist.Add(new Artist { Name = name });
|
||||
_artist.Add(new Author { Name = name });
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Exceptions;
|
||||
using NzbDrone.Core.MetadataSource.SkyHook;
|
||||
using NzbDrone.Core.MetadataSource.SkyHook.Resource;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Profiles.Metadata;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
@@ -23,33 +21,7 @@ namespace NzbDrone.Core.Test.MetadataSource.SkyHook
|
||||
{
|
||||
UseRealHttp();
|
||||
|
||||
_metadataProfile = new MetadataProfile
|
||||
{
|
||||
PrimaryAlbumTypes = new List<ProfilePrimaryAlbumTypeItem>
|
||||
{
|
||||
new ProfilePrimaryAlbumTypeItem
|
||||
{
|
||||
PrimaryAlbumType = PrimaryAlbumType.Album,
|
||||
Allowed = true
|
||||
}
|
||||
},
|
||||
SecondaryAlbumTypes = new List<ProfileSecondaryAlbumTypeItem>
|
||||
{
|
||||
new ProfileSecondaryAlbumTypeItem()
|
||||
{
|
||||
SecondaryAlbumType = SecondaryAlbumType.Studio,
|
||||
Allowed = true
|
||||
}
|
||||
},
|
||||
ReleaseStatuses = new List<ProfileReleaseStatusItem>
|
||||
{
|
||||
new ProfileReleaseStatusItem
|
||||
{
|
||||
ReleaseStatus = ReleaseStatus.Official,
|
||||
Allowed = true
|
||||
}
|
||||
}
|
||||
};
|
||||
_metadataProfile = new MetadataProfile();
|
||||
|
||||
Mocker.GetMock<IMetadataProfileService>()
|
||||
.Setup(s => s.Get(It.IsAny<int>()))
|
||||
@@ -60,164 +32,61 @@ namespace NzbDrone.Core.Test.MetadataSource.SkyHook
|
||||
.Returns(true);
|
||||
}
|
||||
|
||||
public List<AlbumResource> GivenExampleAlbums()
|
||||
[TestCase("amzn1.gr.author.v1.qTrNu9-PIaaBj5gYRDmN4Q", "Terry Pratchett")]
|
||||
[TestCase("amzn1.gr.author.v1.afCyJgprpWE2xJU2_z3zTQ", "Robert Harris")]
|
||||
public void should_be_able_to_get_author_detail(string mbId, string name)
|
||||
{
|
||||
var result = new List<AlbumResource>();
|
||||
var details = Subject.GetAuthorInfo(mbId);
|
||||
|
||||
foreach (var primaryType in PrimaryAlbumType.All)
|
||||
{
|
||||
foreach (var secondaryType in SecondaryAlbumType.All)
|
||||
{
|
||||
var secondaryTypes = secondaryType.Name == "Studio" ? new List<string>() : new List<string> { secondaryType.Name };
|
||||
foreach (var releaseStatus in ReleaseStatus.All)
|
||||
{
|
||||
var releaseStatuses = new List<string> { releaseStatus.Name };
|
||||
result.Add(new AlbumResource
|
||||
{
|
||||
Type = primaryType.Name,
|
||||
SecondaryTypes = secondaryTypes,
|
||||
ReleaseStatuses = releaseStatuses
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[TestCase("f59c5520-5f46-4d2c-b2c4-822eabf53419", "Linkin Park")]
|
||||
[TestCase("66c662b6-6e2f-4930-8610-912e24c63ed1", "AC/DC")]
|
||||
public void should_be_able_to_get_artist_detail(string mbId, string name)
|
||||
{
|
||||
var details = Subject.GetArtistInfo(mbId, 1);
|
||||
|
||||
ValidateArtist(details);
|
||||
ValidateAlbums(details.Albums.Value, true);
|
||||
ValidateAuthor(details);
|
||||
|
||||
details.Name.Should().Be(name);
|
||||
}
|
||||
|
||||
[TestCaseSource(typeof(PrimaryAlbumType), "All")]
|
||||
public void should_filter_albums_by_primary_release_type(PrimaryAlbumType type)
|
||||
[TestCase("amzn1.gr.book.v1.2rp8a0vJ8clGzMzZf61R9Q", "Guards! Guards!")]
|
||||
public void should_be_able_to_get_book_detail(string mbId, string name)
|
||||
{
|
||||
_metadataProfile.PrimaryAlbumTypes = new List<ProfilePrimaryAlbumTypeItem>
|
||||
{
|
||||
new ProfilePrimaryAlbumTypeItem
|
||||
{
|
||||
PrimaryAlbumType = type,
|
||||
Allowed = true
|
||||
}
|
||||
};
|
||||
var details = Subject.GetBookInfo(mbId);
|
||||
|
||||
var albums = GivenExampleAlbums();
|
||||
Subject.FilterAlbums(albums, 1).Select(x => x.Type).Distinct()
|
||||
.Should().BeEquivalentTo(new List<string> { type.Name });
|
||||
}
|
||||
ValidateAlbums(new List<Book> { details.Item2 });
|
||||
|
||||
[TestCaseSource(typeof(SecondaryAlbumType), "All")]
|
||||
public void should_filter_albums_by_secondary_release_type(SecondaryAlbumType type)
|
||||
{
|
||||
_metadataProfile.SecondaryAlbumTypes = new List<ProfileSecondaryAlbumTypeItem>
|
||||
{
|
||||
new ProfileSecondaryAlbumTypeItem
|
||||
{
|
||||
SecondaryAlbumType = type,
|
||||
Allowed = true
|
||||
}
|
||||
};
|
||||
|
||||
var albums = GivenExampleAlbums();
|
||||
var filtered = Subject.FilterAlbums(albums, 1);
|
||||
TestLogger.Debug(filtered.Count());
|
||||
|
||||
filtered.SelectMany(x => x.SecondaryTypes.Select(SkyHookProxy.MapSecondaryTypes))
|
||||
.Select(x => x.Name)
|
||||
.Distinct()
|
||||
.Should().BeEquivalentTo(type.Name == "Studio" ? new List<string>() : new List<string> { type.Name });
|
||||
}
|
||||
|
||||
[TestCaseSource(typeof(ReleaseStatus), "All")]
|
||||
public void should_filter_albums_by_release_status(ReleaseStatus type)
|
||||
{
|
||||
_metadataProfile.ReleaseStatuses = new List<ProfileReleaseStatusItem>
|
||||
{
|
||||
new ProfileReleaseStatusItem
|
||||
{
|
||||
ReleaseStatus = type,
|
||||
Allowed = true
|
||||
}
|
||||
};
|
||||
|
||||
var albums = GivenExampleAlbums();
|
||||
Subject.FilterAlbums(albums, 1).SelectMany(x => x.ReleaseStatuses).Distinct()
|
||||
.Should().BeEquivalentTo(new List<string> { type.Name });
|
||||
}
|
||||
|
||||
[TestCase("12fa3845-7c62-36e5-a8da-8be137155a72", "Hysteria")]
|
||||
public void should_be_able_to_get_album_detail(string mbId, string name)
|
||||
{
|
||||
var details = Subject.GetAlbumInfo(mbId);
|
||||
|
||||
ValidateAlbums(new List<Album> { details.Item2 });
|
||||
|
||||
details.Item2.Title.Should().Be(name);
|
||||
}
|
||||
|
||||
[TestCase("12fa3845-7c62-36e5-a8da-8be137155a72", "3c186b52-ca73-46a3-a8e6-04559bfbb581", 1, 13, "Hysteria")]
|
||||
[TestCase("12fa3845-7c62-36e5-a8da-8be137155a72", "dee9ca6f-4f84-4359-82a9-b75a37ffc316", 2, 27, "Hysteria")]
|
||||
public void should_be_able_to_get_album_detail_with_release(string mbId, string release, int mediaCount, int trackCount, string name)
|
||||
{
|
||||
var details = Subject.GetAlbumInfo(mbId);
|
||||
|
||||
ValidateAlbums(new List<Album> { details.Item2 });
|
||||
|
||||
details.Item2.AlbumReleases.Value.Single(r => r.ForeignReleaseId == release).Media.Count.Should().Be(mediaCount);
|
||||
details.Item2.AlbumReleases.Value.Single(r => r.ForeignReleaseId == release).Tracks.Value.Count.Should().Be(trackCount);
|
||||
details.Item2.Title.Should().Be(name);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void getting_details_of_invalid_artist()
|
||||
{
|
||||
Assert.Throws<ArtistNotFoundException>(() => Subject.GetArtistInfo("66c66aaa-6e2f-4930-8610-912e24c63ed1", 1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void getting_details_of_invalid_guid_for_artist()
|
||||
{
|
||||
Assert.Throws<BadRequestException>(() => Subject.GetArtistInfo("66c66aaa-6e2f-4930-aaaaaa", 1));
|
||||
Assert.Throws<ArtistNotFoundException>(() => Subject.GetAuthorInfo("66c66aaa-6e2f-4930-8610-912e24c63ed1"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void getting_details_of_invalid_album()
|
||||
{
|
||||
Assert.Throws<AlbumNotFoundException>(() => Subject.GetAlbumInfo("66c66aaa-6e2f-4930-8610-912e24c63ed1"));
|
||||
Assert.Throws<AlbumNotFoundException>(() => Subject.GetBookInfo("66c66aaa-6e2f-4930-8610-912e24c63ed1"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void getting_details_of_invalid_guid_for_album()
|
||||
private void ValidateAuthor(Author author)
|
||||
{
|
||||
Assert.Throws<BadRequestException>(() => Subject.GetAlbumInfo("66c66aaa-6e2f-4930-aaaaaa"));
|
||||
author.Should().NotBeNull();
|
||||
author.Name.Should().NotBeNullOrWhiteSpace();
|
||||
author.CleanName.Should().Be(Parser.Parser.CleanArtistName(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();
|
||||
author.Books.IsLoaded.Should().BeTrue();
|
||||
author.Books.Value.Should().NotBeEmpty();
|
||||
author.Books.Value.Should().OnlyContain(x => x.CleanTitle != null);
|
||||
}
|
||||
|
||||
private void ValidateArtist(Artist artist)
|
||||
{
|
||||
artist.Should().NotBeNull();
|
||||
artist.Name.Should().NotBeNullOrWhiteSpace();
|
||||
artist.CleanName.Should().Be(Parser.Parser.CleanArtistName(artist.Name));
|
||||
artist.SortName.Should().Be(Parser.Parser.NormalizeTitle(artist.Name));
|
||||
artist.Metadata.Value.Overview.Should().NotBeNullOrWhiteSpace();
|
||||
artist.Metadata.Value.Images.Should().NotBeEmpty();
|
||||
artist.ForeignArtistId.Should().NotBeNullOrWhiteSpace();
|
||||
}
|
||||
|
||||
private void ValidateAlbums(List<Album> albums, bool idOnly = false)
|
||||
private void ValidateAlbums(List<Book> albums, bool idOnly = false)
|
||||
{
|
||||
albums.Should().NotBeEmpty();
|
||||
|
||||
foreach (var album in albums)
|
||||
{
|
||||
album.ForeignAlbumId.Should().NotBeNullOrWhiteSpace();
|
||||
album.ForeignBookId.Should().NotBeNullOrWhiteSpace();
|
||||
if (!idOnly)
|
||||
{
|
||||
ValidateAlbum(album);
|
||||
@@ -231,12 +100,11 @@ namespace NzbDrone.Core.Test.MetadataSource.SkyHook
|
||||
}
|
||||
}
|
||||
|
||||
private void ValidateAlbum(Album album)
|
||||
private void ValidateAlbum(Book album)
|
||||
{
|
||||
album.Should().NotBeNull();
|
||||
|
||||
album.Title.Should().NotBeNullOrWhiteSpace();
|
||||
album.AlbumType.Should().NotBeNullOrWhiteSpace();
|
||||
|
||||
album.Should().NotBeNull();
|
||||
|
||||
|
||||
@@ -19,34 +19,7 @@ namespace NzbDrone.Core.Test.MetadataSource.SkyHook
|
||||
{
|
||||
UseRealHttp();
|
||||
|
||||
var metadataProfile = new MetadataProfile
|
||||
{
|
||||
Id = 1,
|
||||
PrimaryAlbumTypes = new List<ProfilePrimaryAlbumTypeItem>
|
||||
{
|
||||
new ProfilePrimaryAlbumTypeItem
|
||||
{
|
||||
PrimaryAlbumType = PrimaryAlbumType.Album,
|
||||
Allowed = true
|
||||
}
|
||||
},
|
||||
SecondaryAlbumTypes = new List<ProfileSecondaryAlbumTypeItem>
|
||||
{
|
||||
new ProfileSecondaryAlbumTypeItem()
|
||||
{
|
||||
SecondaryAlbumType = SecondaryAlbumType.Studio,
|
||||
Allowed = true
|
||||
}
|
||||
},
|
||||
ReleaseStatuses = new List<ProfileReleaseStatusItem>
|
||||
{
|
||||
new ProfileReleaseStatusItem
|
||||
{
|
||||
ReleaseStatus = ReleaseStatus.Official,
|
||||
Allowed = true
|
||||
}
|
||||
}
|
||||
};
|
||||
var metadataProfile = new MetadataProfile();
|
||||
|
||||
Mocker.GetMock<IMetadataProfileService>()
|
||||
.Setup(s => s.All())
|
||||
@@ -57,16 +30,12 @@ namespace NzbDrone.Core.Test.MetadataSource.SkyHook
|
||||
.Returns(metadataProfile);
|
||||
}
|
||||
|
||||
[TestCase("Coldplay", "Coldplay")]
|
||||
[TestCase("Avenged Sevenfold", "Avenged Sevenfold")]
|
||||
[TestCase("3OH!3", "3OH!3")]
|
||||
[TestCase("The Academy Is...", "The Academy Is…")]
|
||||
[TestCase("readarr:f59c5520-5f46-4d2c-b2c4-822eabf53419", "Linkin Park")]
|
||||
[TestCase("readarrid:f59c5520-5f46-4d2c-b2c4-822eabf53419", "Linkin Park")]
|
||||
[TestCase("readarrid: f59c5520-5f46-4d2c-b2c4-822eabf53419 ", "Linkin Park")]
|
||||
[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.SearchForNewArtist(title);
|
||||
var result = Subject.SearchForNewAuthor(title);
|
||||
|
||||
result.Should().NotBeEmpty();
|
||||
|
||||
@@ -75,14 +44,16 @@ namespace NzbDrone.Core.Test.MetadataSource.SkyHook
|
||||
ExceptionVerification.IgnoreWarns();
|
||||
}
|
||||
|
||||
[TestCase("Evolve", "Imagine Dragons", "Evolve")]
|
||||
[TestCase("Hysteria", null, "Hysteria")]
|
||||
[TestCase("readarr:d77df681-b779-3d6d-b66a-3bfd15985e3e", null, "Pyromania")]
|
||||
[TestCase("readarr: d77df681-b779-3d6d-b66a-3bfd15985e3e", null, "Pyromania")]
|
||||
[TestCase("readarrid:d77df681-b779-3d6d-b66a-3bfd15985e3e", null, "Pyromania")]
|
||||
[TestCase("Harry Potter and the sorcerer's stone", null, "Harry Potter and the Sorcerer's Stone")]
|
||||
[TestCase("readarr:3", null, "Harry Potter and the Sorcerer's Stone")]
|
||||
[TestCase("readarr: 3", null, "Harry Potter and the Sorcerer's Stone")]
|
||||
[TestCase("readarrid:3", null, "Harry Potter and the Sorcerer's Stone")]
|
||||
[TestCase("goodreads:3", null, "Harry Potter and the Sorcerer'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.SearchForNewAlbum(title, artist);
|
||||
var result = Subject.SearchForNewBook(title, artist);
|
||||
|
||||
result.Should().NotBeEmpty();
|
||||
|
||||
@@ -95,34 +66,33 @@ namespace NzbDrone.Core.Test.MetadataSource.SkyHook
|
||||
[TestCase("readarrid: 99999999999999999999")]
|
||||
[TestCase("readarrid: 0")]
|
||||
[TestCase("readarrid: -12")]
|
||||
[TestCase("readarrid:289578")]
|
||||
[TestCase("readarrid: aaaa")]
|
||||
[TestCase("adjalkwdjkalwdjklawjdlKAJD")]
|
||||
public void no_artist_search_result(string term)
|
||||
{
|
||||
var result = Subject.SearchForNewArtist(term);
|
||||
var result = Subject.SearchForNewAuthor(term);
|
||||
result.Should().BeEmpty();
|
||||
|
||||
ExceptionVerification.IgnoreWarns();
|
||||
}
|
||||
|
||||
[TestCase("Eminem", 0, typeof(Artist), "Eminem")]
|
||||
[TestCase("Eminem Kamikaze", 0, typeof(Artist), "Eminem")]
|
||||
[TestCase("Eminem Kamikaze", 1, typeof(Album), "Kamikaze")]
|
||||
[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(Artist))
|
||||
if (resultType == typeof(Author))
|
||||
{
|
||||
var cast = result[position] as Artist;
|
||||
var cast = result[position] as Author;
|
||||
cast.Should().NotBeNull();
|
||||
cast.Name.Should().Be(expected);
|
||||
}
|
||||
else
|
||||
{
|
||||
var cast = result[position] as Album;
|
||||
var cast = result[position] as Book;
|
||||
cast.Should().NotBeNull();
|
||||
cast.Title.Should().Be(expected);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user