# Path: performanceplatform/utils/data_pusher.py
# class Pusher(object):
#     def __init__(self, target_data_set_config, options):
#         self.data_set_client = DataSet.from_config(target_data_set_config)
#         self.chunk_size = options.get('chunk-size', 100)
#         self.empty_data_set = options.get('empty-data-set', False)
# 
#     def push(self, data):
#         if data:
#             if self.empty_data_set:
#                 self.data_set_client.empty_data_set()
#             self.data_set_client.post(
#                 data, chunk_size=self.chunk_size)
#         else:
#             logging.info("Doing nothing - no data to push")


import unittest
from performanceplatform.utils.data_pusher import \
    Pusher
from mock import patch, Mock
from hamcrest import assert_that, equal_to


@patch('performanceplatform.utils.data_pusher.DataSet.from_config')
class TestPusher(unittest.TestCase):
    def setUp(self):
        self.data_set_config = {'beep': 'boop'}
        self.data = {'some': 'data'}

    def test_Pusher_init_sets_up_client_correctly(self, mock_from_config):
        Pusher(self.data_set_config, {})
        mock_from_config.assert_called_once_with(self.data_set_config)

    def test_pushes_with_default_chunk_100(self, mock_from_config):
        mock_data_set_client = Mock()
        mock_from_config.return_value = mock_data_set_client

# Path: performanceplatform/utils/data_pusher.py
# class Pusher(object):
#     def __init__(self, target_data_set_config, options):
#         self.data_set_client = DataSet.from_config(target_data_set_config)
#         self.chunk_size = options.get('chunk-size', 100)
#         self.empty_data_set = options.get('empty-data-set', False)
# 
#     def push(self, data):
#         if data:
#             if self.empty_data_set:
#                 self.data_set_client.empty_data_set()
#             self.data_set_client.post(
#                 data, chunk_size=self.chunk_size)
#         else:
#             logging.info("Doing nothing - no data to push")


# Path: tests/performanceplatform/utils/test_data_pusher.py
import unittest
from performanceplatform.utils.data_pusher import \
    Pusher
from mock import patch, Mock
from hamcrest import assert_that, equal_to



@patch('performanceplatform.utils.data_pusher.DataSet.from_config')
class TestPusher(unittest.TestCase):
    def setUp(self):
        self.data_set_config = {'beep': 'boop'}
        self.data = {'some': 'data'}

    def test_Pusher_init_sets_up_client_correctly(self, mock_from_config):
        Pusher(self.data_set_config, {})
        mock_from_config.assert_called_once_with(self.data_set_config)

    def test_pushes_with_default_chunk_100(self, mock_from_config):
        mock_data_set_client = Mock()
        mock_from_config.return_value = mock_data_set_client

        Pusher(self.data_set_config, {}).push(self.data)