Fixed: Don't mark releases as imported unless at least one file is imported

This commit is contained in:
Mark McDowall 2014-09-03 17:57:27 -07:00
parent 20894b40cf
commit b638e09f24
8 changed files with 143 additions and 23 deletions

View File

@ -449,7 +449,39 @@ namespace NzbDrone.Core.Test.Download
}
[Test]
public void should_not_mark_as_successful_if_no_files_were_imported()
public void should_not_mark_as_imported_if_all_files_were_rejected()
{
GivenCompletedDownloadClientHistory();
var history = Builder<History.History>.CreateListOfSize(1)
.Build()
.ToList();
GivenGrabbedHistory(history);
GivenNoImportedHistory();
Mocker.GetMock<IDownloadedEpisodesImportService>()
.Setup(v => v.ProcessFolder(It.IsAny<DirectoryInfo>(), It.IsAny<DownloadClientItem>()))
.Returns(new List<ImportResult>
{
new ImportResult(
new ImportDecision(new LocalEpisode() {Path = @"C:\TestPath\Droned.S01E01.mkv"}, "Rejected!"),
"Test Failure")
});
history.First().Data.Add("downloadClient", "SabnzbdClient");
history.First().Data.Add("downloadClientId", _completed.First().DownloadClientId);
Subject.Execute(new CheckForFinishedDownloadCommand());
Mocker.GetMock<IDiskProvider>()
.Verify(c => c.DeleteFolder(It.IsAny<string>(), true), Times.Never());
ExceptionVerification.ExpectedErrors(1);
}
[Test]
public void should_not_mark_as_imported_if_all_files_were_skipped()
{
GivenCompletedDownloadClientHistory();
@ -479,5 +511,38 @@ namespace NzbDrone.Core.Test.Download
ExceptionVerification.ExpectedErrors(1);
}
[Test]
public void should_not_mark_as_imported_if_some_files_were_skipped()
{
GivenCompletedDownloadClientHistory();
var history = Builder<History.History>.CreateListOfSize(1)
.Build()
.ToList();
GivenGrabbedHistory(history);
GivenNoImportedHistory();
Mocker.GetMock<IDownloadedEpisodesImportService>()
.Setup(v => v.ProcessFolder(It.IsAny<DirectoryInfo>(), It.IsAny<DownloadClientItem>()))
.Returns(new List<ImportResult>
{
new ImportResult(new ImportDecision(new LocalEpisode() {Path = @"C:\TestPath\Droned.S01E01.mkv"})),
new ImportResult(
new ImportDecision(new LocalEpisode() {Path = @"C:\TestPath\Droned.S01E01.mkv"}),
"Test Failure")
});
history.First().Data.Add("downloadClient", "SabnzbdClient");
history.First().Data.Add("downloadClientId", _completed.First().DownloadClientId);
Subject.Execute(new CheckForFinishedDownloadCommand());
Mocker.GetMock<IDiskProvider>()
.Verify(c => c.DeleteFolder(It.IsAny<string>(), true), Times.Never());
ExceptionVerification.ExpectedErrors(1);
}
}
}

View File

@ -81,7 +81,6 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport
.Setup(c => c.GetLocalEpisode(It.IsAny<String>(), It.IsAny<Series>(), It.IsAny<Boolean>()))
.Returns(_localEpisode);
Mocker.GetMock<IMediaFileService>()
.Setup(c => c.FilterExistingFiles(_videoFiles, It.IsAny<Series>()))
.Returns(_videoFiles);
@ -147,11 +146,12 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport
}
[Test]
public void failed_parse_shouldnt_blowup_the_process()
public void should_not_blowup_the_process_due_to_failed_parse()
{
GivenSpecifications(_pass1);
Mocker.GetMock<IParsingService>().Setup(c => c.GetLocalEpisode(It.IsAny<String>(), It.IsAny<Series>(), It.IsAny<Boolean>()))
Mocker.GetMock<IParsingService>()
.Setup(c => c.GetLocalEpisode(It.IsAny<String>(), It.IsAny<Series>(), It.IsAny<Boolean>()))
.Throws<TestException>();
_videoFiles = new List<String>
@ -161,7 +161,6 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport
"The.Office.S03E115.DVDRip.XviD-OSiTV"
};
Mocker.GetMock<IMediaFileService>()
.Setup(c => c.FilterExistingFiles(_videoFiles, It.IsAny<Series>()))
.Returns(_videoFiles);
@ -206,5 +205,31 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport
result.Single().LocalEpisode.Quality.Should().Be(expectedQuality);
}
[Test]
public void should_not_throw_if_episodes_are_not_found()
{
GivenSpecifications(_pass1);
Mocker.GetMock<IParsingService>()
.Setup(c => c.GetLocalEpisode(It.IsAny<String>(), It.IsAny<Series>(), It.IsAny<Boolean>()))
.Throws(new EpisodeNotFoundException("Episode not found"));
_videoFiles = new List<String>
{
"The.Office.S03E115.DVDRip.XviD-OSiTV",
"The.Office.S03E115.DVDRip.XviD-OSiTV",
"The.Office.S03E115.DVDRip.XviD-OSiTV"
};
Mocker.GetMock<IMediaFileService>()
.Setup(c => c.FilterExistingFiles(_videoFiles, It.IsAny<Series>()))
.Returns(_videoFiles);
Subject.GetImportDecisions(_videoFiles, _series, false);
Mocker.GetMock<IParsingService>()
.Verify(c => c.GetLocalEpisode(It.IsAny<String>(), It.IsAny<Series>(), It.IsAny<Boolean>()), Times.Exactly(_videoFiles.Count));
}
}
}

View File

@ -187,7 +187,7 @@ namespace NzbDrone.Core.Download
{
UpdateStatusMessage(trackedDownload, LogLevel.Error, "No files found are eligible for import in {0}", trackedDownload.DownloadItem.OutputPath);
}
else if (importResults.All(v => v.Result == ImportResultType.Imported || v.Result == ImportResultType.Rejected))
else if (importResults.Any(v => v.Result == ImportResultType.Imported) && importResults.All(v => v.Result == ImportResultType.Imported || v.Result == ImportResultType.Rejected))
{
UpdateStatusMessage(trackedDownload, LogLevel.Info, "Imported {0} files.", importResults.Count(v => v.Result == ImportResultType.Imported));

View File

@ -63,7 +63,9 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport
if (parsedEpisode != null)
{
if (quality != null && new QualityModelComparer(parsedEpisode.Series.Profile).Compare(quality, parsedEpisode.Quality) > 0)
if (quality != null &&
new QualityModelComparer(parsedEpisode.Series.Profile).Compare(quality,
parsedEpisode.Quality) > 0)
{
_logger.Debug("Using quality from folder: {0}", quality);
parsedEpisode.Quality = quality;
@ -85,9 +87,16 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport
decision = new ImportDecision(parsedEpisode, "Unable to parse file");
}
}
catch (EpisodeNotFoundException e)
{
var parsedEpisode = new LocalEpisode();
parsedEpisode.Path = file;
decision = new ImportDecision(parsedEpisode, e.Message);
}
catch (Exception e)
{
_logger.ErrorException("Couldn't import file." + file, e);
_logger.ErrorException("Couldn't import file. " + file, e);
}
if (decision != null)

View File

@ -58,12 +58,14 @@ namespace NzbDrone.Core.Metadata
if (metadata.Type == MetadataType.EpisodeImage ||
metadata.Type == MetadataType.EpisodeMetadata)
{
try
{
var localEpisode = _parsingService.GetLocalEpisode(possibleMetadataFile, message.Series, false);
if (localEpisode == null)
{
_logger.Debug("Cannot find related episodes for: {0}", possibleMetadataFile);
_logger.Debug("Unable to parse meta data file: {0}", possibleMetadataFile);
break;
}
@ -74,6 +76,13 @@ namespace NzbDrone.Core.Metadata
}
metadata.EpisodeFileId = localEpisode.Episodes.First().EpisodeFileId;
}
catch (EpisodeNotFoundException e)
{
_logger.Debug("Cannot find related episodes for: {0}", possibleMetadataFile);
continue;
}
}
metadataFiles.Add(metadata);

View File

@ -652,6 +652,7 @@
<Compile Include="Organizer\NamingConfig.cs" />
<Compile Include="Organizer\NamingConfigService.cs" />
<Compile Include="Organizer\SampleResult.cs" />
<Compile Include="Parser\EpisodeNotFoundException.cs" />
<Compile Include="Parser\InvalidDateException.cs" />
<Compile Include="Parser\Language.cs" />
<Compile Include="Parser\Model\LocalEpisode.cs" />

View File

@ -0,0 +1,11 @@
using NzbDrone.Common.Exceptions;
namespace NzbDrone.Core.Parser
{
public class EpisodeNotFoundException : NzbDroneException
{
public EpisodeNotFoundException(string message, params object[] args) : base(message, args)
{
}
}
}

View File

@ -62,10 +62,10 @@ namespace NzbDrone.Core.Parser
var episodes = GetEpisodes(parsedEpisodeInfo, series, sceneSource);
if (!episodes.Any())
if (episodes.Empty())
{
_logger.Debug("No matching episodes found for: {0}", parsedEpisodeInfo);
return null;
throw new EpisodeNotFoundException("Unable to find episodes for file: {0}", parsedEpisodeInfo);
}
return new LocalEpisode