def test_delete_from_elasticsearch(self, mock_delete): """ Letter.delete_from_elasticsearch() should call ES_CLIENT.delete() """ letter = LetterFactory() letter.delete_from_elasticsearch(letter.pk) args, kwargs = mock_delete.call_args self.assertEqual(kwargs['id'], letter.pk, 'Letter.delete_from_elasticsearch() should call ES_CLIENT.delete()')
def test_calculate_custom_sentiment_without_mocks(self): """ Haven't yet figured out why Elasticsearch doesn't deliver the same score in test as in prod, so for now just make sure it doesn't cause an error """ sentiment = CustomSentimentFactory(name='OMG Ponies!', max_weight=2) TermFactory(text='pony', weight=2, custom_sentiment=sentiment) TermFactory(text='horse', weight=1, custom_sentiment=sentiment) letter = LetterFactory(date=ApproximateDate(1970, 1, 1), body='Look at the horse. Look at the pony.') # Make sure there's not already an indexed document with the same Id # because it might not have gotten cleaned up properly after a previous test if es_settings.ES_CLIENT.exists(index=[Letter._meta.es_index_name], id=letter.pk): letter.delete_from_elasticsearch(pk=letter.pk) letter.create_or_update_in_elasticsearch(is_new=None) calculate_custom_sentiment(letter_id=letter.id, sentiment_id=sentiment.id) letter.delete_from_elasticsearch(pk=letter.pk)