# Path: responsebot/listeners/tweepy_wrapper_listener.py
# class TweepyWrapperListener(StreamListener):
#     def __init__(self, listener, *args, **kwargs):
#         super(TweepyWrapperListener, self).__init__(*args, **kwargs)
# 
#         self.listener = listener
# 
#     def on_status(self, status):
#         self.listener.on_tweet(Tweet(status._json))
# 
#     def on_event(self, event):
#         self.listener.on_event(Event(event._json))
# 
# Path: responsebot/models.py
# class Event(object):
#     """
#     Represent a user events (e.g. following, unfollowing, etc.). See more `here <../guides/user_event_handling.html>`_
#     and `here <https://dev.twitter.com/streaming/overview/messages-types#Events_event>`_.
#     """
#     def __init__(self, data):
#         """
#         :param data: Parsed JSON data
#         :type data: dictionary
#         """
#         self.raw_data = data
# 
#         for key, value in data.items():
#             if key == 'target':
#                 setattr(self, key, User(value))
#             elif key == 'source':
#                 setattr(self, key, User(value))
#             elif key == 'created_at':
#                 setattr(self, key, parse(value))
#             else:
#                 setattr(self, key, value)
# 
#         setattr(self, 'target_object', self._parse_target_obj(data))
# 
#     def _parse_target_obj(self, data):
#         # TODO: parse target obj base on event
#         if data['event'] in ['follow', 'unfollow', 'block', 'unblock', 'user_update']:
#             return None
#         elif data['event'] in ['favorite', 'unfavorite', 'quoted_tweet']:
#             return Tweet(data['target_object'])
#         elif data['event'] in ['list_created', 'list_destroyed', 'list_updated', 'list_member_added',
#                 'list_member_removed', 'list_user_subscribed', 'list_user_unsubscribed']:
#             return List(data['target_object'])
#         return data.get('target_object')


from unittest.case import TestCase
from responsebot.listeners.tweepy_wrapper_listener import TweepyWrapperListener
from responsebot.models import Event
    from mock import MagicMock, patch
    from unittest.mock import MagicMock, patch


try:
except ImportError:


class TweepyWrapperListenerTestCase(TestCase):
    def test_call_generic_listener_on_tweet(self):
        generic_listener = MagicMock(on_tweet=MagicMock())
        status = MagicMock(_json={'some key': 'some value'})

        tweet_obj = 'tweet_obj'
        with patch('responsebot.listeners.tweepy_wrapper_listener.Tweet', return_value=tweet_obj) as mock_tweet_obj:
            TweepyWrapperListener(listener=generic_listener).on_status(status)

            mock_tweet_obj.assert_called_once_with(status._json)
            generic_listener.on_tweet.assert_called_once_with(tweet_obj)

    def test_call_generic_listener_on_event(self):
        generic_listener = MagicMock(on_event=MagicMock())
        event = MagicMock(_json={})
        event_wrapper = Event(event)

        with patch('responsebot.listeners.tweepy_wrapper_listener.Event', return_value=event_wrapper):

# Path: responsebot/listeners/tweepy_wrapper_listener.py
# class TweepyWrapperListener(StreamListener):
#     def __init__(self, listener, *args, **kwargs):
#         super(TweepyWrapperListener, self).__init__(*args, **kwargs)
# 
#         self.listener = listener
# 
#     def on_status(self, status):
#         self.listener.on_tweet(Tweet(status._json))
# 
#     def on_event(self, event):
#         self.listener.on_event(Event(event._json))
# 
# Path: responsebot/models.py
# class Event(object):
#     """
#     Represent a user events (e.g. following, unfollowing, etc.). See more `here <../guides/user_event_handling.html>`_
#     and `here <https://dev.twitter.com/streaming/overview/messages-types#Events_event>`_.
#     """
#     def __init__(self, data):
#         """
#         :param data: Parsed JSON data
#         :type data: dictionary
#         """
#         self.raw_data = data
# 
#         for key, value in data.items():
#             if key == 'target':
#                 setattr(self, key, User(value))
#             elif key == 'source':
#                 setattr(self, key, User(value))
#             elif key == 'created_at':
#                 setattr(self, key, parse(value))
#             else:
#                 setattr(self, key, value)
# 
#         setattr(self, 'target_object', self._parse_target_obj(data))
# 
#     def _parse_target_obj(self, data):
#         # TODO: parse target obj base on event
#         if data['event'] in ['follow', 'unfollow', 'block', 'unblock', 'user_update']:
#             return None
#         elif data['event'] in ['favorite', 'unfavorite', 'quoted_tweet']:
#             return Tweet(data['target_object'])
#         elif data['event'] in ['list_created', 'list_destroyed', 'list_updated', 'list_member_added',
#                 'list_member_removed', 'list_user_subscribed', 'list_user_unsubscribed']:
#             return List(data['target_object'])
#         return data.get('target_object')


# Path: tests/unit_tests/listeners/test_tweepy_wrapper_listener.py
from unittest.case import TestCase
from responsebot.listeners.tweepy_wrapper_listener import TweepyWrapperListener
from responsebot.models import Event
    from mock import MagicMock, patch
    from unittest.mock import MagicMock, patch



try:
except ImportError:


class TweepyWrapperListenerTestCase(TestCase):
    def test_call_generic_listener_on_tweet(self):
        generic_listener = MagicMock(on_tweet=MagicMock())
        status = MagicMock(_json={'some key': 'some value'})

        tweet_obj = 'tweet_obj'
        with patch('responsebot.listeners.tweepy_wrapper_listener.Tweet', return_value=tweet_obj) as mock_tweet_obj:
            TweepyWrapperListener(listener=generic_listener).on_status(status)

            mock_tweet_obj.assert_called_once_with(status._json)
            generic_listener.on_tweet.assert_called_once_with(tweet_obj)

    def test_call_generic_listener_on_event(self):
        generic_listener = MagicMock(on_event=MagicMock())
        event = MagicMock(_json={})
        event_wrapper = Event(event)

        with patch('responsebot.listeners.tweepy_wrapper_listener.Event', return_value=event_wrapper):

            TweepyWrapperListener(listener=generic_listener).on_event(event)