mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-18 21:34:28 -04:00
Fixed: All the tests
This commit is contained in:
@@ -23,27 +23,27 @@ namespace NzbDrone.Integration.Test.ApiTests
|
||||
[Test]
|
||||
public void should_be_able_to_get_albums()
|
||||
{
|
||||
var artist = EnsureArtist("aaaa_aaaaa_asaaaaa", "Alien Ant Farm", true);
|
||||
var artist = EnsureArtist("cc2c9c3c-b7bc-4b8b-84d8-4fbd8779e493", "Adele", true);
|
||||
|
||||
var request = Calendar.BuildRequest();
|
||||
request.AddParameter("start", new DateTime(2015, 10, 1).ToString("s") + "Z");
|
||||
request.AddParameter("end", new DateTime(2015, 10, 3).ToString("s") + "Z");
|
||||
request.AddParameter("start", new DateTime(2015, 11, 19).ToString("s") + "Z");
|
||||
request.AddParameter("end", new DateTime(2015, 11, 21).ToString("s") + "Z");
|
||||
var items = Calendar.Get<List<AlbumResource>>(request);
|
||||
|
||||
items = items.Where(v => v.ArtistId == artist.Id).ToList();
|
||||
|
||||
items.Should().HaveCount(1);
|
||||
items.First().Title.Should().Be("The Troll Farmer");
|
||||
items.First().Title.Should().Be("25");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_be_able_to_get_unmonitored_albums()
|
||||
{
|
||||
var artist = EnsureArtist("aaaa_aaaaa_asaaaaa", "Alien Ant Farm", false);
|
||||
var artist = EnsureArtist("cc2c9c3c-b7bc-4b8b-84d8-4fbd8779e493", "Adele", false);
|
||||
|
||||
var request = Calendar.BuildRequest();
|
||||
request.AddParameter("start", new DateTime(2015, 10, 1).ToString("s") + "Z");
|
||||
request.AddParameter("end", new DateTime(2015, 10, 3).ToString("s") + "Z");
|
||||
request.AddParameter("start", new DateTime(2015, 11, 19).ToString("s") + "Z");
|
||||
request.AddParameter("end", new DateTime(2015, 11, 21).ToString("s") + "Z");
|
||||
request.AddParameter("unmonitored", "false");
|
||||
var items = Calendar.Get<List<AlbumResource>>(request);
|
||||
|
||||
@@ -55,18 +55,18 @@ namespace NzbDrone.Integration.Test.ApiTests
|
||||
[Test]
|
||||
public void should_be_able_to_get_unmonitored_albums()
|
||||
{
|
||||
var artist = EnsureArtist("aaaa_aaaaa_asaaaaa", "Alien Ant Farm", false);
|
||||
var artist = EnsureArtist("cc2c9c3c-b7bc-4b8b-84d8-4fbd8779e493", "Adele", false);
|
||||
|
||||
var request = Calendar.BuildRequest();
|
||||
request.AddParameter("start", new DateTime(2015, 10, 1).ToString("s") + "Z");
|
||||
request.AddParameter("end", new DateTime(2015, 10, 3).ToString("s") + "Z");
|
||||
request.AddParameter("start", new DateTime(2015, 11, 19).ToString("s") + "Z");
|
||||
request.AddParameter("end", new DateTime(2015, 11, 21).ToString("s") + "Z");
|
||||
request.AddParameter("unmonitored", "true");
|
||||
var items = Calendar.Get<List<AlbumResource>>(request);
|
||||
|
||||
items = items.Where(v => v.ArtistId == artist.Id).ToList();
|
||||
|
||||
items.Should().HaveCount(1);
|
||||
items.First().Title.Should().Be("The Troll Farmer");
|
||||
items.First().Title.Should().Be("25");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using Lidarr.Api.V1.Commands;
|
||||
using NzbDrone.Integration.Test.Client;
|
||||
|
||||
namespace NzbDrone.Integration.Test.ApiTests
|
||||
{
|
||||
@@ -11,7 +11,7 @@ namespace NzbDrone.Integration.Test.ApiTests
|
||||
[Test]
|
||||
public void should_be_able_to_run_rss_sync()
|
||||
{
|
||||
var response = Commands.Post(new CommandResource { Name = "rsssync" });
|
||||
var response = Commands.Post(new SimpleCommandResource { Name = "rsssync" });
|
||||
|
||||
response.Id.Should().NotBe(0);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using Lidarr.Api.V1.Artist;
|
||||
using System.Linq;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Integration.Test.ApiTests
|
||||
{
|
||||
@@ -15,30 +14,16 @@ namespace NzbDrone.Integration.Test.ApiTests
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_artist = GivenArtistWithTracks();
|
||||
_artist = EnsureArtist("8ac6cc32-8ddf-43b1-9ac4-4b04f9053176", "Alien Ant Farm");
|
||||
}
|
||||
|
||||
private ArtistResource GivenArtistWithTracks()
|
||||
{
|
||||
var newArtist = Artist.Lookup("archer").Single(c => c.ForeignArtistId == "110381");
|
||||
|
||||
newArtist.QualityProfileId = 1;
|
||||
newArtist.Path = @"C:\Test\Archer".AsOsAgnostic();
|
||||
|
||||
newArtist = Artist.Post(newArtist);
|
||||
|
||||
WaitForCompletion(() => Tracks.GetTracksInArtist(newArtist.Id).Count > 0);
|
||||
|
||||
return newArtist;
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Test, Order(0)]
|
||||
public void should_be_able_to_get_all_tracks_in_artist()
|
||||
{
|
||||
Tracks.GetTracksInArtist(_artist.Id).Count.Should().BeGreaterThan(0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Test, Order(1)]
|
||||
public void should_be_able_to_get_a_single_track()
|
||||
{
|
||||
var tracks = Tracks.GetTracksInArtist(_artist.Id);
|
||||
|
||||
@@ -36,15 +36,15 @@ namespace NzbDrone.Integration.Test.ApiTests
|
||||
var result = WantedMissing.GetPaged(0, 15, "releaseDate", "desc");
|
||||
|
||||
result.Records.First().Artist.Should().NotBeNull();
|
||||
result.Records.First().Artist.ArtistName.Should().Be("The Blacklist");
|
||||
result.Records.First().Artist.ArtistName.Should().Be("Alien Ant Farm");
|
||||
}
|
||||
|
||||
[Test, Order(1)]
|
||||
public void cutoff_should_have_monitored_items()
|
||||
{
|
||||
EnsureProfileCutoff(1, Quality.MP3_256);
|
||||
EnsureProfileCutoff(1, "Lossless");
|
||||
var artist = EnsureArtist("8ac6cc32-8ddf-43b1-9ac4-4b04f9053176", "Alien Ant Farm", true);
|
||||
EnsureTrackFile(artist, 1, 1, Quality.MP3_192);
|
||||
EnsureTrackFile(artist, 1, 1, 1, Quality.MP3_192);
|
||||
|
||||
var result = WantedCutoffUnmet.GetPaged(0, 15, "releaseDate", "desc");
|
||||
|
||||
@@ -64,9 +64,9 @@ namespace NzbDrone.Integration.Test.ApiTests
|
||||
[Test, Order(1)]
|
||||
public void cutoff_should_not_have_unmonitored_items()
|
||||
{
|
||||
EnsureProfileCutoff(1, Quality.MP3_256);
|
||||
EnsureProfileCutoff(1, "Lossless");
|
||||
var artist = EnsureArtist("8ac6cc32-8ddf-43b1-9ac4-4b04f9053176", "Alien Ant Farm", false);
|
||||
EnsureTrackFile(artist, 1, 1, Quality.MP3_192);
|
||||
EnsureTrackFile(artist, 1, 1, 1, Quality.MP3_192);
|
||||
|
||||
var result = WantedCutoffUnmet.GetPaged(0, 15, "releaseDate", "desc");
|
||||
|
||||
@@ -76,9 +76,9 @@ namespace NzbDrone.Integration.Test.ApiTests
|
||||
[Test, Order(1)]
|
||||
public void cutoff_should_have_artist()
|
||||
{
|
||||
EnsureProfileCutoff(1, Quality.MP3_256);
|
||||
EnsureProfileCutoff(1, "Lossless");
|
||||
var artist = EnsureArtist("8ac6cc32-8ddf-43b1-9ac4-4b04f9053176", "Alien Ant Farm", true);
|
||||
EnsureTrackFile(artist, 1, 1, Quality.MP3_192);
|
||||
EnsureTrackFile(artist, 1, 1, 1, Quality.MP3_192);
|
||||
|
||||
var result = WantedCutoffUnmet.GetPaged(0, 15, "releaseDate", "desc");
|
||||
|
||||
@@ -99,9 +99,9 @@ namespace NzbDrone.Integration.Test.ApiTests
|
||||
[Test, Order(2)]
|
||||
public void cutoff_should_have_unmonitored_items()
|
||||
{
|
||||
EnsureProfileCutoff(1, Quality.MP3_256);
|
||||
EnsureProfileCutoff(1, "Lossless");
|
||||
var artist = EnsureArtist("8ac6cc32-8ddf-43b1-9ac4-4b04f9053176", "Alien Ant Farm", false);
|
||||
EnsureTrackFile(artist, 1, 1, Quality.MP3_192);
|
||||
EnsureTrackFile(artist, 1, 1, 1, Quality.MP3_192);
|
||||
|
||||
var result = WantedCutoffUnmet.GetPaged(0, 15, "releaseDate", "desc", "monitored", "false");
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace NzbDrone.Integration.Test.Client
|
||||
return request;
|
||||
}
|
||||
|
||||
public T Execute<T>(IRestRequest request, HttpStatusCode statusCode) where T : class, new()
|
||||
public string Execute(IRestRequest request, HttpStatusCode statusCode)
|
||||
{
|
||||
_logger.Info("{0}: {1}", request.Method, _restClient.BuildUri(request));
|
||||
|
||||
@@ -58,7 +58,14 @@ namespace NzbDrone.Integration.Test.Client
|
||||
|
||||
response.StatusCode.Should().Be(statusCode);
|
||||
|
||||
return Json.Deserialize<T>(response.Content);
|
||||
return response.Content;
|
||||
}
|
||||
|
||||
public T Execute<T>(IRestRequest request, HttpStatusCode statusCode) where T : class, new()
|
||||
{
|
||||
var content = Execute(request, statusCode);
|
||||
|
||||
return Json.Deserialize<T>(content);
|
||||
}
|
||||
|
||||
private static void AssertDisableCache(IList<Parameter> headers)
|
||||
|
||||
@@ -1,23 +1,47 @@
|
||||
using Lidarr.Api.V1.Commands;
|
||||
using RestSharp;
|
||||
using NzbDrone.Core.Messaging.Commands;
|
||||
using FluentAssertions;
|
||||
using System.Threading;
|
||||
using NUnit.Framework;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using Lidarr.Http.REST;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace NzbDrone.Integration.Test.Client
|
||||
{
|
||||
public class CommandClient : ClientBase<CommandResource>
|
||||
public class SimpleCommandResource : RestResource
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string CommandName { get; set; }
|
||||
public string Message { get; set; }
|
||||
public CommandPriority Priority { get; set; }
|
||||
public CommandStatus Status { get; set; }
|
||||
public DateTime Queued { get; set; }
|
||||
public DateTime? Started { get; set; }
|
||||
public DateTime? Ended { get; set; }
|
||||
public TimeSpan? Duration { get; set; }
|
||||
public string Exception { get; set; }
|
||||
public CommandTrigger Trigger { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public Command Body { get; set; }
|
||||
[JsonProperty("body")]
|
||||
public Command BodyReadOnly { get { return Body; } }
|
||||
}
|
||||
|
||||
public class CommandClient : ClientBase<SimpleCommandResource>
|
||||
{
|
||||
public CommandClient(IRestClient restClient, string apiKey)
|
||||
: base(restClient, apiKey)
|
||||
: base(restClient, apiKey, "command")
|
||||
{
|
||||
}
|
||||
|
||||
public CommandResource PostAndWait(CommandResource command)
|
||||
public SimpleCommandResource PostAndWait<T>(T command) where T : Command, new()
|
||||
{
|
||||
var result = Post(command);
|
||||
var request = BuildRequest();
|
||||
request.AddBody(command);
|
||||
var result = Post<SimpleCommandResource>(request);
|
||||
result.Id.Should().NotBe(0);
|
||||
|
||||
for (var i = 0; i < 50; i++)
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using RestSharp;
|
||||
|
||||
namespace NzbDrone.Integration.Test.Client
|
||||
{
|
||||
public class LogsClient : ClientBase
|
||||
{
|
||||
public LogsClient(IRestClient restClient, string apiKey)
|
||||
: base(restClient, apiKey, "log/file")
|
||||
{
|
||||
}
|
||||
|
||||
public string[] GetLogFileLines(string filename)
|
||||
{
|
||||
var request = BuildRequest(filename);
|
||||
var content = Execute(request, System.Net.HttpStatusCode.OK);
|
||||
|
||||
var lines = content.Split('\n');
|
||||
lines = Array.ConvertAll(lines, s => s.TrimEnd('\r'));
|
||||
Array.Resize(ref lines, lines.Length - 1);
|
||||
return lines;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
@@ -15,16 +15,20 @@ namespace NzbDrone.Integration.Test
|
||||
config.LogLevel = "Trace";
|
||||
HostConfig.Put(config);
|
||||
|
||||
var logFile = Path.Combine(_runner.AppData, "logs", "Lidarr.trace.txt");
|
||||
var logLines = File.ReadAllLines(logFile);
|
||||
var resultGet = Artist.All();
|
||||
|
||||
var logFile = "Lidarr.trace.txt";
|
||||
var logLines = Logs.GetLogFileLines(logFile);
|
||||
|
||||
var result = Artist.InvalidPost(new Lidarr.Api.V1.Artist.ArtistResource());
|
||||
|
||||
logLines = File.ReadAllLines(logFile).Skip(logLines.Length).ToArray();
|
||||
// Skip 2 and 1 to ignore the logs endpoint
|
||||
logLines = Logs.GetLogFileLines(logFile).Skip(logLines.Length + 2).ToArray();
|
||||
Array.Resize(ref logLines, logLines.Length - 1);
|
||||
|
||||
logLines.Should().Contain(v => v.Contains("|Trace|Http|Req"));
|
||||
logLines.Should().Contain(v => v.Contains("|Trace|Http|Res"));
|
||||
logLines.Should().Contain(v => v.Contains("|Debug|Api|"));
|
||||
logLines.Should().Contain(v => v.Contains("|Trace|Http|Req") && v.Contains("/api/v1/artist/"));
|
||||
logLines.Should().Contain(v => v.Contains("|Trace|Http|Res") && v.Contains("/api/v1/artist/: 400.BadRequest"));
|
||||
logLines.Should().Contain(v => v.Contains("|Debug|Api|") && v.Contains("/api/v1/artist/: 400.BadRequest"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
@@ -30,6 +31,8 @@ using NzbDrone.Integration.Test.Client;
|
||||
using NzbDrone.SignalR;
|
||||
using NzbDrone.Test.Common.Categories;
|
||||
using RestSharp;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport.Manual;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Integration.Test
|
||||
{
|
||||
@@ -46,6 +49,7 @@ namespace NzbDrone.Integration.Test
|
||||
public ClientBase<HistoryResource> History;
|
||||
public ClientBase<HostConfigResource> HostConfig;
|
||||
public IndexerClient Indexers;
|
||||
public LogsClient Logs;
|
||||
public ClientBase<NamingConfigResource> NamingConfig;
|
||||
public NotificationClient Notifications;
|
||||
public ClientBase<QualityProfileResource> Profiles;
|
||||
@@ -108,6 +112,7 @@ namespace NzbDrone.Integration.Test
|
||||
History = new ClientBase<HistoryResource>(RestClient, ApiKey);
|
||||
HostConfig = new ClientBase<HostConfigResource>(RestClient, ApiKey, "config/host");
|
||||
Indexers = new IndexerClient(RestClient, ApiKey);
|
||||
Logs = new LogsClient(RestClient, ApiKey);
|
||||
NamingConfig = new ClientBase<NamingConfigResource>(RestClient, ApiKey, "config/naming");
|
||||
Notifications = new NotificationClient(RestClient, ApiKey);
|
||||
Profiles = new ClientBase<QualityProfileResource>(RestClient, ApiKey);
|
||||
@@ -129,7 +134,10 @@ namespace NzbDrone.Integration.Test
|
||||
[SetUp]
|
||||
public void IntegrationSetUp()
|
||||
{
|
||||
TempDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "_test_" + DateTime.UtcNow.Ticks);
|
||||
TempDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "_test_" + TestBase.GetUID());
|
||||
|
||||
// Wait for things to get quiet, otherwise the previous test might influence the current one.
|
||||
Commands.WaitAll();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
@@ -150,6 +158,17 @@ namespace NzbDrone.Integration.Test
|
||||
_signalrConnection = null;
|
||||
_signalRReceived = new List<SignalRMessage>();
|
||||
}
|
||||
|
||||
if (Directory.Exists(TempDirectory))
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.Delete(TempDirectory, true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string GetTempDirectory(params string[] args)
|
||||
@@ -227,19 +246,27 @@ namespace NzbDrone.Integration.Test
|
||||
WaitForCompletion(() => Tracks.GetTracksInArtist(result.Id).Count > 0);
|
||||
}
|
||||
|
||||
var changed = false;
|
||||
|
||||
if (result.RootFolderPath != ArtistRootFolder)
|
||||
{
|
||||
changed = true;
|
||||
result.RootFolderPath = ArtistRootFolder;
|
||||
result.Path = Path.Combine(ArtistRootFolder, result.ArtistName);
|
||||
}
|
||||
|
||||
if (monitored.HasValue)
|
||||
{
|
||||
var changed = false;
|
||||
if (result.Monitored != monitored.Value)
|
||||
{
|
||||
result.Monitored = monitored.Value;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (changed)
|
||||
{
|
||||
Artist.Put(result);
|
||||
}
|
||||
if (changed)
|
||||
{
|
||||
Artist.Put(result);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -256,35 +283,45 @@ namespace NzbDrone.Integration.Test
|
||||
}
|
||||
}
|
||||
|
||||
public TrackFileResource EnsureTrackFile(ArtistResource artist, int albumId, int track, Quality quality)
|
||||
public void EnsureTrackFile(ArtistResource artist, int albumId, int albumReleaseId, int trackId, Quality quality)
|
||||
{
|
||||
var result = Tracks.GetTracksInArtist(artist.Id).Single(v => v.AlbumId == albumId && v.AbsoluteTrackNumber == track);
|
||||
var result = Tracks.GetTracksInArtist(artist.Id).Single(v => v.Id == trackId);
|
||||
|
||||
if (result.TrackFile == null)
|
||||
{
|
||||
var path = Path.Combine(ArtistRootFolder, artist.ArtistName, string.Format("{0} - {1} - Track.mp3", track, artist.ArtistName));
|
||||
var path = Path.Combine(ArtistRootFolder, artist.ArtistName, "Track.mp3");
|
||||
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
||||
File.WriteAllText(path, "Fake Track");
|
||||
|
||||
Commands.PostAndWait(new CommandResource { Name = "refreshartist", Body = new RefreshArtistCommand(artist.Id) });
|
||||
Commands.PostAndWait(new ManualImportCommand {
|
||||
Files = new List<ManualImportFile> {
|
||||
new ManualImportFile {
|
||||
Path = path,
|
||||
ArtistId = artist.Id,
|
||||
AlbumId = albumId,
|
||||
AlbumReleaseId = albumReleaseId,
|
||||
TrackIds = new List<int> { trackId },
|
||||
Quality = new QualityModel(quality)
|
||||
}
|
||||
}
|
||||
});
|
||||
Commands.WaitAll();
|
||||
|
||||
result = Tracks.GetTracksInArtist(artist.Id).Single(v => v.AlbumId == albumId && v.AbsoluteTrackNumber == track);
|
||||
var track = Tracks.GetTracksInArtist(artist.Id).Single(x => x.Id == trackId);
|
||||
|
||||
result.TrackFile.Should().NotBeNull();
|
||||
track.TrackFileId.Should().NotBe(0);
|
||||
}
|
||||
|
||||
return result.TrackFile;
|
||||
}
|
||||
|
||||
public QualityProfileResource EnsureProfileCutoff(int profileId, Quality cutoff)
|
||||
public QualityProfileResource EnsureProfileCutoff(int profileId, string cutoff)
|
||||
{
|
||||
var profile = Profiles.Get(profileId);
|
||||
var cutoffItem = profile.Items.First(x => x.Name == cutoff);
|
||||
|
||||
if (profile.Cutoff != cutoff.Id)
|
||||
if (profile.Cutoff != cutoffItem.Id)
|
||||
{
|
||||
profile.Cutoff = cutoff.Id;
|
||||
profile.Cutoff = cutoffItem.Id;
|
||||
profile = Profiles.Put(profile);
|
||||
}
|
||||
|
||||
|
||||
@@ -74,6 +74,7 @@
|
||||
<Compile Include="Client\CommandClient.cs" />
|
||||
<Compile Include="Client\ReleaseClient.cs" />
|
||||
<Compile Include="Client\ArtistClient.cs" />
|
||||
<Compile Include="Client\LogsClient.cs" />
|
||||
<Compile Include="ApiTests\CommandFixture.cs" />
|
||||
<Compile Include="CorsFixture.cs" />
|
||||
<Compile Include="ApiTests\TrackFixture.cs" />
|
||||
@@ -190,4 +191,4 @@
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user