Skip to content

Commit

Permalink
Add unit test for clean_html not called (#1710)
Browse files Browse the repository at this point in the history
  • Loading branch information
blms committed Jan 13, 2025
1 parent d56ad15 commit 29e7bb6
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions geniza/corpus/tests/test_corpus_solrqueryset.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,22 @@ def test_get_highlighting__regex(self):
mock_get_results.return_value = [
{"id": "document.1", "transcription_regex": ["a test text"]}
]
highlighting = dqs.get_highlighting()
assert highlighting != test_highlight
assert "match" not in highlighting["document.1"]["transcription"]
assert len(highlighting["document.1"]["transcription"]) == 1
assert "<em>test</em>" in highlighting["document.1"]["transcription"][0]
with patch("geniza.corpus.solr_queryset.clean_html") as mock_clean_html:
highlighting = dqs.get_highlighting()
assert highlighting != test_highlight
assert "match" not in highlighting["document.1"]["transcription"]
assert len(highlighting["document.1"]["transcription"]) == 1
assert (
"<em>test</em>"
in highlighting["document.1"]["transcription"][0]
)
# in regex, clean_html should not be called
mock_clean_html.assert_not_called
# it should stil be called in other types of searches
mock_get_results.return_value = [
{"id": "document.1", "transcription_nostem": ["a test text"]}
]
mock_clean_html.assert_called_once

def test_regex_search(self):
dqs = DocumentSolrQuerySet()
Expand Down

0 comments on commit 29e7bb6

Please sign in to comment.