Merge pull request #6849 from 1337joe/server-disabled-metadata

This commit is contained in:
Cody Robibero 2021-11-15 07:25:56 -07:00 committed by GitHub
commit 03435641c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 91 additions and 2 deletions

View File

@ -60,7 +60,7 @@ namespace MediaBrowser.Controller.BaseItemManager
return false;
}
var itemConfig = _serverConfigurationManager.Configuration.MetadataOptions.FirstOrDefault(i => string.Equals(i.ItemType, GetType().Name, StringComparison.OrdinalIgnoreCase));
var itemConfig = _serverConfigurationManager.Configuration.MetadataOptions.FirstOrDefault(i => string.Equals(i.ItemType, baseItem.GetType().Name, StringComparison.OrdinalIgnoreCase));
return itemConfig == null || !itemConfig.DisabledMetadataFetchers.Contains(name.AsSpan(), StringComparison.OrdinalIgnoreCase);
}
@ -91,7 +91,7 @@ namespace MediaBrowser.Controller.BaseItemManager
return false;
}
var itemConfig = _serverConfigurationManager.Configuration.MetadataOptions.FirstOrDefault(i => string.Equals(i.ItemType, GetType().Name, StringComparison.OrdinalIgnoreCase));
var itemConfig = _serverConfigurationManager.Configuration.MetadataOptions.FirstOrDefault(i => string.Equals(i.ItemType, baseItem.GetType().Name, StringComparison.OrdinalIgnoreCase));
return itemConfig == null || !itemConfig.DisabledImageFetchers.Contains(name.AsSpan(), StringComparison.OrdinalIgnoreCase);
}

View File

@ -0,0 +1,89 @@
using System;
using MediaBrowser.Controller.BaseItemManager;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Model.Configuration;
using Moq;
using Xunit;
namespace Jellyfin.Controller.Tests
{
public class BaseItemManagerTests
{
[Theory]
[InlineData(typeof(Book), "LibraryEnabled", true)]
[InlineData(typeof(Book), "LibraryDisabled", false)]
[InlineData(typeof(MusicArtist), "Enabled", true)]
[InlineData(typeof(MusicArtist), "ServerDisabled", false)]
public void IsMetadataFetcherEnabled_ChecksOptions_ReturnsExpected(Type itemType, string fetcherName, bool expected)
{
BaseItem item = (BaseItem)Activator.CreateInstance(itemType)!;
var libraryOptions = new LibraryOptions
{
TypeOptions = new[]
{
new TypeOptions
{
Type = "Book",
MetadataFetchers = new[] { "LibraryEnabled" }
}
}
};
var serverConfiguration = new ServerConfiguration();
foreach (var typeConfig in serverConfiguration.MetadataOptions)
{
typeConfig.DisabledMetadataFetchers = new[] { "ServerDisabled" };
}
var serverConfigurationManager = new Mock<IServerConfigurationManager>();
serverConfigurationManager.Setup(scm => scm.Configuration)
.Returns(serverConfiguration);
var baseItemManager = new BaseItemManager(serverConfigurationManager.Object);
var actual = baseItemManager.IsMetadataFetcherEnabled(item, libraryOptions, fetcherName);
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(typeof(Book), "LibraryEnabled", true)]
[InlineData(typeof(Book), "LibraryDisabled", false)]
[InlineData(typeof(MusicArtist), "Enabled", true)]
[InlineData(typeof(MusicArtist), "ServerDisabled", false)]
public void IsImageFetcherEnabled_ChecksOptions_ReturnsExpected(Type itemType, string fetcherName, bool expected)
{
BaseItem item = (BaseItem)Activator.CreateInstance(itemType)!;
var libraryOptions = new LibraryOptions
{
TypeOptions = new[]
{
new TypeOptions
{
Type = "Book",
ImageFetchers = new[] { "LibraryEnabled" }
}
}
};
var serverConfiguration = new ServerConfiguration();
foreach (var typeConfig in serverConfiguration.MetadataOptions)
{
typeConfig.DisabledImageFetchers = new[] { "ServerDisabled" };
}
var serverConfigurationManager = new Mock<IServerConfigurationManager>();
serverConfigurationManager.Setup(scm => scm.Configuration)
.Returns(serverConfiguration);
var baseItemManager = new BaseItemManager(serverConfigurationManager.Object);
var actual = baseItemManager.IsImageFetcherEnabled(item, libraryOptions, fetcherName);
Assert.Equal(expected, actual);
}
}
}