1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-04 10:34:59 +02:00

SabProvider can now get the entire Queue for additional processing.

This commit is contained in:
Mark McDowall 2012-01-18 16:05:44 -08:00
parent 7acb563c05
commit 26c4240a6b
5 changed files with 138 additions and 4 deletions

View File

@ -15,13 +15,35 @@
<verbosity></verbosity>
<mb>770.96</mb>
<sizeleft>770.96 MB</sizeleft>
<filename>Ubuntu Test</filename>
<filename>30 Rock - 1x05 - Title [SDTV]</filename>
<priority>Normal</priority>
<cat>None</cat>
<mbleft>770.96</mbleft>
<percentage>0</percentage>
<nzo_id>SABnzbd_nzo_xyr5ak</nzo_id>
<unpackopts>3</unpackopts>
<size>770.96 MB</size>
</slot>
<slot>
<status>Queued</status>
<index>0</index>
<eta>unknown</eta>
<timeleft>0:00:00</timeleft>
<avg_age>11h</avg_age>
<script>None</script>
<msgid></msgid>
<verbosity></verbosity>
<mb>770.96</mb>
<sizeleft>770.96 MB</sizeleft>
<filename>The Office (US) - 1x05 - Title [WEBDL]</filename>
<priority>Normal</priority>
<cat>None</cat>
<mbleft>770.96</mbleft>
<percentage>0</percentage>
<nzo_id>SABnzbd_nzo_kqr9gl</nzo_id>
<unpackopts>3</unpackopts>
<size>770.96 MB</size>
</slot>

View File

@ -23,6 +23,28 @@ namespace NzbDrone.Core.Test.ProviderTests
// ReSharper disable InconsistentNaming
public class SabProviderTest : CoreTest
{
private void WithSabConfigValues()
{
//Setup
string sabHost = "192.168.5.55";
int sabPort = 2222;
string apikey = "5c770e3197e4fe763423ee7c392c25d1";
string username = "admin";
string password = "pass";
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SabHost)
.Returns(sabHost);
fakeConfig.SetupGet(c => c.SabPort)
.Returns(sabPort);
fakeConfig.SetupGet(c => c.SabApiKey)
.Returns(apikey);
fakeConfig.SetupGet(c => c.SabUsername)
.Returns(username);
fakeConfig.SetupGet(c => c.SabPassword)
.Returns(password);
}
[Test]
public void AddByUrlSuccess()
{
@ -168,8 +190,6 @@ public void IsInQueue_True()
string username = "admin";
string password = "pass";
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SabHost)
.Returns(sabHost);
@ -187,7 +207,7 @@ public void IsInQueue_True()
.Returns(File.ReadAllText(@".\Files\Queue.xml"));
//Act
bool result = Mocker.Resolve<SabProvider>().IsInQueue("Ubuntu Test");
bool result = Mocker.Resolve<SabProvider>().IsInQueue("30 Rock - 1x05 - Title [SDTV]");
//Assert
result.Should().BeTrue();
@ -445,5 +465,54 @@ public void Get_Categories_Success_Config_Values()
result.Should().NotBeNull();
result.categories.Should().HaveCount(c => c > 0);
}
[Test]
public void GetQueue_should_return_an_empty_list_when_the_queue_is_empty()
{
WithSabConfigValues();
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=queue&output=xml&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
.Returns(File.ReadAllText(@".\Files\QueueEmpty.xml"));
//Act
var result = Mocker.Resolve<SabProvider>().GetQueue();
//Assert
result.Should().BeEmpty();
}
[Test]
[ExpectedException(typeof(ApplicationException), ExpectedMessage = "API Key Incorrect")]
public void GetQueue_should_return_an_empty_list_when_there_is_an_error_getting_the_queue()
{
WithSabConfigValues();
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=queue&output=xml&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
.Returns(File.ReadAllText(@".\Files\QueueError.xml"));
//Act
var result = Mocker.Resolve<SabProvider>().GetQueue();
//Assert
result.Should().BeEmpty();
}
[Test]
public void GetQueue_should_return_a_list_with_items_when_the_queue_has_items()
{
WithSabConfigValues();
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=queue&output=xml&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
.Returns(File.ReadAllText(@".\Files\Queue.xml"));
//Act
var result = Mocker.Resolve<SabProvider>().GetQueue();
//Assert
result.Should().HaveCount(2);
}
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NzbDrone.Core.Model
{
public class SabQueueItem
{
public string Id { get; set; }
public string Title { get; set; }
}
}

View File

@ -234,6 +234,7 @@
<Compile Include="Model\Quality.cs" />
<Compile Include="Model\SabnzbdCategoryModel.cs" />
<Compile Include="Model\SabnzbdInfoModel.cs" />
<Compile Include="Model\SabQueueItem.cs" />
<Compile Include="Model\Twitter\TwitterAuthorizationModel.cs" />
<Compile Include="Model\UpdatePackage.cs" />
<Compile Include="Model\Xbmc\ActionType.cs" />

View File

@ -10,6 +10,7 @@
using NLog;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository.Quality;
namespace NzbDrone.Core.Providers
{
@ -103,6 +104,34 @@ public virtual bool IsInQueue(string title)
return false; //Not in Queue
}
public virtual List<SabQueueItem> GetQueue()
{
const string action = "mode=queue&output=xml";
string request = GetSabRequest(action);
string response = _httpProvider.DownloadString(request);
XDocument xDoc = XDocument.Parse(response);
//If an Error Occurred, return)
if (xDoc.Descendants("error").Count() != 0)
throw new ApplicationException(xDoc.Descendants("error").FirstOrDefault().Value);
if (!xDoc.Descendants("queue").Any())
{
Logger.Debug("SAB Queue is empty.");
return new List<SabQueueItem>();
}
var items = xDoc.Descendants("slot")
.Select(s => new SabQueueItem
{
Title = s.Element("filename").Value,
Id = s.Element("nzo_id").Value
});
return items.ToList();
}
public virtual String GetSabTitle(EpisodeParseResult parseResult)
{
//Handle Full Naming