<commit_before># -*- coding: utf-8 -*-
import json
import unittest
import mock

from twitter_watcher.observers import ObserverTwitter
from twitter_watcher.actions import Callback


class TwitterObserverTestCase(unittest.TestCase):

    def load_fixtures(self):
        fixtures = open('tests/fixtures/tweets.json', 'r')
        twitter_json_list = json.load(fixtures)
        return twitter_json_list

    def test_subclass_of_action_callback(self):
        assert issubclass(ObserverTwitter, Callback)

    def test_have_a_on_message_method(self):
        assert hasattr(ObserverTwitter, 'on_message')
        assert callable(ObserverTwitter.on_message)

    def test_raise_value_error_for_username_not_a_list(self):
        try:
            ObserverTwitter(url_callback='http://teste.com',
                            usernames='',
                            hashtags=[])
            assert False
        except ValueError:
            assert True

    def test_raise_value_error_for_hashtags_not_a_list(self):
        try:
            ObserverTwitter(url_callback='http://teste.com',
                            usernames=[],
                            hashtags='tests')
            assert False
        except ValueError:
            assert True

    def test_send_message_to_callback_url(self):

        tweets = self.load_fixtures()
        tweet = tweets[0]

        observer = ObserverTwitter(url_callback='http://teste.com',
                                   usernames=['@twitterapi'],
                                   hashtags=[])

        observer.send = mock.MagicMock(return_value=True)
        observer.on_message(tweet)
        observer.send.assert_called_once_with()<commit_msg>Adding a test for check if dont call send method in observer twitter<commit_after># -*- coding: utf-8 -*-
import json
import unittest
import mock

from twitter_watcher.observers import ObserverTwitter
from twitter_watcher.actions import Callback


class TwitterObserverTestCase(unittest.TestCase):

    def load_fixtures(self):
        fixtures = open('tests/fixtures/tweets.json', 'r')
        twitter_json_list = json.load(fixtures)
        return twitter_json_list

    def test_subclass_of_action_callback(self):
        assert issubclass(ObserverTwitter, Callback)

    def test_have_a_on_message_method(self):
        assert hasattr(ObserverTwitter, 'on_message')
        assert callable(ObserverTwitter.on_message)

    def test_raise_value_error_for_username_not_a_list(self):
        try:
            ObserverTwitter(url_callback='http://teste.com',
                            usernames='',
                            hashtags=[])
            assert False
        except ValueError:
            assert True

    def test_raise_value_error_for_hashtags_not_a_list(self):
        try:
            ObserverTwitter(url_callback='http://teste.com',
                            usernames=[],
                            hashtags='tests')
            assert False
        except ValueError:
            assert True

    def test_send_message_to_callback_url(self):

        tweets = self.load_fixtures()
        tweet = tweets[0]

        observer = ObserverTwitter(url_callback='http://teste.com',
                                   usernames=['@twitterapi'],
                                   hashtags=[])

        observer.send = mock.MagicMock(return_value=True)
        observer.on_message(tweet)
        observer.send.assert_called_once_with()


    def test_dont_call_send_on_message(self):

        tweets = self.load_fixtures()
        tweet = tweets[0]

        observer = ObserverTwitter(url_callback='http://teste.com',
                                   usernames=['@aoqfonseca'],
                                   hashtags=[])

        observer.send = mock.MagicMock(return_value=True)
        observer.on_message(tweet)
        assert observer.send.call_count == 0
{'fraction_non_alphanumeric': 0.0839340885684861, 'fraction_numerical': 0.001544799176107106, 'mean_word_length': 2.153409090909091, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7196832', 'n_tokens_mistral': 1106, 'n_tokens_neox': 1049, 'n_words': 183}