def setUp(self): self.druid = DruidPlugin()
class TestDruidPlugin(TestCase): @classmethod def setUpClass(cls): settings.reconfigure( AttributeDict(**{ 'DRUID_URL': 'http://*****:*****@patch('pydruid.client.BaseDruidClient.timeseries') def test_execute(self, timeseries_mock): response = Mock() response.result = SAMPLE_DRUID_RESPONSE self.test_druid_check = DRUID_CHECK.copy() timeseries_mock.return_value = response with patch('alamo_worker.plugins.druid.DruidPlugin.process') as proc: self.druid.execute(self.test_druid_check) self.assertTrue(proc.called) proc.assert_called_once_with( self.test_druid_check, SAMPLE_DRUID_RESPONSE ) @patch('alamo_worker.plugins.druid.DruidPlugin.set_check_status') @patch('pydruid.client.BaseDruidClient.timeseries') def test_execute_with_error(self, timeseries_mock, set_mock): ex = IOError() timeseries_mock.side_effect = ex self.test_druid_check = DRUID_CHECK.copy() self.druid.execute(self.test_druid_check) self.assertTrue(set_mock.called) @unpack @data( { 'threshold': 1, 'hysteresis': 0.0, 'expected': { 'status': 1, 'hysteresis': 1, 'message': '[14] > 1.0' } }, { 'threshold': 15, 'hysteresis': 5.0, 'expected': { 'status': 0, 'hysteresis': 1, 'message': '[14] > (15.0 - 5.0 hysteresis)' } }, ) def test_process(self, threshold, hysteresis, expected): self.test_druid_check = DRUID_CHECK.copy() self.ts = SAMPLE_DRUID_RESPONSE.copy() self.test_druid_check['triggers'][0]['threshold'] = threshold self.test_druid_check['triggers'][0]['hysteresis'] = hysteresis trigger = self.test_druid_check['triggers'][0] self.druid.process(self.test_druid_check, self.ts) self.assertEqual(trigger['result']['status'], expected['status']) self.assertEqual(trigger['result']['message'], expected['message']) self.assertEqual( trigger['result']['hysteresis'], expected['hysteresis'] )