コード例 #1
0
    def test_get_empty_metrics_should_return_metrics_with_zeros(self):
        # given
        metrics_service.reset()

        # when
        result = metrics_service.get_empty_metrics()

        # then
        self.assertEqual(result, metrics_service.empty_stats)
コード例 #2
0
    def test_add_error_metric_to_metrics(self):
        # given
        metrics_service.reset()

        # when
        metrics_service.add(METRICS_NAME, ERRORS)
        result = metrics_service.get_currents_metrics()

        # then
        self.assertEqual(result[ERRORS][METRICS_NAME], 1)
        self.assertEqual(result[COUNT], 1)
コード例 #3
0
    def test_add_many_metrics(self):
        # given
        metrics_service.reset()

        # when
        metrics_service.add(METRICS_NAME, ERRORS)
        metrics_service.add(METRICS_NAME, OK)
        setup = metrics_service.get_currents_metrics()

        # then
        self.assertEqual(setup[ERRORS][METRICS_NAME], 1)
        self.assertEqual(setup[OK][METRICS_NAME], 1)
        self.assertEqual(setup[COUNT], 2)
コード例 #4
0
    def test_should_save_backup(self):
        # given
        metrics_service.reset()
        metrics_service.add(METRICS_NAME, ERRORS)
        metrics_service.add(METRICS_NAME, OK)
        setup = metrics_service.get_currents_metrics()

        # verify
        self.assertEqual(setup[ERRORS][METRICS_NAME], 1)
        self.assertEqual(setup[OK][METRICS_NAME], 1)
        self.assertEqual(setup[COUNT], 2)

        # when
        result = metrics_service.save_metrics()

        # then
        self.assertEqual(result, 'saved')
コード例 #5
0
    def test_reset_should_clear_metrics(self):
        # given
        metrics_service.reset()
        metrics_service.add(METRICS_NAME, ERRORS)
        metrics_service.add(METRICS_NAME, OK)
        setup = metrics_service.get_currents_metrics()

        # verify
        self.assertEqual(setup[ERRORS][METRICS_NAME], 1)
        self.assertEqual(setup[OK][METRICS_NAME], 1)
        self.assertEqual(setup[COUNT], 2)

        # when
        metrics_service.reset()
        result = metrics_service.get_currents_metrics()
        # then
        self.assertEqual(result[ERRORS][METRICS_NAME], 0)
        self.assertEqual(result[OK][METRICS_NAME], 0)
        self.assertEqual(result[COUNT], 0)
コード例 #6
0
    def test_add_not_existing_metric_result_do_not_change_counts(self):
        # given
        metrics_service.reset()
        metrics_service.add(METRICS_NAME, ERRORS)
        metrics_service.add(METRICS_NAME, OK)
        setup = metrics_service.get_currents_metrics()

        # verify
        self.assertEqual(setup[ERRORS][METRICS_NAME], 1)
        self.assertEqual(setup[OK][METRICS_NAME], 1)
        self.assertEqual(setup[COUNT], 2)

        # when
        metrics_service.add(METRICS_NAME, "UFO")

        # then
        result = metrics_service.get_currents_metrics()
        self.assertEqual(result[ERRORS][METRICS_NAME], 1)
        self.assertEqual(result[OK][METRICS_NAME], 1)
        self.assertEqual(result[COUNT], 2)