diff --git a/site/tests/moderation/test_domains.py b/site/tests/moderation/test_domains.py index c8895f956..7c74a418d 100644 --- a/site/tests/moderation/test_domains.py +++ b/site/tests/moderation/test_domains.py @@ -39,3 +39,17 @@ def test_lookup_domain(domains, domain, expected_status): assert LinkDomain.lookup_domain(domain) is None else: assert LinkDomain.lookup_domain(domain).status == expected_status + + +@pytest.mark.parametrize( + "stored,expected", + [ + (".io.blog", "blog.io"), + (".io.blog.spam", "spam.blog.io"), + (".ch.edu", "edu.ch"), + (".cam", "cam"), + ], +) +def test_domain_name(stored, expected): + """Domain names are exposed in display order.""" + assert LinkDomain(domain=stored).domain_name == expected diff --git a/site/tests/moderation/test_moderation_tasks.py b/site/tests/moderation/test_moderation_tasks.py new file mode 100644 index 000000000..6d677a7e1 --- /dev/null +++ b/site/tests/moderation/test_moderation_tasks.py @@ -0,0 +1,59 @@ +# SPDX-FileCopyrightText: 2024-2026 CERN +# SPDX-License-Identifier: GPL-3.0-or-later +"""Tests for moderation tasks.""" + +from zenodo_rdm.moderation.tasks import _render_breakdown + + +def test_render_breakdown_groups_drivers_by_rule(): + """Only score-moving reasons are listed, grouped under their rule subtotal.""" + results = { + "link_rule": { + "label": "Links", + "score": 13, + "reasons": [ + {"score": 5, "label": "7 links in description"}, + {"score": 8, "label": "link to spam domain bad.ru"}, + ], + }, + # rule that fired nothing is omitted entirely + "metadata_spam_indicators_rule": { + "label": "Metadata spam indicators", + "score": 0, + "reasons": [{"score": 0, "label": "2 emoji in metadata"}], + }, + } + assert _render_breakdown(results) == ( + "