diff --git a/NzbDrone.Core.Test/Files/QueueUnknownPriority.txt b/NzbDrone.Core.Test/Files/QueueUnknownPriority.txt new file mode 100644 index 000000000..0d0c18abd --- /dev/null +++ b/NzbDrone.Core.Test/Files/QueueUnknownPriority.txt @@ -0,0 +1,210 @@ +{ + "queue":{ + "active_lang":"en", + "cache_art":"10", + "cache_max":"67108864", + "cache_size":"7 MB", + "categories":[ + "*", + "apps", + "consoles", + "emp", + "movies", + "tv" + ], + "color_scheme":"lightblue", + "darwin":false, + "diskspace1":"127.50", + "diskspace2":"127.50", + "diskspacetotal1":"157.76", + "diskspacetotal2":"157.76", + "eta":"01:45 PM Mon 23 Jan", + "finish":0, + "finishaction":null, + "have_warnings":"20", + "helpuri":"http://wiki.sabnzbd.org/", + "isverbose":false, + "kbpersec":"2.18", + "last_warning":"2012-01-19 23:42:39,934\nWARNING:\nAPI Key incorrect, Use the api key from Config->General in your 3rd party program:", + "limit":0, + "loadavg":"", + "mb":"686.67", + "mbleft":"657.89", + "new_rel_url":"http://sourceforge.net/projects/sabnzbdplus/files/sabnzbdplus/sabnzbd-0.6.14", + "new_release":"0.6.14", + "newzbinDetails":true, + "noofslots":2, + "nt":true, + "nzb_quota":"", + "pause_int":"0", + "paused":false, + "paused_all":false, + "power_options":true, + "queue_details":"0", + "refresh_rate":"20", + "restart_req":false, + "scripts":[ + + ], + "session":"f37dc33baec2e5566f5aec666287870d", + "size":"687 MB", + "sizeleft":"658 MB", + "slots":[ + { + "avg_age":"149d", + "cat":"tv", + "eta":"06:55 AM Sat 21 Jan", + "filename":"30 Rock - 1x05 - Title [HDTV]", + "index":0, + "mb":"267.44", + "mbleft":"238.66", + "missing":0, + "msgid":6256072, + "nzo_id":"SABnzbd_nzo_qv6ilb", + "percentage":"10", + "priority":"Repair", + "script":"None", + "size":"267 MB", + "sizeleft":"239 MB", + "status":"Downloading", + "timeleft":"57:27:45", + "unpackopts":"3", + "verbosity":"" + }, + { + "avg_age":"580d", + "cat":"tv", + "eta":"01:45 PM Mon 23 Jan", + "filename":"Parks and Recreation - 4x8 - Smallest Park [WEBDL]", + "index":1, + "mb":"419.23", + "mbleft":"419.23", + "missing":0, + "msgid":5657628, + "nzo_id":"SABnzbd_nzo_dgrzts", + "percentage":"0", + "priority":"Fail", + "script":"None", + "size":"419 MB", + "sizeleft":"419 MB", + "status":"Queued", + "timeleft":"86:01:55", + "unpackopts":"3", + "verbosity":"" + }, + { + "avg_age":"580d", + "cat":"tv", + "eta":"01:45 PM Mon 23 Jan", + "filename":"Invalid Item", + "index":1, + "mb":"419.23", + "mbleft":"419.23", + "missing":0, + "msgid":5657628, + "nzo_id":"SABnzbd_nzo_dgrzts", + "percentage":"0", + "priority":"Normal", + "script":"None", + "size":"419 MB", + "sizeleft":"419 MB", + "status":"Queued", + "timeleft":"86:01:55", + "unpackopts":"3", + "verbosity":"" + }, + { + "avg_age":"580d", + "cat":"tv", + "eta":"01:45 PM Mon 23 Jan", + "filename":"The Dailyshow - 2011-12-01 - My Episode Title [Bluray720p] [Proper]", + "index":1, + "mb":"419.23", + "mbleft":"419.23", + "missing":0, + "msgid":5657628, + "nzo_id":"SABnzbd_nzo_dgrzts", + "percentage":"0", + "priority":"Test", + "script":"None", + "size":"419 MB", + "sizeleft":"419 MB", + "status":"Queued", + "timeleft":"86:01:55", + "unpackopts":"3", + "verbosity":"" + }, + { + "avg_age":"580d", + "cat":"tv", + "eta":"01:45 PM Mon 23 Jan", + "filename":"My Name is earl - Season 5 [Bluray720p]", + "index":1, + "mb":"419.23", + "mbleft":"419.23", + "missing":0, + "msgid":5657628, + "nzo_id":"SABnzbd_nzo_dgrzts", + "percentage":"0", + "priority":"Normal", + "script":"None", + "size":"419 MB", + "sizeleft":"419 MB", + "status":"Queued", + "timeleft":"86:01:55", + "unpackopts":"3", + "verbosity":"" + }, + { + "avg_age":"580d", + "cat":"tv", + "eta":"01:45 PM Mon 23 Jan", + "filename":"My Name Is Earl - 3x14-3x15 - I Won't Die With a Little Help from My Friends (1) + I Won't Die With a Little Help from My Friend [Bluray720p]", + "index":1, + "mb":"419.23", + "mbleft":"419.23", + "missing":0, + "msgid":5657628, + "nzo_id":"SABnzbd_nzo_dgrzts", + "percentage":"0", + "priority":"Normal", + "script":"None", + "size":"419 MB", + "sizeleft":"419 MB", + "status":"Queued", + "timeleft":"86:01:55", + "unpackopts":"3", + "verbosity":"" + }, + { + "status":"Paused", + "index":1, + "eta":"unknown", + "missing":0, + "avg_age":"1d", + "script":"None", + "msgid":"", + "verbosity":"", + "mb":"546.13", + "sizeleft":"546 MB", + "filename":"DUPLICATE / The Big Bang Theory - 5x13 - The Recombination Hypothesis [HDTV] [Proper]", + "priority":"NotReal", + "cat":"tv", + "mbleft":"546.13", + "timeleft":"0:00:00", + "percentage":"0", + "nzo_id":"SABnzbd_nzo_vayub5", + "unpackopts":"3", + "size":"546 MB" + } + ], + "speed":"2 K", + "speedlimit":"2", + "start":0, + "status":"Downloading", + "timeleft":"86:01:55", + "uptime":"2d", + "version":"0.6.9", + "webdir":"C:\\Tools\\SABnzbd\\interfaces\\Classic\\templates" + } +} \ No newline at end of file diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 74cac4081..c4938453d 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -206,6 +206,9 @@ Always + + Always + Always diff --git a/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/SabProviderTests/QueueFixture.cs b/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/SabProviderTests/QueueFixture.cs index 32c6c80d2..95445c30e 100644 --- a/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/SabProviderTests/QueueFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/SabProviderTests/QueueFixture.cs @@ -9,6 +9,7 @@ using Moq; using NUnit.Framework; using NzbDrone.Common; using NzbDrone.Core.Model; +using NzbDrone.Core.Model.Sabnzbd; using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Providers.DownloadClients; using NzbDrone.Core.Repository; @@ -42,7 +43,6 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.SabProviderTests fakeConfig.SetupGet(c => c.SabTvCategory).Returns(cat); } - private void WithFullQueue() { Mocker.GetMock() @@ -69,6 +69,16 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.SabProviderTests .Setup(s => s.DownloadString(It.IsAny())).Returns(File.ReadAllText(@".\Files\JsonError.txt")); } + private void WithUnknownPriorityQueue() + { + Mocker.GetMock() + .Setup( + s => + s.DownloadString( + "http://192.168.5.55:2222/api?mode=queue&output=json&start=0&limit=0&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass")) + .Returns(File.ReadAllText(@".\Files\QueueUnknownPriority.txt")); + } + [Test] public void GetQueue_should_return_an_empty_list_when_the_queue_is_empty() { @@ -97,6 +107,17 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.SabProviderTests result.Should().HaveCount(7); } + [Test] + public void GetQueue_should_return_a_list_with_items_even_when_priority_is_non_standard() + { + WithUnknownPriorityQueue(); + + var result = Mocker.Resolve().GetQueue(); + + result.Should().HaveCount(7); + result.Should().OnlyContain(i => i.Priority == SabPriorityType.Normal); + } + [Test] public void is_in_queue_should_find_if_exact_episode_is_in_queue() { diff --git a/NzbDrone.Core/Helpers/SabnzbdPriorityTypeConverter.cs b/NzbDrone.Core/Helpers/SabnzbdPriorityTypeConverter.cs new file mode 100644 index 000000000..40b157e2d --- /dev/null +++ b/NzbDrone.Core/Helpers/SabnzbdPriorityTypeConverter.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Newtonsoft.Json; +using NzbDrone.Core.Model.Sabnzbd; + +namespace NzbDrone.Core.Helpers +{ + public class SabnzbdPriorityTypeConverter : JsonConverter + { + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + var priorityType = (SabPriorityType)value; + writer.WriteValue(priorityType.ToString()); + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + var queuePriority = reader.Value.ToString(); + + SabPriorityType output; + Enum.TryParse(queuePriority, out output); + + return output; + } + + public override bool CanConvert(Type objectType) + { + return objectType == typeof(SabPriorityType); + } + } +} diff --git a/NzbDrone.Core/Model/Sabnzbd/SabQueueItem.cs b/NzbDrone.Core/Model/Sabnzbd/SabQueueItem.cs index b8e61fee5..fb895acb4 100644 --- a/NzbDrone.Core/Model/Sabnzbd/SabQueueItem.cs +++ b/NzbDrone.Core/Model/Sabnzbd/SabQueueItem.cs @@ -31,6 +31,7 @@ namespace NzbDrone.Core.Model.Sabnzbd } } + [JsonConverter(typeof(SabnzbdPriorityTypeConverter))] public SabPriorityType Priority { get; set; } [JsonProperty(PropertyName = "cat")] diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index d77e6da71..3f3ce06b8 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -243,6 +243,7 @@ +