def setUp(self): patcher1 = patch('charlesbot.robot.Robot.initialize_robot') self.addCleanup(patcher1.stop) self.mock_initialize_robot = patcher1.start() from charlesbot.robot import Robot self.robot = Robot()
def main(args=None): logging.basicConfig( stream=sys.stdout, level=logging.INFO, format='%(asctime)s: %(levelname)s [%(name)s:%(lineno)d] %(message)s') log = logging.getLogger(__name__) log.info("Starting CharlesBOT now!") slackbot = Robot() slackbot.start()
def main(args=None): logging.basicConfig( stream=sys.stdout, level=logging.INFO, format='%(asctime)s: %(levelname)s [%(name)s:%(lineno)d] %(message)s' ) log = logging.getLogger(__name__) log.info("Starting CharlesBOT now!") slackbot = Robot() slackbot.start()
class TestRobot(asynctest.TestCase): def setUp(self): patcher1 = patch('charlesbot.robot.Robot.initialize_robot') self.addCleanup(patcher1.stop) self.mock_initialize_robot = patcher1.start() from charlesbot.robot import Robot self.robot = Robot() @asynctest.ignore_loop def test_exit_cleanly_no_plugins(self): self.robot.plugin_list = [] self.robot.exit_cleanly() self.assertEqual(self.robot.is_running(), False) @asynctest.ignore_loop def test_exit_cleanly_multiple_plugins(self): plugin1 = MagicMock() plugin2 = MagicMock() self.robot.plugin_list = [plugin1, plugin2] self.robot.exit_cleanly() self.assertEqual(self.robot.is_running(), False) self.assertFalse(plugin1.is_running) self.assertFalse(plugin2.is_running) def test_queue_message_empty_msg_1(self): plugin1 = MagicMock() msg = "" yield from self.robot.queue_message(msg, plugin1) self.assertEqual(plugin1.method_calls, []) def test_queue_message_empty_msg_2(self): plugin1 = MagicMock() msg = [] yield from self.robot.queue_message(msg, plugin1) self.assertEqual(plugin1.method_calls, []) def test_queue_message_actual_msg_1(self): plugin1 = MagicMock() msg = "HelloPlugin" yield from self.robot.queue_message(msg, plugin1) expected = call.queue_message('HelloPlugin') self.assertEqual(plugin1.method_calls, [expected]) def test_queue_message_actual_msg_2(self): plugin1 = MagicMock() msg = ["HelloPlugin"] yield from self.robot.queue_message(msg, plugin1) expected = call.queue_message(['HelloPlugin']) self.assertEqual(plugin1.method_calls, [expected])
class TestRobotInitializePlugin(unittest.TestCase): def setUp(self): patcher1 = patch('charlesbot.robot.Robot.initialize_robot') self.addCleanup(patcher1.stop) self.mock_initialize_robot = patcher1.start() from charlesbot.robot import Robot self.robot = Robot() def test_empty_enabled_plugins_list(self): self.robot.enabled_plugins = [] enabled_list = self.robot.initialize_plugins() self.assertEqual(enabled_list, []) def test_dummy_class_loader(self): self.robot.enabled_plugins = ['charlesbot.robot.Robot'] enabled_list = self.robot.initialize_plugins() self.assertEqual(len(enabled_list), 1)
def setUp(self): patcher1 = patch('charlesbot.robot.Robot.initialize_robot') self.addCleanup(patcher1.stop) self.mock_initialize_robot = patcher1.start() patcher2 = patch('charlesbot.robot.Robot.is_running') self.addCleanup(patcher2.stop) self.mock_is_running = patcher2.start() self.mock_slack = MagicMock() self.mock_slack.get_stream_messages = CoroutineMock() patcher3 = patch('charlesbot.robot.Robot.queue_message') self.addCleanup(patcher3.stop) self.mock_queue_message = patcher3.start() from charlesbot.robot import Robot self.robot = Robot() self.robot.slack = self.mock_slack self.mock_is_running.side_effect = [True, False] # single iteration
class TestRobotHelpMessages(asynctest.TestCase): def setUp(self): patcher1 = patch('charlesbot.robot.Robot.initialize_robot') self.addCleanup(patcher1.stop) self.mock_initialize_robot = patcher1.start() from charlesbot.robot import Robot self.robot = Robot() @asynctest.ignore_loop def test_empty_plugin_list(self): self.robot.plugin_list = [] self.robot.initialize_static_plugins() self.assertEqual(len(self.robot.plugin_list), 2) @asynctest.ignore_loop def test_plugin_list_one_entry(self): plugin1 = MagicMock() self.robot.plugin_list = [plugin1] self.robot.initialize_static_plugins() self.assertEqual(len(self.robot.plugin_list), 3) @asynctest.ignore_loop def test_plugin_list_two_entries(self): plugin1 = MagicMock() plugin2 = MagicMock() self.robot.plugin_list = [plugin1, plugin2] self.robot.initialize_static_plugins() self.assertEqual(len(self.robot.plugin_list), 4)
class TestRobotRouteMessageToPlugin(asynctest.TestCase): def setUp(self): patcher1 = patch('charlesbot.robot.Robot.initialize_robot') self.addCleanup(patcher1.stop) self.mock_initialize_robot = patcher1.start() patcher2 = patch('charlesbot.robot.Robot.is_running') self.addCleanup(patcher2.stop) self.mock_is_running = patcher2.start() self.mock_slack = MagicMock() self.mock_slack.get_stream_messages = CoroutineMock() patcher3 = patch('charlesbot.robot.Robot.queue_message') self.addCleanup(patcher3.stop) self.mock_queue_message = patcher3.start() from charlesbot.robot import Robot self.robot = Robot() self.robot.slack = self.mock_slack self.mock_is_running.side_effect = [True, False] # single iteration def test_no_msgs_returned_from_stream(self): self.mock_slack.get_stream_messages.return_value = [] yield from self.robot.produce() self.assertEqual(self.mock_queue_message.mock_calls, []) def test_multiple_produce_iterations(self): self.mock_is_running.side_effect = [True, True, False] self.mock_slack.get_stream_messages.return_value = [] yield from self.robot.produce() self.assertEqual(self.mock_queue_message.mock_calls, []) def test_single_msg_empty_plugin_list(self): self.mock_slack.get_stream_messages.return_value = ['msg1'] self.robot.plugin_list = [] yield from self.robot.produce() self.assertEqual(self.mock_queue_message.mock_calls, []) def test_single_msg_one_plugin(self): self.mock_slack.get_stream_messages.return_value = ['msg1'] self.robot.plugin_list = ['plug1'] yield from self.robot.produce() expected_call_1 = call('msg1', 'plug1') self.assertTrue(len(self.mock_queue_message.mock_calls), 1) self.assertTrue(expected_call_1 in self.mock_queue_message.mock_calls) def test_single_msg_multiple_plugins(self): self.mock_slack.get_stream_messages.return_value = ['msg1'] self.robot.plugin_list = ['plug1', 'plug2'] yield from self.robot.produce() expected_call_1 = call('msg1', 'plug1') expected_call_2 = call('msg1', 'plug2') self.assertTrue(len(self.mock_queue_message.mock_calls), 2) self.assertTrue(expected_call_1 in self.mock_queue_message.mock_calls) self.assertTrue(expected_call_2 in self.mock_queue_message.mock_calls) def test_multiple_msgs_empty_plugin_list(self): self.mock_slack.get_stream_messages.return_value = ['msg1', 'msg2'] self.robot.plugin_list = [] yield from self.robot.produce() self.assertEqual(self.mock_queue_message.mock_calls, []) def test_multiple_msgs_one_plugin(self): self.mock_slack.get_stream_messages.return_value = ['msg1', 'msg2'] self.robot.plugin_list = ['plug1'] yield from self.robot.produce() expected_call_1 = call('msg1', 'plug1') expected_call_2 = call('msg2', 'plug1') self.assertTrue(len(self.mock_queue_message.mock_calls), 2) self.assertTrue(expected_call_1 in self.mock_queue_message.mock_calls) self.assertTrue(expected_call_2 in self.mock_queue_message.mock_calls) def test_multiple_msgs_multiple_plugins(self): self.mock_slack.get_stream_messages.return_value = ['msg1', 'msg2'] self.robot.plugin_list = ['plug1', 'plug2'] yield from self.robot.produce() expected_call_1 = call('msg1', 'plug1') expected_call_2 = call('msg2', 'plug1') expected_call_3 = call('msg1', 'plug2') expected_call_4 = call('msg2', 'plug2') self.assertTrue(len(self.mock_queue_message.mock_calls), 4) self.assertTrue(expected_call_1 in self.mock_queue_message.mock_calls) self.assertTrue(expected_call_2 in self.mock_queue_message.mock_calls) self.assertTrue(expected_call_3 in self.mock_queue_message.mock_calls) self.assertTrue(expected_call_4 in self.mock_queue_message.mock_calls)