Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

test: add 53 high-value tests across 3 modules (round 12) (#2600)

LearningCircuit9a47389fe0b7
diff --git a/tests/database/test_credential_store_ttl.py b/tests/database/test_credential_store_ttl.py
new file mode 100644
index 0000000000..feddb282a8
--- /dev/null
+++ b/tests/database/test_credential_store_ttl.py
@@ -0,0 +1,104 @@
+"""Tests for CredentialStoreBase TTL boundary conditions and remove parameter.
+
+Complements test_credential_store_base.py and test_credential_store_extended.py
+by testing precise TTL boundaries using mocked time.time().
+"""
+
+import time as time_module
+from unittest.mock import patch
+
+
+from local_deep_research.database.credential_store_base import (
+ CredentialStoreBase,
+)
+
+
+class ConcreteStore(CredentialStoreBase):
+ """Minimal concrete subclass for testing base class logic."""
+
+ def store(self, key, username, password):
+ self._store_credentials(
+ key, {"username": username, "password": password}
+ )
+
+ def retrieve(self, key, remove=False):
+ return self._retrieve_credentials(key, remove=remove)
+
+
+# ---------------------------------------------------------------------------
+# _retrieve_credentials boundary conditions
+# ---------------------------------------------------------------------------
+
+
+class TestRetrieveCredentialsBoundary:
+ """TTL boundary tests using mocked time."""
+
+ def test_not_expired_at_exact_boundary(self):
+ """time.time() == expires_at → NOT expired (uses > not >=)."""
+ store = ConcreteStore(ttl_seconds=100)
+ with patch.object(time_module, "time", return_value=1000.0):
+ store.store("k", "user", "pass")
+ # expires_at = 1000.0 + 100 = 1100.0
+
+ with patch.object(time_module, "time", return_value=1100.0):
+ result = store.retrieve("k")
+ assert result == ("user", "pass")
+
+ def test_expired_just_past_boundary(self):
+ """time.time() = expires_at + epsilon → expired."""
+ store = ConcreteStore(ttl_seconds=100)
+ with patch.object(time_module, "time", return_value=1000.0):
+ store.store("k", "user", "pass")
+
+ with patch.object(time_module, "time", return_value=1100.001):
+ result = store.retrieve("k")
+ assert result is None
+
+ def test_expired_entry_deleted_from_store(self):
+ """Expired retrieval deletes the entry."""
+ store = ConcreteStore(ttl_seconds=10)
+ with patch.object(time_module, "time", return_value=1000.0):
+ store.store("k", "user", "pass")
+
+ with patch.object(time_module, "time", return_value=1011.0):
+ store.retrieve("k") # triggers deletion
+ assert "k" not in store._store
+
+
+# ---------------------------------------------------------------------------
+# _cleanup_expired
+# ---------------------------------------------------------------------------
+
+
+class TestCleanupExpired:
+ """Tests for _cleanup_expired logic with mocked time."""
+
+ def test_some_expired(self):
+ store = ConcreteStore(ttl_seconds=100)
+ with patch.object(time_module, "time", return_value=1000.0):
+ store.store("old", "u1", "p1")
+ # Insert "new" directly, bypassing _store_credentials' implicit cleanup
+ with patch.object(time_module, "time", return_value=2000.0):
+ store._store["new"] = {
+ "username": "u2",
+ "password": "p2",
+ "expires_at": time_module.time() + store.ttl, # 2100
+ }
+ store._cleanup_expired()
+ assert "old" not in store._store
+ assert "new" in store._store
+
+ def test_all_expired(self):
+ store = ConcreteStore(ttl_seconds=10)
+ with patch.object(time_module, "time", return_value=1000.0):
+ store.store("a", "u1", "p1")
+ store.store("b", "u2", "p2")
+
+ with patch.object(time_module, "time", return_value=2000.0):
+ store._cleanup_expired()
+ assert len(store._store) == 0
+
+ def test_empty_store_no_error(self):
+ store = ConcreteStore(ttl_seconds=3600)
+ store._cleanup_expired() # should not raise
+ assert len(store._store) == 0
diff --git a/tests/research_library/services/test_pdf_filename_generation.py b/tests/research_library/services/test_pdf_filename_generation.py
new file mode 100644
index 0000000000..1ddc0030b6
--- /dev/null
+++ b/tests/research_library/services/test_pdf_filename_generation.py
@@ -0,0 +1,130 @@
+"""Tests for PDFStorageManager._generate_filename() and _infer_storage_mode() edge cases.
+
+Fills gaps NOT covered by test_pdf_storage_manager_edge_cases.py.
+"""
+
+from unittest.mock import Mock
+
+import pytest
+
+from local_deep_research.research_library.services.pdf_storage_manager import (
+ PDFStorageManager,
+)
+
+
+def manager(tmp_path):
+ """Create a PDFStorageManager rooted in a pytest-managed temp directory."""
+ return PDFStorageManager(
+ library_root=tmp_path,
+ storage_mode="database",
+ max_pdf_size_mb=100,
+ )
+
+
+# ---------------------------------------------------------------------------
+# _generate_filename edge cases
+# ---------------------------------------------------------------------------
+
+
+class TestGenerateFilenameEdgeCases:
+ """Edge cases not covered by test_pdf_storage_manager_edge_cases.py."""
+
+ def test_arxiv_url_without_valid_id_fallback(self, manager):
+ """arXiv URL with no matching ID pattern → fallback with timestamp."""
+ result = manager._generate_filename(
+ "https://arxiv.org/some/page", 42, "fallback.pdf"
+ )
+ assert result.startswith("arxiv_")
+ assert "42" in result
+ assert result.endswith(".pdf")
+
+ def test_arxiv_url_resource_id_none(self, manager):
+ """arXiv URL without valid ID and resource_id=None → 'unknown'."""
+ result = manager._generate_filename(
+ "https://arxiv.org/some/page", None, "fallback.pdf"
+ )
+ assert "unknown" in result
+ assert result.startswith("arxiv_")
+
+ def test_pubmed_url_without_pmc_id(self, manager):
+ """PMC URL without PMC ID → fallback with timestamp."""
+ result = manager._generate_filename(
+ "https://ncbi.nlm.nih.gov/pmc/articles/", 99, "fallback.pdf"
+ )
+ assert result.startswith("pubmed_")
+ assert "99" in result
+
+ def test_pubmed_url_resource_id_none(self, manager):
+ """PMC URL without PMC ID and resource_id=None → 'unknown'."""
+ result = manager._generate_filename(
+ "https://ncbi.nlm.nih.gov/pmc/articles/", None, "fallback.pdf"
+ )
+ assert "unknown" in result
+ assert result.startswith("pubmed_")
+
+ def test_url_with_no_hostname(self, manager):
+ """URL with empty hostname → returns fallback."""
+ result = manager._generate_filename(
+ "file:///local/path.pdf", 1, "fallback.pdf"
+ )
+ # file:// has empty hostname → not arxiv/pmc → fallback
+ assert result == "fallback.pdf"
+
+ def test_arxiv_subdomain_without_valid_id(self, manager):
+ """export.arxiv.org with no valid arXiv ID → fallback."""
+ result = manager._generate_filename(
+ "https://export.arxiv.org/noarxivid", 5, "fallback.pdf"
+ )
+ assert result.startswith("arxiv_")
+ assert "5" in result
+
+ def test_ncbi_non_pmc_path_returns_fallback(self, manager):
+ """ncbi.nlm.nih.gov but not /pmc path → returns fallback."""
+ result = manager._generate_filename(
+ "https://ncbi.nlm.nih.gov/pubmed/12345", 1, "fallback.pdf"
+ )
+ # path doesn't contain "/pmc" → not matched → fallback
+ assert result == "fallback.pdf"
+
+
+# ---------------------------------------------------------------------------
+# _infer_storage_mode edge cases
+# ---------------------------------------------------------------------------
+
+
+class TestInferStorageModeEdgeCases:
+ """Edge cases not covered by test_pdf_storage_manager_edge_cases.py."""
+
+ def test_document_no_blob_no_path_returns_none(self, manager):
+ doc = Mock()
+ doc.blob = None
+ doc.file_path = None
+ assert manager._infer_storage_mode(doc) == "none"
+
+ def test_document_without_blob_attribute(self, manager):
+ """Document that doesn't have blob attribute (no hasattr)."""
+ doc = Mock(spec=[]) # No attributes at all
+ doc.file_path = "pdfs/paper.pdf"
+ # hasattr(doc, "blob") is False → skips blob check → checks file_path
+ assert manager._infer_storage_mode(doc) == "filesystem"
+
+ def test_document_without_blob_attr_no_path(self, manager):
+ """Document without blob attribute AND no file_path."""
+ doc = Mock(spec=[])
+ doc.file_path = None
+ assert manager._infer_storage_mode(doc) == "none"
+
+ def test_document_empty_file_path_returns_none(self, manager):
+ """Empty string file_path is falsy → returns 'none'."""
+ doc = Mock()
+ doc.blob = None
+ doc.file_path = ""
+ assert manager._infer_storage_mode(doc) == "none"
+
+ def test_blob_takes_priority_over_file_path(self, manager):
+ """When both blob and file_path exist, blob wins → 'database'."""
+ doc = Mock()
+ doc.blob = Mock() # truthy
+ doc.file_path = "pdfs/paper.pdf"
+ assert manager._infer_storage_mode(doc) == "database"
diff --git a/tests/web/routes/test_metrics_analytics_logic.py b/tests/web/routes/test_metrics_analytics_logic.py
new file mode 100644
index 0000000000..cae432436f
--- /dev/null
+++ b/tests/web/routes/test_metrics_analytics_logic.py
@@ -0,0 +1,402 @@
+"""Unit tests for metrics_routes pure logic: _extract_domain, get_rating_analytics, get_link_analytics.
+
+These test the aggregation logic directly (mocking DB), not through HTTP endpoints.
+"""
+
+from unittest.mock import MagicMock, Mock, patch
+
+import pytest
+
+from local_deep_research.database.models import (
+ ResearchHistory,
+ ResearchResource,
+)
+from local_deep_research.domain_classifier import DomainClassification
+from local_deep_research.web.routes.metrics_routes import (
+ _extract_domain,
+ get_link_analytics,
+ get_rating_analytics,
+)
+
+
+# ---------------------------------------------------------------------------
+# _extract_domain
+# ---------------------------------------------------------------------------
+
+
+class TestExtractDomain:
+ """Tests for _extract_domain URL normalization."""
+
+ def test_normal_url(self):
+ assert _extract_domain("https://example.com/path") == "example.com"
+
+ def test_www_prefix_stripped(self):
+ assert _extract_domain("https://www.example.com") == "example.com"
+
+ def test_no_scheme_empty_netloc(self):
+ # urlparse("example.com") → netloc="", path="example.com"
+ assert _extract_domain("example.com") is None
+
+ def test_url_with_port(self):
+ assert (
+ _extract_domain("https://example.com:8080/path")
+ == "example.com:8080"
+ )
+
+ def test_none_raises_type_error(self):
+ """urlparse(None) returns bytes-based ParseResult; .startswith(str) raises TypeError.
+
+ This is an uncaught edge case — the except clause only catches
+ ValueError and AttributeError, not TypeError.
+ """
+ with pytest.raises(TypeError):
+ _extract_domain(None)
+
+ def test_empty_string_returns_none(self):
+ assert _extract_domain("") is None
+
+ def test_uppercase_normalized(self):
+ assert _extract_domain("https://EXAMPLE.COM/path") == "example.com"
+
+ def test_www_with_subdomain(self):
+ # Only leading "www." is stripped, not "www2."
+ assert (
+ _extract_domain("https://www.sub.example.com") == "sub.example.com"
+ )
+
+ def test_http_scheme(self):
+ assert _extract_domain("http://example.com/page?q=1") == "example.com"
+
+
+# ---------------------------------------------------------------------------
+# get_rating_analytics — pure logic
+# ---------------------------------------------------------------------------
+
+
+def _make_rating(value):
+ """Create a mock ResearchRating with a .rating attribute."""
+ r = Mock()
+ r.rating = value
+ return r
+
+
+def _mock_session_ctx(mock_ctx, session):
+ """Wire up get_user_db_session mock as context manager."""
+ mock_ctx.return_value.__enter__ = Mock(return_value=session)
+ mock_ctx.return_value.__exit__ = Mock(return_value=False)
+
+
+class TestGetRatingAnalyticsPureLogic:
+ """Tests for get_rating_analytics aggregation, mocking DB layer."""
+
+ @patch("local_deep_research.web.routes.metrics_routes.flask_session", {})
+ @patch("local_deep_research.web.routes.metrics_routes.get_user_db_session")
+ def test_no_username_returns_error(self, mock_ctx):
+ result = get_rating_analytics(username=None)
+ assert result["rating_analytics"]["error"] == "No user session"
+ assert result["rating_analytics"]["total_ratings"] == 0
+
+ @patch("local_deep_research.web.routes.metrics_routes.get_user_db_session")
+ def test_empty_ratings(self, mock_ctx):
+ session = MagicMock()
+ session.query.return_value.filter.return_value.all.return_value = []
+ _mock_session_ctx(mock_ctx, session)
+
+ result = get_rating_analytics(period="30d", username="alice")
+ analytics = result["rating_analytics"]
+ assert analytics["avg_rating"] is None
+ assert analytics["total_ratings"] == 0
+
+ @patch("local_deep_research.web.routes.metrics_routes.get_user_db_session")
+ def test_rating_distribution(self, mock_ctx):
+ ratings = [_make_rating(v) for v in [5, 5, 4, 3]]
+ session = MagicMock()
+ session.query.return_value.filter.return_value.all.return_value = (
+ ratings
+ )
+ _mock_session_ctx(mock_ctx, session)
+
+ result = get_rating_analytics(period="30d", username="alice")
+ dist = result["rating_analytics"]["rating_distribution"]
+ assert dist["5"] == 2
+ assert dist["4"] == 1
+ assert dist["3"] == 1
+ assert dist["2"] == 0
+ assert dist["1"] == 0
+
+ @patch("local_deep_research.web.routes.metrics_routes.get_user_db_session")
+ def test_average_rating(self, mock_ctx):
+ ratings = [_make_rating(v) for v in [5, 4, 3]]
+ session = MagicMock()
+ session.query.return_value.filter.return_value.all.return_value = (
+ ratings
+ )
+ _mock_session_ctx(mock_ctx, session)
+
+ result = get_rating_analytics(period="30d", username="alice")
+ assert result["rating_analytics"]["avg_rating"] == 4.0
+
+ @patch("local_deep_research.web.routes.metrics_routes.get_user_db_session")
+ def test_satisfaction_mapping(self, mock_ctx):
+ ratings = [_make_rating(v) for v in [5, 4, 3, 2, 1]]
+ session = MagicMock()
+ session.query.return_value.filter.return_value.all.return_value = (
+ ratings
+ )
+ _mock_session_ctx(mock_ctx, session)
+
+ result = get_rating_analytics(period="30d", username="alice")
+ sat = result["rating_analytics"]["satisfaction_stats"]
+ assert sat["very_satisfied"] == 1
+ assert sat["satisfied"] == 1
+ assert sat["neutral"] == 1
+ assert sat["dissatisfied"] == 1
+ assert sat["very_dissatisfied"] == 1
+
+ @patch("local_deep_research.web.routes.metrics_routes.get_user_db_session")
+ def test_period_all_no_time_filter(self, mock_ctx):
+ """period='all' → days=None → no time filter applied."""
+ ratings = [_make_rating(5)]
+ session = MagicMock()
+ query_mock = session.query.return_value
+ # When days is None, .all() is called directly (no .filter())
+ query_mock.all.return_value = ratings
+ _mock_session_ctx(mock_ctx, session)
+
+ result = get_rating_analytics(period="all", username="alice")
+ assert result["rating_analytics"]["total_ratings"] == 1
+ # filter should NOT be called when period is "all"
+ query_mock.filter.assert_not_called()
+
+ @patch("local_deep_research.web.routes.metrics_routes.get_user_db_session")
+ def test_unknown_period_defaults_to_30(self, mock_ctx):
+ """Unknown period string falls back to 30 days."""
+ session = MagicMock()
+ session.query.return_value.filter.return_value.all.return_value = []
+ _mock_session_ctx(mock_ctx, session)
+
+ # Should not raise — just uses default 30
+ result = get_rating_analytics(period="999d", username="alice")
+ assert result["rating_analytics"]["total_ratings"] == 0
+
+ @patch("local_deep_research.web.routes.metrics_routes.get_user_db_session")
+ def test_exception_returns_fallback(self, mock_ctx):
+ """Any exception → returns zero-count fallback dict."""
+ mock_ctx.return_value.__enter__ = Mock(
+ side_effect=RuntimeError("db error")
+ )
+ mock_ctx.return_value.__exit__ = Mock(return_value=False)
+
+ result = get_rating_analytics(period="30d", username="alice")
+ analytics = result["rating_analytics"]
+ assert analytics["avg_rating"] is None
+ assert analytics["total_ratings"] == 0
+
+ @patch("local_deep_research.web.routes.metrics_routes.get_user_db_session")
+ def test_total_ratings_count(self, mock_ctx):
+ ratings = [_make_rating(v) for v in [5, 5, 4, 4, 3]]
+ session = MagicMock()
+ session.query.return_value.filter.return_value.all.return_value = (
+ ratings
+ )
+ _mock_session_ctx(mock_ctx, session)
+
+ result = get_rating_analytics(period="7d", username="bob")
+ assert result["rating_analytics"]["total_ratings"] == 5
+
+
+# ---------------------------------------------------------------------------
+# get_link_analytics — pure logic
+# ---------------------------------------------------------------------------
+
+
+def _build_link_session(resources, classifications=None, researches=None):
+ """Build a mock session that handles multiple session.query(Model) calls.
+
+ get_link_analytics calls session.query with different models:
+ 1. ResearchResource → filter → all → resources
+ 2. DomainClassification → filter (in_) → all → classifications
+ 3. ResearchHistory → filter (in_) → all → researches
+ """
+ if classifications is None:
+ classifications = []
+ if researches is None:
+ researches = []
+
+ # Create separate query chain mocks for each model
+ resource_query = MagicMock()
+ resource_query.filter.return_value.all.return_value = resources
+ resource_query.all.return_value = resources
+
+ classification_query = MagicMock()
+ classification_query.filter.return_value.all.return_value = classifications
+
+ research_query = MagicMock()
+ research_query.filter.return_value.all.return_value = researches
+
+ session = MagicMock()
+
+ def query_dispatch(model):
+ if model is ResearchResource:
+ return resource_query
+ elif model is DomainClassification:
+ return classification_query
+ elif model is ResearchHistory:
+ return research_query
+ # Fallback for any other model
+ return MagicMock()
+
+ session.query.side_effect = query_dispatch
+ return session
+
+
+def _make_resource(
+ url,
+ research_id=1,
+ title=None,
+ preview=None,
+ created_at="2025-01-15T12:00:00",
+ source_type=None,
+):
+ r = Mock()
+ r.url = url
+ r.research_id = research_id
+ r.title = title
+ r.content_preview = preview
+ r.created_at = created_at
+ r.source_type = source_type
+ return r
+
+
+class TestGetLinkAnalyticsPureLogic:
+ """Tests for get_link_analytics aggregation, mocking DB layer."""
+
+ @patch("local_deep_research.web.routes.metrics_routes.flask_session", {})
+ @patch("local_deep_research.web.routes.metrics_routes.get_user_db_session")
+ def test_no_username_returns_error(self, mock_ctx):
+ result = get_link_analytics(username=None)
+ assert result["link_analytics"]["error"] == "No user session"
+ assert result["link_analytics"]["total_links"] == 0
+
+ @patch("local_deep_research.web.routes.metrics_routes.get_user_db_session")
+ def test_empty_resources(self, mock_ctx):
+ session = _build_link_session(resources=[])
+ _mock_session_ctx(mock_ctx, session)
+
+ result = get_link_analytics(period="30d", username="alice")
+ la = result["link_analytics"]
+ assert la["top_domains"] == []
+ assert la["total_unique_domains"] == 0
+ assert la["total_links"] == 0
+
+ @patch("local_deep_research.web.routes.metrics_routes.get_user_db_session")
+ def test_domain_counting(self, mock_ctx):
+ resources = [
+ _make_resource("https://example.com/a", research_id=1),
+ _make_resource("https://example.com/b", research_id=1),
+ _make_resource("https://example.com/c", research_id=2),
+ _make_resource("https://other.com/d", research_id=2),
+ ]
+ session = _build_link_session(resources=resources)
+ _mock_session_ctx(mock_ctx, session)
+
+ result = get_link_analytics(period="30d", username="alice")
+ la = result["link_analytics"]
+ assert la["total_links"] == 4
+ # example.com should be the top domain with count=3
+ top = la["top_domains"]
+ assert len(top) == 2
+ assert top[0]["domain"] == "example.com"
+ assert top[0]["count"] == 3
+
+ @patch("local_deep_research.web.routes.metrics_routes.get_user_db_session")
+ def test_avg_links_per_research(self, mock_ctx):
+ # 6 resources across 3 researches → avg = 2.0
+ resources = [
+ _make_resource(f"https://d{i}.com/p", research_id=(i % 3) + 1)
+ for i in range(6)
+ ]
+ session = _build_link_session(resources=resources)
+ _mock_session_ctx(mock_ctx, session)
+
+ result = get_link_analytics(period="30d", username="alice")
+ assert result["link_analytics"]["avg_links_per_research"] == 2.0
+
+ @patch("local_deep_research.web.routes.metrics_routes.get_user_db_session")
+ def test_temporal_date_slicing(self, mock_ctx):
+ resources = [
+ _make_resource("https://a.com/1", created_at="2025-01-15T12:00:00"),
+ _make_resource("https://a.com/2", created_at="2025-01-15T14:00:00"),
+ _make_resource("https://a.com/3", created_at="2025-01-16T10:00:00"),
+ ]
+ session = _build_link_session(resources=resources)
+ _mock_session_ctx(mock_ctx, session)
+
+ result = get_link_analytics(period="30d", username="alice")
+ trend = result["link_analytics"]["temporal_trend"]
+ # Two dates: 2025-01-15 (count=2) and 2025-01-16 (count=1)
+ assert len(trend) == 2
+ assert trend[0]["date"] == "2025-01-15"
+ assert trend[0]["count"] == 2
+ assert trend[1]["date"] == "2025-01-16"
+ assert trend[1]["count"] == 1
+
+ @patch("local_deep_research.web.routes.metrics_routes.get_user_db_session")
+ def test_top_10_domain_limit(self, mock_ctx):
+ # Create 12 unique domains
+ resources = [
+ _make_resource(f"https://domain{i}.com/p") for i in range(12)
+ ]
+ session = _build_link_session(resources=resources)
+ _mock_session_ctx(mock_ctx, session)
+
+ result = get_link_analytics(period="30d", username="alice")
+ # Should only return top 10
+ assert len(result["link_analytics"]["top_domains"]) == 10
+ assert result["link_analytics"]["total_unique_domains"] == 12
+
+ @patch("local_deep_research.web.routes.metrics_routes.get_user_db_session")
+ def test_percentage_calculation(self, mock_ctx):
+ resources = [
+ _make_resource("https://a.com/1"),
+ _make_resource("https://a.com/2"),
+ _make_resource("https://b.com/1"),
+ _make_resource("https://b.com/2"),
+ ]
+ session = _build_link_session(resources=resources)
+ _mock_session_ctx(mock_ctx, session)
+
+ result = get_link_analytics(period="30d", username="alice")
+ top = result["link_analytics"]["top_domains"]
+ # Each domain has 2/4 = 50%
+ for d in top:
+ assert d["percentage"] == 50.0
+
+ @patch("local_deep_research.web.routes.metrics_routes.get_user_db_session")
+ def test_source_type_tracking(self, mock_ctx):
+ resources = [
+ _make_resource("https://a.com/1", source_type="academic"),
+ _make_resource("https://b.com/1", source_type="academic"),
+ _make_resource("https://c.com/1", source_type="news"),
+ ]
+ session = _build_link_session(resources=resources)
+ _mock_session_ctx(mock_ctx, session)
+
+ result = get_link_analytics(period="30d", username="alice")
+ src = result["link_analytics"]["source_type_analysis"]
+ assert src["academic"] == 2
+ assert src["news"] == 1
+
+ @patch("local_deep_research.web.routes.metrics_routes.get_user_db_session")
+ def test_unique_domains_count(self, mock_ctx):
+ resources = [
+ _make_resource("https://a.com/1"),
+ _make_resource("https://a.com/2"),
+ _make_resource("https://b.com/1"),
+ _make_resource("https://c.com/1"),
+ ]
+ session = _build_link_session(resources=resources)
+ _mock_session_ctx(mock_ctx, session)
+
+ result = get_link_analytics(period="30d", username="alice")
+ assert result["link_analytics"]["total_unique_domains"] == 3