Example #1
0
 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'}))
Example #2
0
 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()
Example #3
0
 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())
Example #4
0
 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, {}))
Example #5
0
 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))
Example #6
0
 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)
Example #7
0
 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)
Example #8
0
 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)
Example #9
0
 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))
Example #10
0
 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)
Example #11
0
 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))
Example #12
0
 def test_setup(self):
     mock = MagicMock()
     queue = SqsReceiver(DUMMY, client=mock)
     queue.setup()
     self.assertIsNotNone(queue.client)
     mock.create_queue.assert_called()
Example #13
0
 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)