diff --git a/letters/tests/test_views.py b/letters/tests/test_views.py index 71abee4..2eb3fb8 100644 --- a/letters/tests/test_views.py +++ b/letters/tests/test_views.py @@ -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): """ diff --git a/letters/views.py b/letters/views.py index 8d236ae..a3b1f6a 100644 --- a/letters/views.py +++ b/letters/views.py @@ -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))]