Fixed broken test, drop folder prefix uses regex instead of prefix now.
This commit is contained in:
parent
1b2af8ea1b
commit
35e44284c0
|
@ -91,7 +91,6 @@
|
||||||
<Compile Include="JobTests\BacklogSearchJobTest.cs" />
|
<Compile Include="JobTests\BacklogSearchJobTest.cs" />
|
||||||
<Compile Include="JobTests\BannerDownloadJobTest.cs" />
|
<Compile Include="JobTests\BannerDownloadJobTest.cs" />
|
||||||
<Compile Include="ProviderTests\ConfigFileProviderTest.cs" />
|
<Compile Include="ProviderTests\ConfigFileProviderTest.cs" />
|
||||||
<Compile Include="Framework\AutoMoq\TestBaseTests.cs" />
|
|
||||||
<Compile Include="ProviderTests\DiskProviderTests\ExtractArchiveFixture.cs" />
|
<Compile Include="ProviderTests\DiskProviderTests\ExtractArchiveFixture.cs" />
|
||||||
<Compile Include="ProviderTests\PostDownloadProviderTest.cs" />
|
<Compile Include="ProviderTests\PostDownloadProviderTest.cs" />
|
||||||
<Compile Include="JobTests\SearchJobTest.cs" />
|
<Compile Include="JobTests\SearchJobTest.cs" />
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
public class DiskScanProviderTest : TestBase
|
public class DiskScanProviderTest : TestBase
|
||||||
{
|
{
|
||||||
[Test]
|
[Test]
|
||||||
public void scan_series_should_update_last_scan_date()
|
public void scan_series_should_update_the_last_scan_date()
|
||||||
{
|
{
|
||||||
|
|
||||||
var mocker = new AutoMoqer();
|
var mocker = new AutoMoqer();
|
||||||
|
@ -26,6 +26,8 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
.Setup(c => c.GetEpisodeBySeries(It.IsAny<long>()))
|
.Setup(c => c.GetEpisodeBySeries(It.IsAny<long>()))
|
||||||
.Returns(new List<Episode> { new Episode() });
|
.Returns(new List<Episode> { new Episode() });
|
||||||
|
|
||||||
|
mocker.GetMock<DiskProvider>().Setup(c => c.FolderExists(It.IsAny<string>())).Returns(true);
|
||||||
|
|
||||||
|
|
||||||
mocker.GetMock<MediaFileProvider>()
|
mocker.GetMock<MediaFileProvider>()
|
||||||
.Setup(c => c.GetSeriesFiles(It.IsAny<int>()))
|
.Setup(c => c.GetSeriesFiles(It.IsAny<int>()))
|
||||||
|
|
|
@ -82,9 +82,13 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
|
|
||||||
mocker.GetMock<MediaFileProvider>()
|
mocker.GetMock<MediaFileProvider>()
|
||||||
.Setup(e => e.RepairLinks()).Returns(0);
|
.Setup(e => e.RepairLinks()).Returns(0);
|
||||||
|
|
||||||
mocker.GetMock<MediaFileProvider>()
|
mocker.GetMock<MediaFileProvider>()
|
||||||
.Setup(e => e.DeleteOrphaned()).Returns(0);
|
.Setup(e => e.DeleteOrphaned()).Returns(0);
|
||||||
|
|
||||||
|
mocker.GetMock<DiskProvider>()
|
||||||
|
.Setup(c => c.FolderExists(It.IsAny<string>()))
|
||||||
|
.Returns(true);
|
||||||
|
|
||||||
var series = Builder<Series>.CreateNew()
|
var series = Builder<Series>.CreateNew()
|
||||||
.With(s => s.SeriesId = 12).Build();
|
.With(s => s.SeriesId = 12).Build();
|
||||||
|
@ -127,7 +131,7 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
result.Should().HaveSameCount(episodes);
|
result.Should().HaveSameCount(episodes);
|
||||||
result.Should().OnlyContain(e => e.EpisodeFileId == 0);
|
result.Should().OnlyContain(e => e.EpisodeFileId == 0);
|
||||||
removedLinks.Should().Be(10);
|
removedLinks.Should().Be(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void DeleteOrphanedEpisodeFiles()
|
public void DeleteOrphanedEpisodeFiles()
|
||||||
|
|
|
@ -54,7 +54,7 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
s => s.SetPostDownloadStatus(expectedEpisodesNumbers, postDownloadStatus)).Verifiable();
|
s => s.SetPostDownloadStatus(expectedEpisodesNumbers, postDownloadStatus)).Verifiable();
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
mocker.Resolve<PostDownloadProvider>().ProcessFailedOrUnpackingDownload(new DirectoryInfo(Path.Combine(Directory.GetCurrentDirectory(), folderName)),postDownloadStatus);
|
mocker.Resolve<PostDownloadProvider>().ProcessFailedOrUnpackingDownload(new DirectoryInfo(Path.Combine(Directory.GetCurrentDirectory(), folderName)), postDownloadStatus);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
mocker.GetMock<EpisodeProvider>().Verify(c => c.SetPostDownloadStatus(expectedEpisodesNumbers, postDownloadStatus), Times.Once());
|
mocker.GetMock<EpisodeProvider>().Verify(c => c.SetPostDownloadStatus(expectedEpisodesNumbers, postDownloadStatus), Times.Once());
|
||||||
|
@ -116,26 +116,6 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
mocker.VerifyAllMocks();
|
mocker.VerifyAllMocks();
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestCase(PostDownloadStatusType.Unpacking, 8)]
|
|
||||||
[TestCase(PostDownloadStatusType.Failed, 8)]
|
|
||||||
[TestCase(PostDownloadStatusType.InvalidSeries, 24)]
|
|
||||||
[TestCase(PostDownloadStatusType.ParseError, 21)]
|
|
||||||
[TestCase(PostDownloadStatusType.Unknown, 10)]
|
|
||||||
[TestCase(PostDownloadStatusType.Processed, 0)]
|
|
||||||
[TestCase(PostDownloadStatusType.InvalidEpisode, 25)]
|
|
||||||
[TestCase(PostDownloadStatusType.NoError, 0)]
|
|
||||||
public void GetPrefixLength(PostDownloadStatusType postDownloadStatus, int expected)
|
|
||||||
{
|
|
||||||
//Setup
|
|
||||||
var mocker = new AutoMoqer();
|
|
||||||
|
|
||||||
//Act
|
|
||||||
var result = mocker.Resolve<PostDownloadProvider>().GetPrefixLength(postDownloadStatus);
|
|
||||||
|
|
||||||
//Assert
|
|
||||||
result.Should().Be(expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void ProcessDownload_InvalidSeries()
|
public void ProcessDownload_InvalidSeries()
|
||||||
{
|
{
|
||||||
|
@ -346,5 +326,14 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
//Assert
|
//Assert
|
||||||
result.Should().Be(expectedResult);
|
result.Should().Be(expectedResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestCase("_NzbDrone_ParseError_The Office (US) - S01E01 - Episode Title", "The Office (US) - S01E01 - Episode Title")]
|
||||||
|
[TestCase("_Status_The Office (US) - S01E01 - Episode Title", "The Office (US) - S01E01 - Episode Title")]
|
||||||
|
[TestCase("The Office (US) - S01E01 - Episode Title", "The Office (US) - S01E01 - Episode Title")]
|
||||||
|
[TestCase("_The Office (US) - S01E01 - Episode Title", "_The Office (US) - S01E01 - Episode Title")]
|
||||||
|
public void RemoveStatus_should_remove_status_string_from_folder_name(string folderName, string cleanFolderName)
|
||||||
|
{
|
||||||
|
PostDownloadProvider.RemoveStatusFromFolderName(folderName).Should().Be(cleanFolderName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,44 +2,14 @@
|
||||||
{
|
{
|
||||||
public enum PostDownloadStatusType
|
public enum PostDownloadStatusType
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Unknown (Default)
|
|
||||||
/// </summary>
|
|
||||||
Unknown = 0,
|
Unknown = 0,
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Unpacking
|
|
||||||
/// </summary>
|
|
||||||
Unpacking = 1,
|
Unpacking = 1,
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Failed
|
|
||||||
/// </summary>
|
|
||||||
Failed = 2,
|
Failed = 2,
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Processed
|
|
||||||
/// </summary>
|
|
||||||
Processed = 3,
|
Processed = 3,
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// InvalidSeries
|
|
||||||
/// </summary>
|
|
||||||
InvalidSeries = 4,
|
InvalidSeries = 4,
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// ParseError
|
|
||||||
/// </summary>
|
|
||||||
ParseError = 5,
|
ParseError = 5,
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// InvalidEpisode
|
|
||||||
/// </summary>
|
|
||||||
InvalidEpisode = 6,
|
InvalidEpisode = 6,
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// NoError
|
|
||||||
/// </summary>
|
|
||||||
NoError = 7,
|
NoError = 7,
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -394,17 +394,6 @@ namespace NzbDrone.Core
|
||||||
return info.FullName.Trim('/', '\\', ' ');
|
return info.FullName.Trim('/', '\\', ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string UppercaseFirst(string s)
|
|
||||||
{
|
|
||||||
// Check for empty string.
|
|
||||||
if (string.IsNullOrEmpty(s))
|
|
||||||
{
|
|
||||||
return string.Empty;
|
|
||||||
}
|
|
||||||
// Return char and concat substring.
|
|
||||||
return char.ToUpper(s[0]) + s.Substring(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static long GetReportSize(string sizeString)
|
public static long GetReportSize(string sizeString)
|
||||||
{
|
{
|
||||||
var match = ReportSizeRegex.Matches(sizeString);
|
var match = ReportSizeRegex.Matches(sizeString);
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
using System;
|
using Ninject;
|
||||||
using System.IO;
|
|
||||||
using Ninject;
|
|
||||||
using NLog;
|
|
||||||
using NzbDrone.Core.Model;
|
|
||||||
using NzbDrone.Core.Model.Notification;
|
using NzbDrone.Core.Model.Notification;
|
||||||
using NzbDrone.Core.Providers.Core;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Providers.Jobs
|
namespace NzbDrone.Core.Providers.Jobs
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using NLog;
|
using NLog;
|
||||||
using Ninject;
|
using Ninject;
|
||||||
using NzbDrone.Core.Model;
|
using NzbDrone.Core.Model;
|
||||||
|
@ -21,6 +22,8 @@ namespace NzbDrone.Core.Providers
|
||||||
private readonly EpisodeProvider _episodeProvider;
|
private readonly EpisodeProvider _episodeProvider;
|
||||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
|
private static readonly Regex StatusRegex = new Regex(@"^_[\w_]*_", RegexOptions.Compiled);
|
||||||
|
|
||||||
private static readonly List<PostDownloadInfoModel> InfoList = new List<PostDownloadInfoModel>();
|
private static readonly List<PostDownloadInfoModel> InfoList = new List<PostDownloadInfoModel>();
|
||||||
|
|
||||||
[Inject]
|
[Inject]
|
||||||
|
@ -69,6 +72,8 @@ namespace NzbDrone.Core.Providers
|
||||||
|
|
||||||
var folderStatus = GetPostDownloadStatusForFolder(subfolderInfo.Name);
|
var folderStatus = GetPostDownloadStatusForFolder(subfolderInfo.Name);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (folderStatus == PostDownloadStatusType.Unpacking)
|
if (folderStatus == PostDownloadStatusType.Unpacking)
|
||||||
{
|
{
|
||||||
ProcessFailedOrUnpackingDownload(subfolderInfo, PostDownloadStatusType.Unpacking);
|
ProcessFailedOrUnpackingDownload(subfolderInfo, PostDownloadStatusType.Unpacking);
|
||||||
|
@ -86,8 +91,7 @@ namespace NzbDrone.Core.Providers
|
||||||
if (folderStatus != PostDownloadStatusType.NoError)
|
if (folderStatus != PostDownloadStatusType.NoError)
|
||||||
{
|
{
|
||||||
//Retry processing on the download
|
//Retry processing on the download
|
||||||
ReProcessDownload(new PostDownloadInfoModel{ Name = subfolderInfo.FullName, Status = folderStatus });
|
ReProcessDownload(new PostDownloadInfoModel { Name = subfolderInfo.FullName, Status = folderStatus });
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +169,7 @@ namespace NzbDrone.Core.Providers
|
||||||
}
|
}
|
||||||
|
|
||||||
//Remove the error prefix before processing
|
//Remove the error prefix before processing
|
||||||
var parseResult = Parser.ParseTitle(directoryInfo.Name.Substring(GetPrefixLength(postDownloadStatus)));
|
var parseResult = Parser.ParseTitle(RemoveStatusFromFolderName(directoryInfo.Name));
|
||||||
|
|
||||||
parseResult.Series = _seriesProvider.FindSeries(parseResult.CleanTitle);
|
parseResult.Series = _seriesProvider.FindSeries(parseResult.CleanTitle);
|
||||||
|
|
||||||
|
@ -215,25 +219,6 @@ namespace NzbDrone.Core.Providers
|
||||||
ProcessDownload(directoryInfo);
|
ProcessDownload(directoryInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetPrefixLength(PostDownloadStatusType postDownloadStatus)
|
|
||||||
{
|
|
||||||
//_UNPACK_ & _FAILED_ have a length of 8
|
|
||||||
if (postDownloadStatus == PostDownloadStatusType.Unpacking || postDownloadStatus == PostDownloadStatusType.Failed)
|
|
||||||
return 8;
|
|
||||||
|
|
||||||
if (postDownloadStatus == PostDownloadStatusType.Unknown)
|
|
||||||
return 10;
|
|
||||||
|
|
||||||
if (postDownloadStatus == PostDownloadStatusType.Processed)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (postDownloadStatus == PostDownloadStatusType.NoError)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
//Return the 11 (_NzbDrone_) + trailing underscore + postDownloadStatus length
|
|
||||||
return 11 + postDownloadStatus.ToString().Length;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Add(PostDownloadInfoModel model)
|
public void Add(PostDownloadInfoModel model)
|
||||||
{
|
{
|
||||||
InfoList.Add(model);
|
InfoList.Add(model);
|
||||||
|
@ -278,7 +263,7 @@ namespace NzbDrone.Core.Providers
|
||||||
var error = String.Format("_NzbDrone_{0}_", postDownloadStatus.ToString());
|
var error = String.Format("_NzbDrone_{0}_", postDownloadStatus.ToString());
|
||||||
|
|
||||||
if (existingError != PostDownloadStatusType.NoError)
|
if (existingError != PostDownloadStatusType.NoError)
|
||||||
newFolderName = directoryInfo.Name.Substring(GetPrefixLength(existingError));
|
newFolderName = RemoveStatusFromFolderName(directoryInfo.Name);
|
||||||
|
|
||||||
if (postDownloadStatus == PostDownloadStatusType.Unknown)
|
if (postDownloadStatus == PostDownloadStatusType.Unknown)
|
||||||
error = "_NzbDrone_";
|
error = "_NzbDrone_";
|
||||||
|
@ -294,5 +279,10 @@ namespace NzbDrone.Core.Providers
|
||||||
|
|
||||||
return Path.Combine(parent, newName);
|
return Path.Combine(parent, newName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string RemoveStatusFromFolderName(string folderName)
|
||||||
|
{
|
||||||
|
return StatusRegex.Replace(folderName, string.Empty);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue