more reliable apikey for integration tests.

pull/6/head
kayone 11 years ago
parent 1695ff7305
commit af3ffa1c48

@ -119,7 +119,7 @@ namespace NzbDrone.Core.Notifications.Xbmc
return String.Empty; return String.Empty;
var xDoc = XDocument.Load(new StringReader(response.Replace("&", "&"))); var xDoc = XDocument.Load(new StringReader(response.Replace("&", "&")));
var xml = (from x in xDoc.Descendants("xml") select x).FirstOrDefault(); var xml = xDoc.Descendants("xml").Select(x => x).FirstOrDefault();
if (xml == null) if (xml == null)
return null; return null;

@ -4,6 +4,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Xml.Linq; using System.Xml.Linq;
using System.Xml.XPath;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Processes; using NzbDrone.Common.Processes;
@ -56,7 +57,7 @@ namespace NzbDrone.Integration.Test
Assert.Fail("Process has exited"); Assert.Fail("Process has exited");
} }
ApiKey = GetApiKey(); SetApiKey();
var request = new RestRequest("system/status"); var request = new RestRequest("system/status");
request.AddHeader("Authorization", ApiKey); request.AddHeader("Authorization", ApiKey);
@ -98,16 +99,23 @@ namespace NzbDrone.Integration.Test
} }
} }
private string GetApiKey() private void SetApiKey()
{ {
var configFile = Path.Combine(AppData, "config.xml"); var configFile = Path.Combine(AppData, "config.xml");
if (!String.IsNullOrWhiteSpace(ApiKey)) return ApiKey; while (ApiKey == null)
if (!File.Exists(configFile)) return null; {
if (File.Exists(configFile))
var xDoc = XDocument.Load(configFile); {
var config = xDoc.Descendants(ConfigFileProvider.CONFIG_ELEMENT_NAME).Single(); var apiKeyElement = XDocument.Load(configFile)
return config.Descendants("ApiKey").Single().Value; .XPathSelectElement("Config/ApiKey");
if (apiKeyElement != null)
{
ApiKey = apiKeyElement.Value;
}
}
Thread.Sleep(1000);
}
} }
} }
} }
Loading…
Cancel
Save