Пример #1
0
    def test_end_uses_metric_value_on_metric_value_not_none(
            self, mock_acts_blackbox):
        result = Mock()
        expected_result = Mock()
        mock_acts_blackbox.return_value = result

        logger = BlackboxMetricLogger(self.TEST_METRIC_NAME)
        logger.context = self.context
        logger.context.identifier = 'Class.test'
        logger.publisher = self.publisher
        logger.metric_value = expected_result
        logger.end(self.event)

        self.assertEqual(result.metric_value, expected_result)
Пример #2
0
    def test_end_populates_result(self, mock_acts_blackbox):
        result = Mock()
        mock_acts_blackbox.return_value = result

        logger = BlackboxMetricLogger(self.TEST_METRIC_NAME)
        logger.context = self.context
        logger.publisher = self.publisher
        logger.context.identifier = 'Class.test'
        logger.metric_value = 'foo'

        logger.end(self.event)

        self.assertEqual(result.test_identifier, 'Class#test')
        self.assertEqual(result.metric_key,
                         '%s.%s' % ('Class#test', self.TEST_METRIC_NAME))
        self.assertEqual(result.metric_value, logger.metric_value)
Пример #3
0
    def test_end_uses_custom_metric_key(self, mock_acts_blackbox):
        result = Mock()
        mock_acts_blackbox.return_value = result
        metric_key = 'metric_key'

        logger = BlackboxMetricLogger(self.TEST_METRIC_NAME,
                                      metric_key=metric_key)
        logger.context = self.context
        logger.publisher = self.publisher
        logger._get_blackbox_identifier = self._get_blackbox_identifier
        logger.metric_value = 'foo'

        logger.end(self.event)

        expected_metric_key = '%s.%s' % (metric_key, self.TEST_METRIC_NAME)
        self.assertEqual(result.metric_key, expected_metric_key)
Пример #4
0
    def test_end_does_publish(self, mock_acts_blackbox, proto_metric_cls):
        result = Mock()
        mock_acts_blackbox.return_value = result
        metric_key = 'metric_key'

        logger = BlackboxMetricLogger(self.TEST_METRIC_NAME,
                                      metric_key=metric_key)
        logger.context = self.context
        logger.publisher = self.publisher
        logger._get_blackbox_identifier = self._get_blackbox_identifier
        logger.metric_value = 'foo'

        logger.end(self.event)

        proto_metric_cls.assert_called_once_with(name=self.TEST_FILE_NAME,
                                                 data=result)
        self.publisher.publish.assert_called_once_with(
            [proto_metric_cls.return_value])