From 0a589c529fe3e4106d8ba90bfb52f8c115ed1b58 Mon Sep 17 00:00:00 2001 From: ta264 Date: Wed, 8 May 2019 06:06:05 +0100 Subject: [PATCH] Fixed: Map dsm shared folder to full path in status (#797) * Fixed: Map dsm shared folder to full path in status * Add tests * fix tests --- .../TorrentDownloadStationFixture.cs | 49 ++++++++++++++++++- .../UsenetDownloadStationFixture.cs | 47 ++++++++++++++++++ .../DownloadStation/TorrentDownloadStation.cs | 7 ++- .../DownloadStation/UsenetDownloadStation.cs | 7 ++- 4 files changed, 105 insertions(+), 5 deletions(-) diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/TorrentDownloadStationFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/TorrentDownloadStationFixture.cs index 6197b1b83..3d071c8bc 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/TorrentDownloadStationFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/TorrentDownloadStationFixture.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using FluentAssertions; @@ -7,6 +7,7 @@ using NUnit.Framework; using NzbDrone.Common.Disk; using NzbDrone.Common.Http; using NzbDrone.Core.Download; +using NzbDrone.Core.Download.Clients; using NzbDrone.Core.Download.Clients.DownloadStation; using NzbDrone.Core.Download.Clients.DownloadStation.Proxies; using NzbDrone.Core.MediaFiles.TorrentInfo; @@ -296,6 +297,17 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests .Returns((path, setttings, serial) => _physicalPath); } + protected void GivenSharedFolder(string share) + { + Mocker.GetMock() + .Setup(s => s.RemapToFullPath(It.IsAny(), It.IsAny(), It.IsAny())) + .Throws(new DownloadClientException("There is no matching shared folder")); + + Mocker.GetMock() + .Setup(s => s.RemapToFullPath(It.Is(x => x.FullPath == share), It.IsAny(), It.IsAny())) + .Returns((path, setttings, serial) => _physicalPath); + } + protected void GivenSerialNumber() { Mocker.GetMock() @@ -495,6 +507,41 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests .Verify(v => v.AddTaskFromUrl(It.IsAny(), null, _settings), Times.Never()); } + [Test] + public void GetStatus_should_map_outputpath_when_using_default() + { + GivenSerialNumber(); + GivenSharedFolder("/somepath"); + + var status = Subject.GetStatus(); + + status.OutputRootFolders.First().Should().Be(_physicalPath); + } + + [Test] + public void GetStatus_should_map_outputpath_when_using_destination() + { + GivenSerialNumber(); + GivenTvDirectory(); + GivenSharedFolder($"/{_tvDirectory}"); + + var status = Subject.GetStatus(); + + status.OutputRootFolders.First().Should().Be(_physicalPath); + } + + [Test] + public void GetStatus_should_map_outputpath_when_using_category() + { + GivenSerialNumber(); + GivenTvCategory(); + GivenSharedFolder($"/somepath/{_category}"); + + var status = Subject.GetStatus(); + + status.OutputRootFolders.First().Should().Be(_physicalPath); + } + [Test] public void GetItems_should_set_outputPath_to_base_folder_when_single_file_non_finished_tasks() { diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/UsenetDownloadStationFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/UsenetDownloadStationFixture.cs index 79463f1cc..1bea62b49 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/UsenetDownloadStationFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/UsenetDownloadStationFixture.cs @@ -7,6 +7,7 @@ using NUnit.Framework; using NzbDrone.Common.Disk; using NzbDrone.Common.Http; using NzbDrone.Core.Download; +using NzbDrone.Core.Download.Clients; using NzbDrone.Core.Download.Clients.DownloadStation; using NzbDrone.Core.Download.Clients.DownloadStation.Proxies; using NzbDrone.Core.Organizer; @@ -188,6 +189,17 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests .Returns((path, setttings, serial) => _physicalPath); } + protected void GivenSharedFolder(string share) + { + Mocker.GetMock() + .Setup(s => s.RemapToFullPath(It.IsAny(), It.IsAny(), It.IsAny())) + .Throws(new DownloadClientException("There is no matching shared folder")); + + Mocker.GetMock() + .Setup(s => s.RemapToFullPath(It.Is(x => x.FullPath == share), It.IsAny(), It.IsAny())) + .Returns((path, setttings, serial) => _physicalPath); + } + protected void GivenSerialNumber() { Mocker.GetMock() @@ -377,6 +389,41 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests .Verify(v => v.AddTaskFromUrl(It.IsAny(), null, _settings), Times.Never()); } + [Test] + public void GetStatus_should_map_outputpath_when_using_default() + { + GivenSerialNumber(); + GivenSharedFolder("/somepath"); + + var status = Subject.GetStatus(); + + status.OutputRootFolders.First().Should().Be(_physicalPath); + } + + [Test] + public void GetStatus_should_map_outputpath_when_using_destination() + { + GivenSerialNumber(); + GivenTvDirectory(); + GivenSharedFolder($"/{_tvDirectory}"); + + var status = Subject.GetStatus(); + + status.OutputRootFolders.First().Should().Be(_physicalPath); + } + + [Test] + public void GetStatus_should_map_outputpath_when_using_category() + { + GivenSerialNumber(); + GivenTvCategory(); + GivenSharedFolder($"/somepath/{_category}"); + + var status = Subject.GetStatus(); + + status.OutputRootFolders.First().Should().Be(_physicalPath); + } + [Test] public void GetItems_should_not_map_outputpath_for_queued_or_downloading_tasks() { diff --git a/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs b/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs index abdaa75a1..e1165d086 100644 --- a/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs +++ b/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs @@ -115,12 +115,15 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation { try { - var path = GetDownloadDirectory(); + var serialNumber = _serialNumberProvider.GetSerialNumber(Settings); + var sharedFolder = GetDownloadDirectory() ?? GetDefaultDir(); + var outputPath = new OsPath($"/{sharedFolder.TrimStart('/')}"); + var path = _sharedFolderResolver.RemapToFullPath(outputPath, Settings, serialNumber); return new DownloadClientInfo { IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost", - OutputRootFolders = new List { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(path)) } + OutputRootFolders = new List { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, path) } }; } catch (DownloadClientException e) diff --git a/src/NzbDrone.Core/Download/Clients/DownloadStation/UsenetDownloadStation.cs b/src/NzbDrone.Core/Download/Clients/DownloadStation/UsenetDownloadStation.cs index 4032d8bf3..b590f665f 100644 --- a/src/NzbDrone.Core/Download/Clients/DownloadStation/UsenetDownloadStation.cs +++ b/src/NzbDrone.Core/Download/Clients/DownloadStation/UsenetDownloadStation.cs @@ -139,12 +139,15 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation { try { - var path = GetDownloadDirectory(); + var serialNumber = _serialNumberProvider.GetSerialNumber(Settings); + var sharedFolder = GetDownloadDirectory() ?? GetDefaultDir(); + var outputPath = new OsPath($"/{sharedFolder.TrimStart('/')}"); + var path = _sharedFolderResolver.RemapToFullPath(outputPath, Settings, serialNumber); return new DownloadClientInfo { IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost", - OutputRootFolders = new List { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(path)) } + OutputRootFolders = new List { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, path) } }; } catch (DownloadClientException e)