mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-10-13 03:27:13 +00:00
Chore: New helper for JSON parsing during settings, to provide a better error message to users (#14419)
This commit is contained in:
1 parent
1fb463b55c
commit
6f496f741b
4 files changed
+116
-89
No files matched your search
@@ -7,7 +7,6 @@ from django.core.exceptions import ImproperlyConfigured
|
||||
|
||||
from paperless.settings import _get_allauth_trusted_proxy_count
|
||||
from paperless.settings import _get_classifier_language_setting
|
||||
from paperless.settings import _get_llm_extra_params
|
||||
from paperless.settings import _get_search_language_setting
|
||||
from paperless.settings import _parse_paperless_url
|
||||
from paperless.settings import default_threads_per_worker
|
||||
@@ -167,45 +166,3 @@ class TestPaperlessURLSettings(TestCase):
|
||||
|
||||
self.assertIn(url, settings.CSRF_TRUSTED_ORIGINS)
|
||||
self.assertIn(url, settings.CORS_ALLOWED_ORIGINS)
|
||||
|
||||
|
||||
class TestLlmExtraParams:
|
||||
@pytest.mark.parametrize(
|
||||
("env_value", "expected"),
|
||||
[
|
||||
pytest.param(None, {}, id="unset"),
|
||||
pytest.param(
|
||||
'{"reasoning_effort": "none"}',
|
||||
{"reasoning_effort": "none"},
|
||||
id="json-object",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_parses(
|
||||
self,
|
||||
monkeypatch,
|
||||
env_value,
|
||||
expected,
|
||||
):
|
||||
if env_value is None:
|
||||
monkeypatch.delenv("PAPERLESS_AI_LLM_EXTRA_PARAMS", raising=False)
|
||||
else:
|
||||
monkeypatch.setenv("PAPERLESS_AI_LLM_EXTRA_PARAMS", env_value)
|
||||
assert _get_llm_extra_params() == expected
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("env_value", "match"),
|
||||
[
|
||||
pytest.param("reasoning_effort=none", "valid JSON", id="invalid-json"),
|
||||
pytest.param('["none"]', "JSON object", id="not-an-object"),
|
||||
],
|
||||
)
|
||||
def test_invalid_raises(
|
||||
self,
|
||||
monkeypatch,
|
||||
env_value,
|
||||
match,
|
||||
):
|
||||
monkeypatch.setenv("PAPERLESS_AI_LLM_EXTRA_PARAMS", env_value)
|
||||
with pytest.raises(ImproperlyConfigured, match=match):
|
||||
_get_llm_extra_params()
|
||||
Reference in new issue
Block a user