mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-26 07:35:44 -03:00
Add new setting 'mature_blur_level' with options PG13/R/X/XXX to control which NSFW rating level triggers blur filtering when NSFW blur is enabled. - Backend: update preview selection logic to respect threshold - Frontend: update UI components to use configurable threshold - Settings: add validation and normalization for mature_blur_level - Tests: add coverage for new threshold behavior - Translations: add keys for all supported languages Fixes #867
50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
import pytest
|
|
|
|
from py.utils.constants import NSFW_LEVELS
|
|
from py.utils.preview_selection import resolve_mature_threshold, select_preview_media
|
|
|
|
|
|
def test_select_preview_returns_first_when_blur_disabled():
|
|
images = [
|
|
{"url": "nsfw", "type": "image", "nsfwLevel": 32},
|
|
{"url": "safe", "type": "image", "nsfwLevel": 1},
|
|
]
|
|
|
|
selected, level = select_preview_media(images, blur_mature_content=False)
|
|
|
|
assert selected["url"] == "nsfw"
|
|
assert level == 32
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("threshold_name", "expected_url"),
|
|
[
|
|
("PG13", "pg"),
|
|
("R", "pg13"),
|
|
("X", "r"),
|
|
("XXX", "x"),
|
|
],
|
|
)
|
|
def test_select_preview_respects_configurable_threshold(threshold_name, expected_url):
|
|
images = [
|
|
{"url": "xxx", "type": "image", "nsfwLevel": NSFW_LEVELS["XXX"]},
|
|
{"url": "x", "type": "image", "nsfwLevel": NSFW_LEVELS["X"]},
|
|
{"url": "r", "type": "image", "nsfwLevel": NSFW_LEVELS["R"]},
|
|
{"url": "pg13", "type": "image", "nsfwLevel": NSFW_LEVELS["PG13"]},
|
|
{"url": "pg", "type": "image", "nsfwLevel": NSFW_LEVELS["PG"]},
|
|
]
|
|
|
|
selected, level = select_preview_media(
|
|
images,
|
|
blur_mature_content=True,
|
|
mature_threshold=NSFW_LEVELS[threshold_name],
|
|
)
|
|
|
|
assert selected["url"] == expected_url
|
|
assert level == next(item["nsfwLevel"] for item in images if item["url"] == expected_url)
|
|
|
|
|
|
def test_resolve_mature_threshold_falls_back_to_r_for_invalid_value():
|
|
assert resolve_mature_threshold({"mature_blur_level": "invalid"}) == NSFW_LEVELS["R"]
|
|
assert resolve_mature_threshold({}) == NSFW_LEVELS["R"]
|