7a0da7932b
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Has been cancelled
Docker Tests (Consolidated) / Accessibility Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Unit Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Example Tests (push) Has been cancelled
Docker Tests (Consolidated) / Production Image Smoke Test (push) Has been cancelled
Docker Tests (Consolidated) / Infrastructure Tests (push) Has been cancelled
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Has been cancelled
Backwards Compatibility / Verify Encryption Constants (push) Has been cancelled
Backwards Compatibility / PyPI Version Compatibility (push) Has been cancelled
Backwards Compatibility / Database Migration Tests (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Docker Tests (Consolidated) / detect-changes (push) Has been cancelled
Docker Tests (Consolidated) / Build Test Image (push) Has been cancelled
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Has been cancelled
152 lines
5.7 KiB
Python
152 lines
5.7 KiB
Python
"""Tests for web/utils/templates.py."""
|
|
|
|
from unittest.mock import patch
|
|
|
|
|
|
class TestRenderTemplateWithDefaults:
|
|
"""Tests for render_template_with_defaults function."""
|
|
|
|
def test_adds_version_to_kwargs(self):
|
|
"""Test that version is added to template kwargs."""
|
|
with patch(
|
|
"local_deep_research.web.utils.templates.render_template"
|
|
) as mock_render:
|
|
with patch(
|
|
"local_deep_research.database.encrypted_db.db_manager"
|
|
) as mock_db:
|
|
mock_db.has_encryption = False
|
|
mock_render.return_value = "rendered"
|
|
|
|
from local_deep_research.web.utils.templates import (
|
|
render_template_with_defaults,
|
|
)
|
|
|
|
render_template_with_defaults("test.html")
|
|
|
|
# Check that version was passed
|
|
call_kwargs = mock_render.call_args[1]
|
|
assert "version" in call_kwargs
|
|
|
|
def test_adds_has_encryption_to_kwargs(self):
|
|
"""Test that has_encryption is added to template kwargs."""
|
|
with patch(
|
|
"local_deep_research.web.utils.templates.render_template"
|
|
) as mock_render:
|
|
with patch(
|
|
"local_deep_research.database.encrypted_db.db_manager"
|
|
) as mock_db:
|
|
mock_db.has_encryption = True
|
|
mock_render.return_value = "rendered"
|
|
|
|
from local_deep_research.web.utils.templates import (
|
|
render_template_with_defaults,
|
|
)
|
|
|
|
render_template_with_defaults("test.html")
|
|
|
|
call_kwargs = mock_render.call_args[1]
|
|
assert call_kwargs["has_encryption"] is True
|
|
|
|
def test_passes_encryption_false_when_disabled(self):
|
|
"""Test that has_encryption is False when encryption disabled."""
|
|
with patch(
|
|
"local_deep_research.web.utils.templates.render_template"
|
|
) as mock_render:
|
|
with patch(
|
|
"local_deep_research.database.encrypted_db.db_manager"
|
|
) as mock_db:
|
|
mock_db.has_encryption = False
|
|
mock_render.return_value = "rendered"
|
|
|
|
from local_deep_research.web.utils.templates import (
|
|
render_template_with_defaults,
|
|
)
|
|
|
|
render_template_with_defaults("test.html")
|
|
|
|
call_kwargs = mock_render.call_args[1]
|
|
assert call_kwargs["has_encryption"] is False
|
|
|
|
def test_passes_template_name_as_first_arg(self):
|
|
"""Test that template name is passed as first argument."""
|
|
with patch(
|
|
"local_deep_research.web.utils.templates.render_template"
|
|
) as mock_render:
|
|
with patch(
|
|
"local_deep_research.database.encrypted_db.db_manager"
|
|
) as mock_db:
|
|
mock_db.has_encryption = False
|
|
mock_render.return_value = "rendered"
|
|
|
|
from local_deep_research.web.utils.templates import (
|
|
render_template_with_defaults,
|
|
)
|
|
|
|
render_template_with_defaults("my_template.html")
|
|
|
|
call_args = mock_render.call_args[0]
|
|
assert call_args[0] == "my_template.html"
|
|
|
|
def test_passes_custom_kwargs_to_render_template(self):
|
|
"""Test that custom kwargs are passed through to render_template."""
|
|
with patch(
|
|
"local_deep_research.web.utils.templates.render_template"
|
|
) as mock_render:
|
|
with patch(
|
|
"local_deep_research.database.encrypted_db.db_manager"
|
|
) as mock_db:
|
|
mock_db.has_encryption = False
|
|
mock_render.return_value = "rendered"
|
|
|
|
from local_deep_research.web.utils.templates import (
|
|
render_template_with_defaults,
|
|
)
|
|
|
|
render_template_with_defaults(
|
|
"test.html", title="My Title", data={"key": "value"}
|
|
)
|
|
|
|
call_kwargs = mock_render.call_args[1]
|
|
assert call_kwargs["title"] == "My Title"
|
|
assert call_kwargs["data"] == {"key": "value"}
|
|
|
|
def test_returns_render_template_result(self):
|
|
"""Test that the function returns the result from render_template."""
|
|
with patch(
|
|
"local_deep_research.web.utils.templates.render_template"
|
|
) as mock_render:
|
|
with patch(
|
|
"local_deep_research.database.encrypted_db.db_manager"
|
|
) as mock_db:
|
|
mock_db.has_encryption = False
|
|
mock_render.return_value = "<html>Content</html>"
|
|
|
|
from local_deep_research.web.utils.templates import (
|
|
render_template_with_defaults,
|
|
)
|
|
|
|
result = render_template_with_defaults("test.html")
|
|
|
|
assert result == "<html>Content</html>"
|
|
|
|
def test_passes_multiple_positional_args(self):
|
|
"""Test that multiple positional arguments are passed through."""
|
|
with patch(
|
|
"local_deep_research.web.utils.templates.render_template"
|
|
) as mock_render:
|
|
with patch(
|
|
"local_deep_research.database.encrypted_db.db_manager"
|
|
) as mock_db:
|
|
mock_db.has_encryption = False
|
|
mock_render.return_value = "rendered"
|
|
|
|
from local_deep_research.web.utils.templates import (
|
|
render_template_with_defaults,
|
|
)
|
|
|
|
render_template_with_defaults("template.html", "extra_arg")
|
|
|
|
call_args = mock_render.call_args[0]
|
|
assert "template.html" in call_args
|
|
assert "extra_arg" in call_args
|