mirror of
https://github.com/Radarr/Radarr
synced 2025-12-06 08:28:50 +01:00
Add unit tests and code documentation for Pre-Import feature
Tests: - Added 8 comprehensive unit tests covering all Pre-Import scenarios - Tests verify savePath is passed correctly when feature is enabled - Tests verify savePath is null when feature is disabled or invalid - Tests cover both magnet links and torrent files - Tests cover edge cases (null movie, null path, empty path) Documentation: - Added inline code comments explaining Pre-Import feature purpose - Documented that feature avoids cross-drive file moves - Comments explain when savePath parameter is set All tests follow existing Radarr testing patterns using NUnit, FluentAssertions, and Moq. The tests ensure the feature behaves correctly in all scenarios and maintains backward compatibility.
This commit is contained in:
parent
908c2212c1
commit
6e4eb7f5ec
4 changed files with 175 additions and 0 deletions
|
|
@ -994,5 +994,170 @@ public void Test_should_force_api_version_check()
|
|||
Mocker.GetMock<IQBittorrentProxySelector>()
|
||||
.Verify(v => v.GetProxy(It.IsAny<QBittorrentSettings>(), true), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Download_should_not_use_savepath_when_preimport_disabled()
|
||||
{
|
||||
// Arrange
|
||||
var remoteMovie = CreateRemoteMovie();
|
||||
remoteMovie.Movie.Path = "/movies/My Movie (2024)";
|
||||
|
||||
// Ensure PreImportToDestination is false (default)
|
||||
Subject.Definition.Settings.As<QBittorrentSettings>().PreImportToDestination = false;
|
||||
|
||||
// Act
|
||||
await Subject.Download(remoteMovie, CreateIndexer());
|
||||
|
||||
// Assert - savePath parameter should be null
|
||||
Mocker.GetMock<IQBittorrentProxy>()
|
||||
.Verify(v => v.AddTorrentFromFile(
|
||||
It.IsAny<string>(),
|
||||
It.IsAny<byte[]>(),
|
||||
It.IsAny<TorrentSeedConfiguration>(),
|
||||
It.IsAny<QBittorrentSettings>(),
|
||||
null), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Download_should_use_savepath_when_preimport_enabled_with_valid_movie_path()
|
||||
{
|
||||
// Arrange
|
||||
var moviePath = "/movies/My Movie (2024)";
|
||||
var remoteMovie = CreateRemoteMovie();
|
||||
remoteMovie.Movie.Path = moviePath;
|
||||
|
||||
// Enable PreImportToDestination
|
||||
Subject.Definition.Settings.As<QBittorrentSettings>().PreImportToDestination = true;
|
||||
|
||||
// Act
|
||||
await Subject.Download(remoteMovie, CreateIndexer());
|
||||
|
||||
// Assert - savePath parameter should be the movie path
|
||||
Mocker.GetMock<IQBittorrentProxy>()
|
||||
.Verify(v => v.AddTorrentFromFile(
|
||||
It.IsAny<string>(),
|
||||
It.IsAny<byte[]>(),
|
||||
It.IsAny<TorrentSeedConfiguration>(),
|
||||
It.IsAny<QBittorrentSettings>(),
|
||||
moviePath), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Download_should_not_use_savepath_when_preimport_enabled_but_movie_path_is_null()
|
||||
{
|
||||
// Arrange
|
||||
var remoteMovie = CreateRemoteMovie();
|
||||
remoteMovie.Movie.Path = null;
|
||||
|
||||
// Enable PreImportToDestination
|
||||
Subject.Definition.Settings.As<QBittorrentSettings>().PreImportToDestination = true;
|
||||
|
||||
// Act
|
||||
await Subject.Download(remoteMovie, CreateIndexer());
|
||||
|
||||
// Assert - savePath parameter should be null due to null movie path
|
||||
Mocker.GetMock<IQBittorrentProxy>()
|
||||
.Verify(v => v.AddTorrentFromFile(
|
||||
It.IsAny<string>(),
|
||||
It.IsAny<byte[]>(),
|
||||
It.IsAny<TorrentSeedConfiguration>(),
|
||||
It.IsAny<QBittorrentSettings>(),
|
||||
null), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Download_should_not_use_savepath_when_preimport_enabled_but_movie_path_is_empty()
|
||||
{
|
||||
// Arrange
|
||||
var remoteMovie = CreateRemoteMovie();
|
||||
remoteMovie.Movie.Path = "";
|
||||
|
||||
// Enable PreImportToDestination
|
||||
Subject.Definition.Settings.As<QBittorrentSettings>().PreImportToDestination = true;
|
||||
|
||||
// Act
|
||||
await Subject.Download(remoteMovie, CreateIndexer());
|
||||
|
||||
// Assert - savePath parameter should be null due to empty movie path
|
||||
Mocker.GetMock<IQBittorrentProxy>()
|
||||
.Verify(v => v.AddTorrentFromFile(
|
||||
It.IsAny<string>(),
|
||||
It.IsAny<byte[]>(),
|
||||
It.IsAny<TorrentSeedConfiguration>(),
|
||||
It.IsAny<QBittorrentSettings>(),
|
||||
null), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Download_from_magnet_should_use_savepath_when_preimport_enabled()
|
||||
{
|
||||
// Arrange
|
||||
var moviePath = "/movies/My Movie (2024)";
|
||||
var magnetUrl = "magnet:?xt=urn:btih:ZPBPA2P6ROZPKRHK44D5OW6NHXU5Z6KR&tr=udp";
|
||||
var remoteMovie = CreateRemoteMovie();
|
||||
remoteMovie.Movie.Path = moviePath;
|
||||
remoteMovie.Release.DownloadUrl = magnetUrl;
|
||||
|
||||
// Enable PreImportToDestination
|
||||
Subject.Definition.Settings.As<QBittorrentSettings>().PreImportToDestination = true;
|
||||
|
||||
// Act
|
||||
await Subject.Download(remoteMovie, CreateIndexer());
|
||||
|
||||
// Assert - savePath parameter should be the movie path for magnet links
|
||||
Mocker.GetMock<IQBittorrentProxy>()
|
||||
.Verify(v => v.AddTorrentFromUrl(
|
||||
magnetUrl,
|
||||
It.IsAny<TorrentSeedConfiguration>(),
|
||||
It.IsAny<QBittorrentSettings>(),
|
||||
moviePath), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Download_from_magnet_should_not_use_savepath_when_preimport_disabled()
|
||||
{
|
||||
// Arrange
|
||||
var magnetUrl = "magnet:?xt=urn:btih:ZPBPA2P6ROZPKRHK44D5OW6NHXU5Z6KR&tr=udp";
|
||||
var remoteMovie = CreateRemoteMovie();
|
||||
remoteMovie.Movie.Path = "/movies/My Movie (2024)";
|
||||
remoteMovie.Release.DownloadUrl = magnetUrl;
|
||||
|
||||
// Ensure PreImportToDestination is false (default)
|
||||
Subject.Definition.Settings.As<QBittorrentSettings>().PreImportToDestination = false;
|
||||
|
||||
// Act
|
||||
await Subject.Download(remoteMovie, CreateIndexer());
|
||||
|
||||
// Assert - savePath parameter should be null
|
||||
Mocker.GetMock<IQBittorrentProxy>()
|
||||
.Verify(v => v.AddTorrentFromUrl(
|
||||
magnetUrl,
|
||||
It.IsAny<TorrentSeedConfiguration>(),
|
||||
It.IsAny<QBittorrentSettings>(),
|
||||
null), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Download_should_not_use_savepath_when_movie_is_null()
|
||||
{
|
||||
// Arrange
|
||||
var remoteMovie = CreateRemoteMovie();
|
||||
remoteMovie.Movie = null;
|
||||
|
||||
// Enable PreImportToDestination
|
||||
Subject.Definition.Settings.As<QBittorrentSettings>().PreImportToDestination = true;
|
||||
|
||||
// Act
|
||||
await Subject.Download(remoteMovie, CreateIndexer());
|
||||
|
||||
// Assert - savePath parameter should be null due to null movie
|
||||
Mocker.GetMock<IQBittorrentProxy>()
|
||||
.Verify(v => v.AddTorrentFromFile(
|
||||
It.IsAny<string>(),
|
||||
It.IsAny<byte[]>(),
|
||||
It.IsAny<TorrentSeedConfiguration>(),
|
||||
It.IsAny<QBittorrentSettings>(),
|
||||
null), Times.Once());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,6 +81,9 @@ protected override string AddFromMagnetLink(RemoteMovie remoteMovie, string hash
|
|||
var moveToTop = (isRecentMovie && Settings.RecentMoviePriority == (int)QBittorrentPriority.First) || (!isRecentMovie && Settings.OlderMoviePriority == (int)QBittorrentPriority.First);
|
||||
var forceStart = (QBittorrentState)Settings.InitialState == QBittorrentState.ForceStart;
|
||||
|
||||
// Pre-Import: Download directly to the movie's final destination folder to avoid
|
||||
// unnecessary file moves between download directory and media library.
|
||||
// This is particularly beneficial when they are on different physical drives.
|
||||
string savePath = null;
|
||||
if (Settings.PreImportToDestination && remoteMovie.Movie != null && remoteMovie.Movie.Path.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
|
|
@ -145,6 +148,9 @@ protected override string AddFromTorrentFile(RemoteMovie remoteMovie, string has
|
|||
var moveToTop = (isRecentMovie && Settings.RecentMoviePriority == (int)QBittorrentPriority.First) || (!isRecentMovie && Settings.OlderMoviePriority == (int)QBittorrentPriority.First);
|
||||
var forceStart = (QBittorrentState)Settings.InitialState == QBittorrentState.ForceStart;
|
||||
|
||||
// Pre-Import: Download directly to the movie's final destination folder to avoid
|
||||
// unnecessary file moves between download directory and media library.
|
||||
// This is particularly beneficial when they are on different physical drives.
|
||||
string savePath = null;
|
||||
if (Settings.PreImportToDestination && remoteMovie.Movie != null && remoteMovie.Movie.Path.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -136,6 +136,7 @@ public void AddTorrentFromUrl(string torrentUrl, TorrentSeedConfiguration seedCo
|
|||
.Post()
|
||||
.AddFormParameter("urls", torrentUrl);
|
||||
|
||||
// Set custom save path for Pre-Import feature to download directly to destination folder
|
||||
if (savePath.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
request.AddFormParameter("savepath", savePath);
|
||||
|
|
@ -171,6 +172,7 @@ public void AddTorrentFromFile(string fileName, byte[] fileContent, TorrentSeedC
|
|||
.Post()
|
||||
.AddFormUpload("torrents", fileName, fileContent);
|
||||
|
||||
// Set custom save path for Pre-Import feature to download directly to destination folder
|
||||
if (savePath.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
request.AddFormParameter("savepath", savePath);
|
||||
|
|
|
|||
|
|
@ -148,6 +148,7 @@ public void AddTorrentFromUrl(string torrentUrl, TorrentSeedConfiguration seedCo
|
|||
.Post()
|
||||
.AddFormParameter("urls", torrentUrl);
|
||||
|
||||
// Set custom save path for Pre-Import feature to download directly to destination folder
|
||||
if (savePath.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
request.AddFormParameter("savepath", savePath);
|
||||
|
|
@ -175,6 +176,7 @@ public void AddTorrentFromFile(string fileName, byte[] fileContent, TorrentSeedC
|
|||
.Post()
|
||||
.AddFormUpload("torrents", fileName, fileContent);
|
||||
|
||||
// Set custom save path for Pre-Import feature to download directly to destination folder
|
||||
if (savePath.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
request.AddFormParameter("savepath", savePath);
|
||||
|
|
|
|||
Loading…
Reference in a new issue