Skip to content

Commit

Permalink
Don't call highlight_for_custom_sentiment() if text is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
clairempr committed May 30, 2022
1 parent 4831a57 commit 513bfe4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions letters/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,11 @@ def test_highlight_for_sentiment(self, mock_highlight_for_custom_sentiment, mock
"highlight_for_sentiment() shouldn't call mock_highlight_text_for_sentiment() if sentiment_id isn't 0")
mock_highlight_for_custom_sentiment.reset_mock()

# If text is empty, highlight_for_custom_sentiment() should not be called
highlight_for_sentiment('', 1)
self.assertEqual(mock_highlight_for_custom_sentiment.call_count, 0,
'If text is empty, highlight_for_custom_sentiment() should not be called')


class SearchViewTestCase(TestCase):
"""
Expand Down
3 changes: 3 additions & 0 deletions letters/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ def highlight_for_sentiment(text, sentiment_id):
if sentiment_id == 0:
return [mark_safe(highlight) for highlight in highlight_text_for_sentiment(text)]

if not text:
return ['']

return [mark_safe(highlight_for_custom_sentiment(text, sentiment_id))]


Expand Down

0 comments on commit 513bfe4

Please sign in to comment.