Download Handling, Clean Up Drone Folder Leftovers

This commit is contained in:
Qstick
2017-09-17 23:00:37 -04:00
parent 9f689c0233
commit 405e7f981d
24 changed files with 467 additions and 754 deletions
@@ -35,12 +35,12 @@ namespace NzbDrone.Core.Test.Download
.With(h => h.Title = "Drone.S01E01.HDTV")
.Build();
var remoteEpisode = BuildRemoteEpisode();
var remoteAlbum = BuildRemoteAlbum();
_trackedDownload = Builder<TrackedDownload>.CreateNew()
.With(c => c.State = TrackedDownloadStage.Downloading)
.With(c => c.DownloadItem = completed)
.With(c => c.RemoteEpisode = remoteEpisode)
.With(c => c.RemoteAlbum = remoteAlbum)
.Build();
@@ -57,17 +57,17 @@ namespace NzbDrone.Core.Test.Download
.Returns(new History.History());
Mocker.GetMock<IParsingService>()
.Setup(s => s.GetSeries("Drone.S01E01.HDTV"))
.Returns(remoteEpisode.Series);
.Setup(s => s.GetArtist("Drone.S01E01.HDTV"))
.Returns(remoteAlbum.Artist);
}
private RemoteEpisode BuildRemoteEpisode()
private RemoteAlbum BuildRemoteAlbum()
{
return new RemoteEpisode
return new RemoteAlbum
{
Series = new Series(),
Episodes = new List<Episode> { new Episode { Id = 1 } }
Artist = new Artist(),
Albums = new List<Album> { new Album { Id = 1 } }
};
}
@@ -81,8 +81,8 @@ namespace NzbDrone.Core.Test.Download
private void GivenSuccessfulImport()
{
Mocker.GetMock<IDownloadedEpisodesImportService>()
.Setup(v => v.ProcessPath(It.IsAny<string>(), It.IsAny<ImportMode>(), It.IsAny<Series>(), It.IsAny<DownloadClientItem>()))
Mocker.GetMock<IDownloadedTracksImportService>()
.Setup(v => v.ProcessPath(It.IsAny<string>(), It.IsAny<ImportMode>(), It.IsAny<Artist>(), It.IsAny<DownloadClientItem>()))
.Returns(new List<ImportResult>
{
new ImportResult(new ImportDecision(new LocalTrack() { Path = @"C:\TestPath\Droned.S01E01.mkv" }))
@@ -99,19 +99,19 @@ namespace NzbDrone.Core.Test.Download
.Returns(new History.History() { SourceTitle = "Droned S01E01" });
Mocker.GetMock<IParsingService>()
.Setup(s => s.GetSeries(It.IsAny<string>()))
.Returns((Series)null);
.Setup(s => s.GetArtist(It.IsAny<string>()))
.Returns((Artist)null);
Mocker.GetMock<IParsingService>()
.Setup(s => s.GetSeries("Droned S01E01"))
.Returns(BuildRemoteEpisode().Series);
.Setup(s => s.GetArtist("Droned S01E01"))
.Returns(BuildRemoteAlbum().Artist);
}
private void GivenSeriesMatch()
private void GivenArtistMatch()
{
Mocker.GetMock<IParsingService>()
.Setup(s => s.GetSeries(It.IsAny<string>()))
.Returns(_trackedDownload.RemoteEpisode.Series);
.Setup(s => s.GetArtist(It.IsAny<string>()))
.Returns(_trackedDownload.RemoteAlbum.Artist);
}
[TestCase(DownloadItemStatus.Downloading)]
@@ -144,7 +144,7 @@ namespace NzbDrone.Core.Test.Download
{
_trackedDownload.DownloadItem.Category = "tv";
GivenNoGrabbedHistory();
GivenSeriesMatch();
GivenArtistMatch();
GivenSuccessfulImport();
Subject.Process(_trackedDownload);
@@ -152,20 +152,6 @@ namespace NzbDrone.Core.Test.Download
AssertCompletedDownload();
}
[Test]
public void should_not_process_if_storage_directory_in_drone_factory()
{
Mocker.GetMock<IConfigService>()
.SetupGet(v => v.DownloadedAlbumsFolder)
.Returns(@"C:\DropFolder".AsOsAgnostic());
_trackedDownload.DownloadItem.OutputPath = new OsPath(@"C:\DropFolder\SomeOtherFolder".AsOsAgnostic());
Subject.Process(_trackedDownload);
AssertNoAttemptedImport();
}
[Test]
public void should_not_process_if_output_path_is_empty()
{
@@ -179,8 +165,8 @@ namespace NzbDrone.Core.Test.Download
[Test]
public void should_mark_as_imported_if_all_episodes_were_imported()
{
Mocker.GetMock<IDownloadedEpisodesImportService>()
.Setup(v => v.ProcessPath(It.IsAny<string>(), It.IsAny<ImportMode>(), It.IsAny<Series>(), It.IsAny<DownloadClientItem>()))
Mocker.GetMock<IDownloadedTracksImportService>()
.Setup(v => v.ProcessPath(It.IsAny<string>(), It.IsAny<ImportMode>(), It.IsAny<Artist>(), It.IsAny<DownloadClientItem>()))
.Returns(new List<ImportResult>
{
new ImportResult(
@@ -200,8 +186,8 @@ namespace NzbDrone.Core.Test.Download
[Test]
public void should_not_mark_as_imported_if_all_files_were_rejected()
{
Mocker.GetMock<IDownloadedEpisodesImportService>()
.Setup(v => v.ProcessPath(It.IsAny<string>(), It.IsAny<ImportMode>(), It.IsAny<Series>(), It.IsAny<DownloadClientItem>()))
Mocker.GetMock<IDownloadedTracksImportService>()
.Setup(v => v.ProcessPath(It.IsAny<string>(), It.IsAny<ImportMode>(), It.IsAny<Artist>(), It.IsAny<DownloadClientItem>()))
.Returns(new List<ImportResult>
{
new ImportResult(
@@ -224,8 +210,8 @@ namespace NzbDrone.Core.Test.Download
[Test]
public void should_not_mark_as_imported_if_no_episodes_were_parsed()
{
Mocker.GetMock<IDownloadedEpisodesImportService>()
.Setup(v => v.ProcessPath(It.IsAny<string>(), It.IsAny<ImportMode>(), It.IsAny<Series>(), It.IsAny<DownloadClientItem>()))
Mocker.GetMock<IDownloadedTracksImportService>()
.Setup(v => v.ProcessPath(It.IsAny<string>(), It.IsAny<ImportMode>(), It.IsAny<Artist>(), It.IsAny<DownloadClientItem>()))
.Returns(new List<ImportResult>
{
new ImportResult(
@@ -237,7 +223,7 @@ namespace NzbDrone.Core.Test.Download
new LocalTrack {Path = @"C:\TestPath\Droned.S01E02.mkv"},new Rejection("Rejected!")), "Test Failure")
});
_trackedDownload.RemoteEpisode.Episodes.Clear();
_trackedDownload.RemoteAlbum.Albums.Clear();
Subject.Process(_trackedDownload);
@@ -247,8 +233,8 @@ namespace NzbDrone.Core.Test.Download
[Test]
public void should_not_mark_as_imported_if_all_files_were_skipped()
{
Mocker.GetMock<IDownloadedEpisodesImportService>()
.Setup(v => v.ProcessPath(It.IsAny<string>(), It.IsAny<ImportMode>(), It.IsAny<Series>(), It.IsAny<DownloadClientItem>()))
Mocker.GetMock<IDownloadedTracksImportService>()
.Setup(v => v.ProcessPath(It.IsAny<string>(), It.IsAny<ImportMode>(), It.IsAny<Artist>(), It.IsAny<DownloadClientItem>()))
.Returns(new List<ImportResult>
{
new ImportResult(new ImportDecision(new LocalTrack {Path = @"C:\TestPath\Droned.S01E01.mkv"}),"Test Failure"),
@@ -264,15 +250,15 @@ namespace NzbDrone.Core.Test.Download
[Test]
public void should_mark_as_imported_if_all_episodes_were_imported_but_extra_files_were_not()
{
GivenSeriesMatch();
GivenArtistMatch();
_trackedDownload.RemoteEpisode.Episodes = new List<Episode>
_trackedDownload.RemoteAlbum.Albums = new List<Album>
{
new Episode()
new Album()
};
Mocker.GetMock<IDownloadedEpisodesImportService>()
.Setup(v => v.ProcessPath(It.IsAny<string>(), It.IsAny<ImportMode>(), It.IsAny<Series>(), It.IsAny<DownloadClientItem>()))
Mocker.GetMock<IDownloadedTracksImportService>()
.Setup(v => v.ProcessPath(It.IsAny<string>(), It.IsAny<ImportMode>(), It.IsAny<Artist>(), It.IsAny<DownloadClientItem>()))
.Returns(new List<ImportResult>
{
new ImportResult(new ImportDecision(new LocalTrack {Path = @"C:\TestPath\Droned.S01E01.mkv"})),
@@ -287,15 +273,15 @@ namespace NzbDrone.Core.Test.Download
[Test]
public void should_mark_as_failed_if_some_of_episodes_were_not_imported()
{
_trackedDownload.RemoteEpisode.Episodes = new List<Episode>
_trackedDownload.RemoteAlbum.Albums = new List<Album>
{
new Episode(),
new Episode(),
new Episode()
new Album(),
new Album(),
new Album()
};
Mocker.GetMock<IDownloadedEpisodesImportService>()
.Setup(v => v.ProcessPath(It.IsAny<string>(), It.IsAny<ImportMode>(), It.IsAny<Series>(), It.IsAny<DownloadClientItem>()))
Mocker.GetMock<IDownloadedTracksImportService>()
.Setup(v => v.ProcessPath(It.IsAny<string>(), It.IsAny<ImportMode>(), It.IsAny<Artist>(), It.IsAny<DownloadClientItem>()))
.Returns(new List<ImportResult>
{
new ImportResult(new ImportDecision(new LocalTrack {Path = @"C:\TestPath\Droned.S01E01.mkv"})),
@@ -314,16 +300,16 @@ namespace NzbDrone.Core.Test.Download
{
GivenABadlyNamedDownload();
Mocker.GetMock<IDownloadedEpisodesImportService>()
.Setup(v => v.ProcessPath(It.IsAny<string>(), It.IsAny<ImportMode>(), It.IsAny<Series>(), It.IsAny<DownloadClientItem>()))
Mocker.GetMock<IDownloadedTracksImportService>()
.Setup(v => v.ProcessPath(It.IsAny<string>(), It.IsAny<ImportMode>(), It.IsAny<Artist>(), It.IsAny<DownloadClientItem>()))
.Returns(new List<ImportResult>
{
new ImportResult(new ImportDecision(new LocalTrack {Path = @"C:\TestPath\Droned.S01E01.mkv"}))
});
Mocker.GetMock<ISeriesService>()
.Setup(v => v.GetSeries(It.IsAny<int>()))
.Returns(BuildRemoteEpisode().Series);
Mocker.GetMock<IArtistService>()
.Setup(v => v.GetArtist(It.IsAny<int>()))
.Returns(BuildRemoteAlbum().Artist);
Subject.Process(_trackedDownload);
@@ -335,8 +321,8 @@ namespace NzbDrone.Core.Test.Download
{
GivenABadlyNamedDownload();
Mocker.GetMock<IDownloadedEpisodesImportService>()
.Setup(v => v.ProcessPath(It.IsAny<string>(), It.IsAny<ImportMode>(), It.IsAny<Series>(), It.IsAny<DownloadClientItem>()))
Mocker.GetMock<IDownloadedTracksImportService>()
.Setup(v => v.ProcessPath(It.IsAny<string>(), It.IsAny<ImportMode>(), It.IsAny<Artist>(), It.IsAny<DownloadClientItem>()))
.Returns(new List<ImportResult>
{
new ImportResult(new ImportDecision(new LocalTrack {Path = @"C:\TestPath\Droned.S01E01.mkv"}))
@@ -354,8 +340,8 @@ namespace NzbDrone.Core.Test.Download
public void should_not_import_when_there_is_a_title_mismatch()
{
Mocker.GetMock<IParsingService>()
.Setup(s => s.GetSeries("Drone.S01E01.HDTV"))
.Returns((Series)null);
.Setup(s => s.GetArtist("Drone.S01E01.HDTV"))
.Returns((Artist)null);
Subject.Process(_trackedDownload);
@@ -365,13 +351,13 @@ namespace NzbDrone.Core.Test.Download
[Test]
public void should_mark_as_import_title_mismatch_if_ignore_warnings_is_true()
{
_trackedDownload.RemoteEpisode.Episodes = new List<Episode>
_trackedDownload.RemoteAlbum.Albums = new List<Album>
{
new Episode()
new Album()
};
Mocker.GetMock<IDownloadedEpisodesImportService>()
.Setup(v => v.ProcessPath(It.IsAny<string>(), It.IsAny<ImportMode>(), It.IsAny<Series>(), It.IsAny<DownloadClientItem>()))
Mocker.GetMock<IDownloadedTracksImportService>()
.Setup(v => v.ProcessPath(It.IsAny<string>(), It.IsAny<ImportMode>(), It.IsAny<Artist>(), It.IsAny<DownloadClientItem>()))
.Returns(new List<ImportResult>
{
new ImportResult(new ImportDecision(new LocalTrack {Path = @"C:\TestPath\Droned.S01E01.mkv"}))
@@ -408,8 +394,8 @@ namespace NzbDrone.Core.Test.Download
private void AssertNoAttemptedImport()
{
Mocker.GetMock<IDownloadedEpisodesImportService>()
.Verify(v => v.ProcessPath(It.IsAny<string>(), It.IsAny<ImportMode>(), It.IsAny<Series>(), It.IsAny<DownloadClientItem>()), Times.Never());
Mocker.GetMock<IDownloadedTracksImportService>()
.Verify(v => v.ProcessPath(It.IsAny<string>(), It.IsAny<ImportMode>(), It.IsAny<Artist>(), It.IsAny<DownloadClientItem>()), Times.Never());
AssertNoCompletedDownload();
}
@@ -424,8 +410,8 @@ namespace NzbDrone.Core.Test.Download
private void AssertCompletedDownload()
{
Mocker.GetMock<IDownloadedEpisodesImportService>()
.Verify(v => v.ProcessPath(_trackedDownload.DownloadItem.OutputPath.FullPath, ImportMode.Auto, _trackedDownload.RemoteEpisode.Series, _trackedDownload.DownloadItem), Times.Once());
Mocker.GetMock<IDownloadedTracksImportService>()
.Verify(v => v.ProcessPath(_trackedDownload.DownloadItem.OutputPath.FullPath, ImportMode.Auto, _trackedDownload.RemoteAlbum.Artist, _trackedDownload.DownloadItem), Times.Once());
Mocker.GetMock<IEventAggregator>()
.Verify(v => v.PublishEvent(It.IsAny<DownloadCompletedEvent>()), Times.Once());
@@ -1,10 +1,9 @@
using System;
using System;
using System.IO;
using System.Net;
using Moq;
using NUnit.Framework;
using NzbDrone.Common.Http;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Download;
using NzbDrone.Core.Download.Clients.Pneumatic;
using NzbDrone.Core.Parser.Model;
@@ -19,9 +18,9 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests
private const string _nzbUrl = "http://www.nzbs.com/url";
private const string _title = "30.Rock.S01E05.hdtv.xvid-LoL";
private string _pneumaticFolder;
private string _sabDrop;
private string _strmFolder;
private string _nzbPath;
private RemoteAlbum _remoteEpisode;
private RemoteAlbum _remoteAlbum;
[SetUp]
public void Setup()
@@ -29,21 +28,20 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests
_pneumaticFolder = @"d:\nzb\pneumatic\".AsOsAgnostic();
_nzbPath = Path.Combine(_pneumaticFolder, _title + ".nzb").AsOsAgnostic();
_sabDrop = @"d:\unsorted tv\".AsOsAgnostic();
_strmFolder = @"d:\unsorted tv\".AsOsAgnostic();
Mocker.GetMock<IConfigService>().SetupGet(c => c.DownloadedAlbumsFolder).Returns(_sabDrop);
_remoteAlbum = new RemoteAlbum();
_remoteAlbum.Release = new ReleaseInfo();
_remoteAlbum.Release.Title = _title;
_remoteAlbum.Release.DownloadUrl = _nzbUrl;
_remoteEpisode = new RemoteAlbum();
_remoteEpisode.Release = new ReleaseInfo();
_remoteEpisode.Release.Title = _title;
_remoteEpisode.Release.DownloadUrl = _nzbUrl;
_remoteEpisode.ParsedAlbumInfo = new ParsedAlbumInfo();
_remoteAlbum.ParsedAlbumInfo = new ParsedAlbumInfo();
Subject.Definition = new DownloadClientDefinition();
Subject.Definition.Settings = new PneumaticSettings
{
NzbFolder = _pneumaticFolder
NzbFolder = _pneumaticFolder,
StrmFolder = _strmFolder
};
}
@@ -55,26 +53,25 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests
[Test]
public void should_download_file_if_it_doesnt_exist()
{
Subject.Download(_remoteEpisode);
Subject.Download(_remoteAlbum);
Mocker.GetMock<IHttpClient>().Verify(c => c.DownloadFile(_nzbUrl, _nzbPath), Times.Once());
}
[Test]
public void should_throw_on_failed_download()
{
WithFailedDownload();
Assert.Throws<WebException>(() => Subject.Download(_remoteEpisode));
Assert.Throws<WebException>(() => Subject.Download(_remoteAlbum));
}
[Test]
public void should_throw_if_full_season_download()
{
_remoteEpisode.Release.Title = "30 Rock - Season 1";
_remoteAlbum.Release.Title = "30 Rock - Season 1";
Assert.Throws<NotSupportedException>(() => Subject.Download(_remoteEpisode));
Assert.Throws<NotSupportedException>(() => Subject.Download(_remoteAlbum));
}
[Test]
@@ -88,9 +85,9 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests
{
var illegalTitle = "Saturday Night Live - S38E08 - Jeremy Renner/Maroon 5 [SDTV]";
var expectedFilename = Path.Combine(_pneumaticFolder, "Saturday Night Live - S38E08 - Jeremy Renner+Maroon 5 [SDTV].nzb");
_remoteEpisode.Release.Title = illegalTitle;
_remoteAlbum.Release.Title = illegalTitle;
Subject.Download(_remoteEpisode);
Subject.Download(_remoteAlbum);
Mocker.GetMock<IHttpClient>().Verify(c => c.DownloadFile(It.IsAny<string>(), expectedFilename), Times.Once());
}