From 547faf945ed4ca0b8039df6cb8563b1be0640bc3 Mon Sep 17 00:00:00 2001 From: James Harries Date: Fri, 31 Jan 2025 15:46:44 +0000 Subject: [PATCH 1/2] FCL-637 | only return true for matching ncn if there is an ncn --- judgments/tests/test_utils.py | 16 ++++++++++++++++ judgments/utils/utils.py | 5 ++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/judgments/tests/test_utils.py b/judgments/tests/test_utils.py index 632fa268f..8a724c0a9 100644 --- a/judgments/tests/test_utils.py +++ b/judgments/tests/test_utils.py @@ -12,6 +12,7 @@ formatted_document_uri, get_document_by_uri, get_press_summaries_for_document_uri, + is_exact_ncn_match, linked_doc_title, linked_doc_url, press_summary_list_breadcrumbs, @@ -95,6 +96,21 @@ def test_press_summary_list_breadcrumbs(self): }, ] + def test_is_exact_ncn_match_empty_ncn(self): + document = JudgmentFactory.build(neutral_citation=None) + + assert not is_exact_ncn_match(document, "foo") + + def test_is_exact_ncn_match_with_matching_ncn(self): + document = JudgmentFactory.build() + + assert is_exact_ncn_match(document, document.neutral_citation) + + def test_is_exact_ncn_match_with_unmatched_ncn(self): + document = JudgmentFactory.build() + + assert not is_exact_ncn_match(document, "foo") + @mock.patch("judgments.utils.utils.api_client") def test_get_press_summaries_for_document_uri(self, mock_api_client): summaries = [mock.Mock(), mock.Mock()] diff --git a/judgments/utils/utils.py b/judgments/utils/utils.py index fc6f0c61e..0994a6452 100644 --- a/judgments/utils/utils.py +++ b/judgments/utils/utils.py @@ -299,7 +299,10 @@ def preprocess_ncn(string: str) -> str: def is_exact_ncn_match(result, query: str) -> bool: - return preprocess_ncn(query) == preprocess_ncn(result.neutral_citation) + if result.neutral_citation: + return preprocess_ncn(query) == preprocess_ncn(result.neutral_citation) + + return False def search_results_have_exact_ncn(search_results, query: str) -> bool: From 5ed46b4d387883c699670a4bb5e49ae92a8257c1 Mon Sep 17 00:00:00 2001 From: James Harries Date: Mon, 3 Feb 2025 15:29:56 +0000 Subject: [PATCH 2/2] FCL-638 | update tests to be specific boolean values --- judgments/tests/test_utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/judgments/tests/test_utils.py b/judgments/tests/test_utils.py index 8a724c0a9..c444a5bf1 100644 --- a/judgments/tests/test_utils.py +++ b/judgments/tests/test_utils.py @@ -99,17 +99,17 @@ def test_press_summary_list_breadcrumbs(self): def test_is_exact_ncn_match_empty_ncn(self): document = JudgmentFactory.build(neutral_citation=None) - assert not is_exact_ncn_match(document, "foo") + assert is_exact_ncn_match(document, "foo") is False def test_is_exact_ncn_match_with_matching_ncn(self): document = JudgmentFactory.build() - assert is_exact_ncn_match(document, document.neutral_citation) + assert is_exact_ncn_match(document, document.neutral_citation) is True def test_is_exact_ncn_match_with_unmatched_ncn(self): document = JudgmentFactory.build() - assert not is_exact_ncn_match(document, "foo") + assert is_exact_ncn_match(document, "foo") is False @mock.patch("judgments.utils.utils.api_client") def test_get_press_summaries_for_document_uri(self, mock_api_client):