Skip to content

Commit

Permalink
Merge pull request #1797 from nationalarchives/FCL-637/only-match-ncn…
Browse files Browse the repository at this point in the history
…-when-it-exists

FCL-637 | only return true for matching ncn if there is an ncn
  • Loading branch information
jacksonj04 authored Feb 4, 2025
2 parents 808af6c + 5ed46b4 commit ad9bd3f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
16 changes: 16 additions & 0 deletions judgments/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 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) is True

def test_is_exact_ncn_match_with_unmatched_ncn(self):
document = JudgmentFactory.build()

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):
summaries = [mock.Mock(), mock.Mock()]
Expand Down
5 changes: 4 additions & 1 deletion judgments/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit ad9bd3f

Please sign in to comment.