<commit_before><commit_msg>Added test for Post model and get_text_sentiment_analysis<commit_after>from django.test import TestCase

import requests
from mock import patch

from .models import Post
from .utils import get_text_sentiment_analysis


class PostTest(TestCase):

    def test_get_absolute_mood(self):
        post = Post(mood_positive=7, mood_negative=2)

        self.assertEqual(post.get_absolute_mood(), 5)

class TestSentimentAnalysis(TestCase):
    MOCK_NEGATIVE_RESPONSE= {'probability': {'pos': 0.234, 'neg':0.712, 'neutral': 0.456}, 'label': 'neg'}

    def test_get_text_sentiment_analysis(self):
        def mock_analysis_response(arg, argtwo):
            class Response(object):
                @staticmethod
                def json():
                    return self.MOCK_NEGATIVE_RESPONSE
            x = Response()
            return Response()

        with patch.object(requests, 'post', new=mock_analysis_response) as mock_method:
            not_realy_random_text = """
            get_text_sentiment_analysis
            """
            res = get_text_sentiment_analysis(not_realy_random_text)

            self.assertEqual(res['neg'], 7)
            self.assertEqual(res['pos'], 2)
            self.assertEqual(res['neutral'], 5)
            self.assertEqual(res['total'], 'neg')
{'fraction_non_alphanumeric': 0.10068649885583524, 'fraction_numerical': 0.013729977116704805, 'mean_word_length': 2.9047619047619047, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3708902', 'n_tokens_mistral': 399, 'n_tokens_neox': 372, 'n_words': 78}