Fixed: Unit Test Fixes

pull/3718/head
Qstick 5 years ago
parent 3bf5476922
commit 242d530bb4

@ -18,6 +18,7 @@ namespace NzbDrone.Api.Config
public string Username { get; set; }
public string Password { get; set; }
public string LogLevel { get; set; }
public string ConsoleLogLevel { get; set; }
public string Branch { get; set; }
public string ApiKey { get; set; }
public string SslCertHash { get; set; }
@ -55,6 +56,7 @@ namespace NzbDrone.Api.Config
//Username
//Password
LogLevel = model.LogLevel,
ConsoleLogLevel = model.ConsoleLogLevel,
Branch = model.Branch,
ApiKey = model.ApiKey,
SslCertHash = model.SslCertHash,

@ -21,10 +21,20 @@ namespace NzbDrone.Common.Test
[TestCase("")]
[TestCase("http://")]
public void DownloadString_should_throw_on_error(string url)
public void DownloadString_should_throw_on_error_windows(string url)
{
WindowsOnly();
Assert.Throws<ArgumentException>(() => Subject.DownloadString(url));
ExceptionVerification.ExpectedWarns(1);
}
[TestCase("http://")]
public void DownloadString_should_throw_on_not_supported_string_mono(string url)
{
MonoOnly();
Assert.Throws<System.Net.WebException>(() => Subject.DownloadString(url));
ExceptionVerification.ExpectedWarns(1);
}
}
}

@ -1,7 +1,8 @@
using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyConfiguration("debug")]
[assembly: AssemblyCompany("radarr.video")]
[assembly: AssemblyProduct("Radarr")]
[assembly: AssemblyVersion("10.0.0.*")]

@ -23,7 +23,7 @@ namespace NzbDrone.Core.Test.IndexerTests.PTPTests
Subject.Definition = new IndexerDefinition()
{
Name = "PTP",
Settings = new PassThePopcornSettings() { Passkey = "fakekey", Username = "asdf", Password = "sad" }
Settings = new PassThePopcornSettings() { APIUser = "asdf", APIKey = "sad" }
};
}

@ -9,6 +9,7 @@ using NzbDrone.Common.Cache;
using NzbDrone.Common.Disk;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Instrumentation;
using NzbDrone.Core.Authentication;
using NzbDrone.Core.Configuration.Events;
using NzbDrone.Core.Lifecycle;
@ -32,6 +33,7 @@ namespace NzbDrone.Core.Configuration
AuthenticationType AuthenticationMethod { get; }
bool AnalyticsEnabled { get; }
string LogLevel { get; }
string ConsoleLogLevel { get; }
string Branch { get; }
string ApiKey { get; }
string SslCertHash { get; }
@ -179,6 +181,7 @@ namespace NzbDrone.Core.Configuration
public string Branch => GetValue("Branch", "develop").ToLowerInvariant();
public string LogLevel => GetValue("LogLevel", "Info");
public string ConsoleLogLevel => GetValue("ConsoleLogLevel", string.Empty, persist: false);
public string SslCertHash => GetValue("SslCertHash", "");

@ -5,9 +5,7 @@ using Newtonsoft.Json;
using NzbDrone.Common.Http;
using NzbDrone.Core.Indexers.Exceptions;
using NzbDrone.Core.Parser.Model;
using System.Linq;
using NLog;
using NzbDrone.Common.Cache;
using NzbDrone.Common.Extensions;
namespace NzbDrone.Core.Indexers.PassThePopcorn

@ -2,10 +2,8 @@ using System;
using System.Collections.Generic;
using NzbDrone.Common.Http;
using NzbDrone.Core.IndexerSearch.Definitions;
using NzbDrone.Common.Cache;
using NLog;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Serializer;
namespace NzbDrone.Core.Indexers.PassThePopcorn
{
@ -44,20 +42,9 @@ namespace NzbDrone.Core.Indexers.PassThePopcorn
new IndexerRequest(
$"{Settings.BaseUrl.Trim().TrimEnd('/')}/torrents.php?action=advanced&json=noredirect&searchstr={searchParameters}",
HttpAccept.Json);
if (Settings.APIKey.IsNullOrWhiteSpace())
{
Cookies = GetCookies();
Authenticate();
Logger.Warn("You are using the old method of logging into PassThePopcorn. Please switch to the new method using APIUser & APIKey.");
}
else
{
request.HttpRequest.Headers["ApiUser"] = Settings.APIUser;
request.HttpRequest.Headers["ApiKey"] = Settings.APIKey;
}
request.HttpRequest.Headers["ApiUser"] = Settings.APIUser;
request.HttpRequest.Headers["ApiKey"] = Settings.APIKey;
if (Settings.APIKey.IsNullOrWhiteSpace())
{
@ -71,49 +58,5 @@ namespace NzbDrone.Core.Indexers.PassThePopcorn
yield return request;
}
private void Authenticate()
{
if (Cookies == null)
{
var requestBuilder = new HttpRequestBuilder($"{Settings.BaseUrl.Trim().TrimEnd('/')}")
{
LogResponseContent = true
};
requestBuilder.Method = HttpMethod.POST;
requestBuilder.Resource("ajax.php?action=login");
requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15);
var authLoginRequest = requestBuilder
.AddFormParameter("username", Settings.Username)
.AddFormParameter("password", Settings.Password)
.AddFormParameter("passkey", Settings.Passkey)
.AddFormParameter("keeplogged", "1")
.SetHeader("Content-Type", "multipart/form-data")
.Accept(HttpAccept.Json)
.Build();
authLoginRequest.AllowAutoRedirect = true;
// We want clean cookies for the auth request.
authLoginRequest.StoreRequestCookie = false;
authLoginRequest.StoreResponseCookie = false;
authLoginRequest.Cookies.Clear();
authLoginRequest.IgnorePersistentCookies = true;
var response = HttpClient.Execute(authLoginRequest);
var result = Json.Deserialize<PassThePopcornAuthResponse>(response.Content);
if (result?.Result != "Ok" || string.IsNullOrWhiteSpace(result.Result))
{
Logger.Debug("PassThePopcorn authentication failed.");
throw new Exception("Failed to authenticate with PassThePopcorn.");
}
Logger.Debug("PassThePopcorn authentication succeeded.");
Cookies = response.GetCookies();
requestBuilder.SetCookies(Cookies);
}
}
}
}

@ -15,9 +15,6 @@ namespace NzbDrone.Core.Indexers.PassThePopcorn
public PassThePopcornSettingsValidator()
{
RuleFor(c => c.BaseUrl).ValidRootUrl();
RuleFor(c => c.Username).Empty();
RuleFor(c => c.Password).Empty();
RuleFor(c => c.Passkey).Empty();
RuleFor(c => c.APIUser).NotEmpty();
RuleFor(c => c.APIKey).NotEmpty();
@ -44,26 +41,17 @@ namespace NzbDrone.Core.Indexers.PassThePopcorn
[FieldDefinition(2, Label = "APIKey", Type = FieldType.Password)]
public string APIKey { get; set; }
[FieldDefinition(3, Label = "DEPRECATED: User", HelpText = "Please use APIKey & APIUser instead. PTP Username")]
public string Username { get; set; }
[FieldDefinition(4, Label = "DEPRECATED: Pass", Type = FieldType.Password, HelpText = "Please use APIKey & APIUser instead. PTP Password")]
public string Password { get; set; }
[FieldDefinition(5, Label = "DEPRECATED: Passkey", HelpText = "Please use APIKey & APIUser instead. PTP Passkey")]
public string Passkey { get; set; }
// [FieldDefinition(6, Type = FieldType.Tag, SelectOptions = typeof(Language), Label = "Multi Languages", HelpText = "What languages are normally in a multi release on this indexer?", Advanced = true)]
// [FieldDefinition(3, Type = FieldType.Tag, SelectOptions = typeof(Language), Label = "Multi Languages", HelpText = "What languages are normally in a multi release on this indexer?", Advanced = true)]
public IEnumerable<int> MultiLanguages { get; set; }
[FieldDefinition(7, Type = FieldType.Textbox, Label = "Minimum Seeders", HelpText = "Minimum number of seeders required.", Advanced = true)]
[FieldDefinition(4, Type = FieldType.Textbox, Label = "Minimum Seeders", HelpText = "Minimum number of seeders required.", Advanced = true)]
public int MinimumSeeders { get; set; }
[FieldDefinition(8)]
[FieldDefinition(5)]
public SeedCriteriaSettings SeedCriteria { get; } = new SeedCriteriaSettings();
[FieldDefinition(9, Type = FieldType.Tag, SelectOptions = typeof(IndexerFlags), Label = "Required Flags", HelpText = "What indexer flags are required?", HelpLink = "https://github.com/Radarr/Radarr/wiki/Indexer-Flags#1-required-flags", Advanced = true)]
[FieldDefinition(6, Type = FieldType.Tag, SelectOptions = typeof(IndexerFlags), Label = "Required Flags", HelpText = "What indexer flags are required?", HelpLink = "https://github.com/Radarr/Radarr/wiki/Indexer-Flags#1-required-flags", Advanced = true)]
public IEnumerable<int> RequiredFlags { get; set; }
public NzbDroneValidationResult Validate()

@ -2,6 +2,7 @@
using System.Linq;
using NLog;
using NLog.Config;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Configuration.Events;
using NzbDrone.Core.Messaging.Events;
@ -20,11 +21,19 @@ namespace NzbDrone.Core.Instrumentation
public void Reconfigure()
{
var minimumLogLevel = LogLevel.FromString(_configFileProvider.LogLevel);
LogLevel minimumConsoleLogLevel;
if (_configFileProvider.ConsoleLogLevel.IsNotNullOrWhiteSpace())
minimumConsoleLogLevel = LogLevel.FromString(_configFileProvider.ConsoleLogLevel);
else if (minimumLogLevel > LogLevel.Info)
minimumConsoleLogLevel = minimumLogLevel;
else
minimumConsoleLogLevel = LogLevel.Info;
var rules = LogManager.Configuration.LoggingRules;
//Console
SetMinimumLogLevel(rules, "consoleLogger", minimumLogLevel);
SetMinimumLogLevel(rules, "consoleLogger", minimumConsoleLogLevel);
//Log Files
SetMinimumLogLevel(rules, "appFileInfo", minimumLogLevel <= LogLevel.Info ? LogLevel.Info : LogLevel.Off);

@ -50,7 +50,7 @@ namespace NzbDrone.Core.Update
{
if (configFileProvider == null)
{
throw new ArgumentNullException("configFileProvider");
throw new ArgumentNullException(nameof(configFileProvider));
}
_checkUpdateService = checkUpdateService;
_appFolderInfo = appFolderInfo;
@ -87,6 +87,12 @@ namespace NzbDrone.Core.Update
}
}
if (_appFolderInfo.StartUpFolder.EndsWith("_output"))
{
_logger.ProgressDebug("Running in developer environment, not updating.");
return;
}
var updateSandboxFolder = _appFolderInfo.GetUpdateSandboxFolder();
var packageDestination = Path.Combine(updateSandboxFolder, updatePackage.FileName);
@ -148,7 +154,7 @@ namespace NzbDrone.Core.Update
}
catch (Exception e)
{
_logger.Error(e, string.Format("Couldn't change the branch from [{0}] to [{1}].", currentBranch, package.Branch));
_logger.Error(e, "Couldn't change the branch from [{0}] to [{1}].", currentBranch, package.Branch);
}
}
}
@ -178,9 +184,8 @@ namespace NzbDrone.Core.Update
{
var processId = _processProvider.GetCurrentProcess().Id.ToString();
var executingApplication = _runtimeInfo.ExecutingApplication;
var args = string.Join(" ", processId, updateSandboxFolder.TrimEnd(Path.DirectorySeparatorChar).WrapInQuotes(), executingApplication.WrapInQuotes(), _startupContext.PreservedArguments);
_logger.Info("Updater Arguments: " + args);
return args;
return string.Join(" ", processId, updateSandboxFolder.TrimEnd(Path.DirectorySeparatorChar).WrapInQuotes(), executingApplication.WrapInQuotes(), _startupContext.PreservedArguments);
}
private void EnsureAppDataSafety()
@ -200,7 +205,7 @@ namespace NzbDrone.Core.Update
if (latestAvailable == null)
{
_logger.ProgressDebug("No update available.");
_logger.ProgressDebug("No update available");
return;
}
@ -213,6 +218,7 @@ namespace NzbDrone.Core.Update
try
{
InstallUpdate(latestAvailable);
_logger.ProgressDebug("Restarting Radarr to apply updates");
}
catch (UpdateFolderNotWritableException ex)
{

@ -13,6 +13,7 @@ namespace NzbDrone.Core.Update
private readonly IUpdatePackageProvider _updatePackageProvider;
private readonly IConfigFileProvider _configFileProvider;
public CheckUpdateService(IUpdatePackageProvider updatePackageProvider,
IConfigFileProvider configFileProvider)
{
@ -25,4 +26,4 @@ namespace NzbDrone.Core.Update
return _updatePackageProvider.GetLatestUpdate(_configFileProvider.Branch, BuildInfo.Version);
}
}
}
}

@ -5,7 +5,6 @@ using NzbDrone.Api.Commands;
namespace NzbDrone.Integration.Test.ApiTests
{
[TestFixture]
[Ignore("Not ready to be used on this branch")]
public class CommandFixture : IntegrationTest
{
[Test]

@ -3,41 +3,11 @@ using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Qualities;
namespace NzbDrone.Integration.Test.ApiTests
namespace NzbDrone.Integration.Test.ApiTests.WantedTests
{
[TestFixture]
public class WantedFixture : IntegrationTest
public class CutoffUnmetFixture : IntegrationTest
{
[Test, Order(0)]
public void missing_should_be_empty()
{
EnsureNoMovie(680, "Pulp Fiction");
var result = WantedMissing.GetPaged(0, 15, "physicalRelease", "desc");
result.Records.Should().BeEmpty();
}
[Test, Order(1)]
public void missing_should_have_monitored_items()
{
EnsureMovie(680, "Pulp Fiction", true);
var result = WantedMissing.GetPaged(0, 15, "physicalRelease", "desc");
result.Records.Should().NotBeEmpty();
}
[Test, Order(1)]
public void missing_should_have_movie()
{
EnsureMovie(680, "Pulp Fiction", true);
var result = WantedMissing.GetPaged(0, 15, "physicalRelease", "desc");
result.Records.First().Title.Should().Be("Pulp Fiction");
}
[Test, Order(1)]
public void cutoff_should_have_monitored_items()
{
@ -45,29 +15,31 @@ namespace NzbDrone.Integration.Test.ApiTests
var movie = EnsureMovie(680, "Pulp Fiction", true);
EnsureMovieFile(movie, Quality.SDTV);
var result = WantedCutoffUnmet.GetPaged(0, 15, "physicalRelease", "desc");
var result = WantedCutoffUnmet.GetPaged(0, 15, "physicalRelease", "desc", "monitored", "true");
result.Records.Should().NotBeEmpty();
}
[Test, Order(1)]
public void missing_should_not_have_unmonitored_items()
public void cutoff_should_not_have_unmonitored_items()
{
EnsureMovie(680, "Pulp Fiction", false);
EnsureProfileCutoff(1, Quality.HDTV720p);
var movie = EnsureMovie(680, "Pulp Fiction", false);
EnsureMovieFile(movie, Quality.SDTV);
var result = WantedMissing.GetPaged(0, 15, "physicalRelease", "desc");
var result = WantedCutoffUnmet.GetPaged(0, 15, "physicalRelease", "desc", "monitored", "true");
result.Records.Should().BeEmpty();
}
[Test, Order(1)]
public void cutoff_should_not_have_unmonitored_items()
public void cutoff_should_not_have_released_items()
{
EnsureProfileCutoff(1, Quality.HDTV720p);
var movie = EnsureMovie(680, "Pulp Fiction", false);
var movie = EnsureMovie(680, "Pulp Fiction", true);
EnsureMovieFile(movie, Quality.SDTV);
var result = WantedCutoffUnmet.GetPaged(0, 15, "physicalRelease", "desc");
var result = WantedCutoffUnmet.GetPaged(0, 15, "physicalRelease", "desc", "status", "inCinemas");
result.Records.Should().BeEmpty();
}
@ -85,25 +57,27 @@ namespace NzbDrone.Integration.Test.ApiTests
}
[Test, Order(2)]
public void missing_should_have_unmonitored_items()
public void cutoff_should_have_unmonitored_items()
{
EnsureMovie(680, "Pulp Fiction", false);
EnsureProfileCutoff(1, Quality.HDTV720p);
var movie = EnsureMovie(680, "Pulp Fiction", false);
EnsureMovieFile(movie, Quality.SDTV);
var result = WantedMissing.GetPaged(0, 15, "physicalRelease", "desc", "monitored", "false");
var result = WantedCutoffUnmet.GetPaged(0, 15, "physicalRelease", "desc", "monitored", "false");
result.Records.Should().NotBeEmpty();
}
[Test, Order(2)]
public void cutoff_should_have_unmonitored_items()
public void cutoff_should_have_released_items()
{
EnsureProfileCutoff(1, Quality.HDTV720p);
var movie = EnsureMovie(680, "Pulp Fiction", false);
EnsureMovieFile(movie, Quality.SDTV);
var result = WantedCutoffUnmet.GetPaged(0, 15, "physicalRelease", "desc", "monitored", "false");
var result = WantedCutoffUnmet.GetPaged(0, 15, "physicalRelease", "desc", "status", "released");
result.Records.Should().NotBeEmpty();
}
}
}
}

@ -0,0 +1,81 @@
using System.Linq;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Qualities;
namespace NzbDrone.Integration.Test.ApiTests.WantedTests
{
[TestFixture]
public class MissingFixture : IntegrationTest
{
[Test, Order(0)]
public void missing_should_be_empty()
{
EnsureNoMovie(680, "Pulp Fiction");
var result = WantedMissing.GetPaged(0, 15, "physicalRelease", "desc");
result.Records.Should().BeEmpty();
}
[Test, Order(1)]
public void missing_should_have_monitored_items()
{
EnsureMovie(680, "Pulp Fiction", true);
var result = WantedMissing.GetPaged(0, 15, "physicalRelease", "desc", "monitored", "true");
result.Records.Should().NotBeEmpty();
}
[Test, Order(1)]
public void missing_should_have_movie()
{
EnsureMovie(680, "Pulp Fiction", true);
var result = WantedMissing.GetPaged(0, 15, "physicalRelease", "desc");
result.Records.First().Title.Should().Be("Pulp Fiction");
}
[Test, Order(1)]
public void missing_should_not_have_unmonitored_items()
{
EnsureMovie(680, "Pulp Fiction", false);
var result = WantedMissing.GetPaged(0, 15, "physicalRelease", "desc", "monitored", "true");
result.Records.Should().BeEmpty();
}
[Test, Order(1)]
public void missing_should_not_have_released_items()
{
EnsureMovie(680, "Pulp Fiction", false);
var result = WantedMissing.GetPaged(0, 15, "physicalRelease", "desc", "status", "inCinemas");
result.Records.Should().BeEmpty();
}
[Test, Order(2)]
public void missing_should_have_unmonitored_items()
{
EnsureMovie(680, "Pulp Fiction", false);
var result = WantedMissing.GetPaged(0, 15, "physicalRelease", "desc", "monitored", "false");
result.Records.Should().NotBeEmpty();
}
[Test, Order(2)]
public void missing_should_have_released_items()
{
EnsureMovie(680, "Pulp Fiction", false);
var result = WantedMissing.GetPaged(0, 15, "physicalRelease", "desc", "status", "released");
result.Records.Should().NotBeEmpty();
}
}
}

@ -63,7 +63,7 @@ namespace NzbDrone.Integration.Test.Client
private static void AssertDisableCache(IList<Parameter> headers)
{
headers.Single(c => c.Name == "Cache-Control").Value.Should().Be("no-cache, no-store, must-revalidate");
headers.Single(c => c.Name == "Cache-Control").Value.Should().Be("no-cache, no-store, must-revalidate, max-age=0");
headers.Single(c => c.Name == "Pragma").Value.Should().Be("no-cache");
headers.Single(c => c.Name == "Expires").Value.Should().Be("0");
}

@ -36,6 +36,11 @@ namespace NzbDrone.Integration.Test
Protocol = Core.Indexers.DownloadProtocol.Usenet,
Fields = SchemaBuilder.ToSchema(new NewznabSettings())
});
// Change Console Log Level to Debug so we get more details.
var config = HostConfig.Get(1);
config.ConsoleLogLevel = "Debug";
HostConfig.Put(config);
}
protected override void StopTestTarget()

@ -238,6 +238,8 @@ namespace NzbDrone.Integration.Test
}
}
Commands.WaitAll();
return result;
}
@ -257,9 +259,13 @@ namespace NzbDrone.Integration.Test
if (result.MovieFile == null)
{
var path = Path.Combine(MovieRootFolder, movie.Title, string.Format("{0} - {1}.mkv", movie.Title, quality.Name));
var path = Path.Combine(MovieRootFolder, movie.Title, string.Format("{0} ({1}) - {2}.strm", movie.Title, movie.Year, quality.Name));
Directory.CreateDirectory(Path.GetDirectoryName(path));
var sourcePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "ApiTests", "Files", "H264_sample.mp4");
//File.Copy(sourcePath, path);
File.WriteAllText(path, "Fake Movie");
Commands.PostAndWait(new CommandResource { Name = "refreshmovie", Body = new RefreshMovieCommand(movie.Id) });

@ -107,7 +107,8 @@
<Compile Include="ApiTests\MovieFileFixture.cs" />
<Compile Include="ApiTests\FileSystemFixture.cs" />
<Compile Include="ApiTests\MovieLookupFixture.cs" />
<Compile Include="ApiTests\WantedFixture.cs" />
<Compile Include="ApiTests\WantedTests\CutoffUnmetFixture.cs" />
<Compile Include="ApiTests\WantedTests\MissingFixture.cs" />
<Compile Include="Client\ClientBase.cs" />
<Compile Include="Client\IndexerClient.cs" />
<Compile Include="Client\DownloadClientClient.cs" />

@ -19,6 +19,7 @@ namespace Radarr.Api.V2.Config
public string Username { get; set; }
public string Password { get; set; }
public string LogLevel { get; set; }
public string ConsoleLogLevel { get; set; }
public string Branch { get; set; }
public string ApiKey { get; set; }
public string SslCertHash { get; set; }
@ -57,6 +58,7 @@ namespace Radarr.Api.V2.Config
//Username
//Password
LogLevel = model.LogLevel,
ConsoleLogLevel = model.ConsoleLogLevel,
Branch = model.Branch,
ApiKey = model.ApiKey,
SslCertHash = model.SslCertHash,

Loading…
Cancel
Save