def test_real_web_send(self): mock = MagicMock() mock.get_secret.return_value = '' stats_client = StatsWebClient(secrets_manager=mock, http_client=HttpRequestor()) self.assertTrue( stats_client.add_gauge('odb', 20, {Constants.PRODUCT: 'odb'}))
def test_run(self): mock = MagicMock() queue = SqsReceiver(DUMMY, client=mock) queue.exit = True self.assertTrue(queue.run(mock)) self.assertTrue(queue.run()) queue.container = mock queue.start()
def test_purge(self): mock = MagicMock() client = Factory.create(Components.ServiceClients.SQS, queue_name=DUMMY, client=mock) self.assertTrue(client.purge()) mock.purge_queue.side_effect = Exception self.assertFalse(client.purge())
def test_timing(self): mock = MagicMock() stats_client = StatsWebClient(secrets_manager=mock, http_client=mock) self.assertTrue( stats_client.add_timing(Constants.DUMMY, Constants.DUMMY_NUM, {})) mock.get_secret.side_effect = Exception self.assertFalse( stats_client.add_timing(Constants.DUMMY, Constants.DUMMY_NUM, {}))
def test_update_increment(self): mock = MagicMock() mock.incr.side_effect = Exception stats_client = StatsLogClient(client=mock, secrets_manager=mock, http_client=mock) name = 'collection_failure' value = 1 self.assertFalse(stats_client.update_increment(name, value))
def test_add_gauge_no_tags(self): mock = MagicMock() stats_client = StatsLogClient(client=mock, secrets_manager=mock, http_client=mock) name = 'test_stat' value = 0 result = stats_client.add_gauge(name, value) mock.gauge.assert_called_once_with(name, value, delta=False, rate=1) self.assertTrue(result)
def test_add_gauge_exception(self): mock = MagicMock() mock.gauge.side_effect = Exception('test') stats_client = StatsLogClient(client=mock, secrets_manager=mock, http_client=mock) name = 'test_stat' value = 0 tags = {'tag1': 'tag1_value', 'tag2': 'tag2_value'} result = stats_client.add_gauge(name, value, tags) self.assertFalse(result)
def test_update_increment_no_tags(self): mock = MagicMock() mock.incr.return_value = True stats_client = StatsLogClient(client=mock, secrets_manager=mock, http_client=mock) name = 'collection_failure' value = 1 result = stats_client.update_increment(name, value) mock.incr.assert_called_once_with(name, value) self.assertTrue(result)
def test_add_timing(self): mock = MagicMock() stats_client = StatsLogClient(client=mock, secrets_manager=mock, http_client=mock) stats_client.add_timing(Constants.DUMMY, Constants.DUMMY_NUM) mock.timing.assert_called_once_with(Constants.DUMMY, Constants.DUMMY_NUM) mock.timing.side_effect = Exception self.assertFalse( stats_client.add_timing(Constants.DUMMY, Constants.DUMMY_NUM))
def test_add_gauge_defaults(self): mock = MagicMock() stats_client = StatsLogClient(client=mock, secrets_manager=mock, http_client=mock) name = 'test_stat' value = 0 tags = {'tag1': 'tag1_value', 'tag2': 'tag2_value'} result = stats_client.add_gauge(name, value, tags) mock.gauge.assert_called_once_with(name, value, delta=False, rate=1, tags=tags) self.assertTrue(result)
def test_full_queue(self): mock = MagicMock() mock.create_queue.return_value = mock mock.get_queue_by_name.return_value = mock mock.receive_message.return_value = MOCK_RESPONSE client = Factory.create(Components.ServiceClients.SQS, queue_name=DUMMY, client=mock) self.assertIsNotNone(client) self.assertTrue(client.send_message(TEST_MESSAGE)) mock.send_message.assert_called() message = client.receive_message() self.assertTrue(message) self.assertTrue(client.complete_message(message)) mock.send_message.side_effect = Exception self.assertFalse(client.send_message(TEST_MESSAGE)) mock.receive_message.side_effect = Exception self.assertFalse(client.receive_message()) mock.delete_message.side_effect = Exception self.assertFalse(client.complete_message(message))
def test_setup(self): mock = MagicMock() queue = SqsReceiver(DUMMY, client=mock) queue.setup() self.assertIsNotNone(queue.client) mock.create_queue.assert_called()
def test_get_web_api_key(self): mock = MagicMock() stats_client = StatsWebClient(secrets_manager=mock, http_client=mock) self.assertIsNotNone(stats_client.get_api_key()) self.assertEqual(stats_client.get_api_key(Constants.DUMMY), Constants.DUMMY)