コード例 #1
0
ファイル: history_tests.py プロジェクト: ICTU/quality-report
    def test_add_metrics_invalid_numeric(self, mock_write_json, mock_read_json):
        """ Test that a metric with numeric value -1 does not record a value. """
        mock_write_json.return_value = None
        mock_read_json.return_value = {"dates": [], "metrics": {}, "statuses": []}
        history = CompactHistory('history_file_name.json')

        class ExampleMetric(object):
            """ Fake a metric. """

            @staticmethod
            def numerical_value():
                """ Return the value. """
                return -1

            @staticmethod
            def stable_id():
                """ Return the stable metric id. """
                return 'ExampleMetric'

            @staticmethod
            def status():
                """ Return the metric status. """
                return 'green'

        history.add_metrics(datetime.datetime(2015, 1, 1), [ExampleMetric()])

        self.assertTrue(history)
        mock_write_json.assert_called_once_with(
            {
                'dates': ['2015-01-01 00:00:00'],
                'metrics': {'ExampleMetric': [
                    {'start': '2015-01-01 00:00:00', 'end': '2015-01-01 00:00:00', 'status': 'green'}]},
                'statuses': [{'green': 1}]
            }, 'history_file_name.json'
        )
コード例 #2
0
    def test_add_metrics_with_previous_history(self, mock_write_json,
                                               mock_read_json):
        """ Test that a metric with a new status adds a record. """
        mock_write_json.return_value = None
        mock_read_json.return_value = {
            "dates": ["2013-02-28 17:01:45"],
            "metrics": {
                "ExampleMetric": [{
                    "value": 10,
                    "start": "2013-02-28 17:01:45",
                    "end": "2013-02-28 17:01:45",
                    "status": "yellow"
                }]
            },
            "statuses": []
        }
        history = CompactHistory('history_file_name.json')

        class ExampleMetric(object):
            """ Fake a metric. """
            @staticmethod
            def numerical_value():
                """ Return the value. """
                return 10

            @staticmethod
            def stable_id():
                """ Return the stable metric id. """
                return 'ExampleMetric'

            @staticmethod
            def status():
                """ Return the metric status. """
                return 'green'

        history.add_metrics(datetime.datetime(2015, 1, 1), [ExampleMetric()])

        self.assertTrue(history)
        mock_write_json.assert_called_once_with(
            {
                'dates': ['2013-02-28 17:01:45', '2015-01-01 00:00:00'],
                'metrics': {
                    'ExampleMetric': [{
                        'value': 10,
                        'start': '2013-02-28 17:01:45',
                        'end': '2013-02-28 17:01:45',
                        'status': 'yellow'
                    }, {
                        'start': '2015-01-01 00:00:00',
                        'end': '2015-01-01 00:00:00',
                        'status': 'green',
                        'value': 10
                    }]
                },
                'statuses': [{
                    'green': 1
                }]
            }, 'history_file_name.json')
コード例 #3
0
    def test_add_metrics_invalid_numeric(self, mock_write_json,
                                         mock_read_json):
        """ Test that a metric with numeric value -1 does not record a value. """
        mock_write_json.return_value = None
        mock_read_json.return_value = {
            "dates": [],
            "metrics": {},
            "statuses": []
        }
        history = CompactHistory('history_file_name.json')

        class ExampleMetric(object):
            """ Fake a metric. """
            @staticmethod
            def numerical_value():
                """ Return the value. """
                return -1

            @staticmethod
            def stable_id():
                """ Return the stable metric id. """
                return 'ExampleMetric'

            @staticmethod
            def status():
                """ Return the metric status. """
                return 'green'

        history.add_metrics(datetime.datetime(2015, 1, 1), [ExampleMetric()])

        self.assertTrue(history)
        mock_write_json.assert_called_once_with(
            {
                'dates': ['2015-01-01 00:00:00'],
                'metrics': {
                    'ExampleMetric': [{
                        'start': '2015-01-01 00:00:00',
                        'end': '2015-01-01 00:00:00',
                        'status': 'green'
                    }]
                },
                'statuses': [{
                    'green': 1
                }]
            }, 'history_file_name.json')
コード例 #4
0
ファイル: history_tests.py プロジェクト: ICTU/quality-report
    def test_add_metrics_with_previous_history(self, mock_write_json, mock_read_json):
        """ Test that a metric with a new status adds a record. """
        mock_write_json.return_value = None
        mock_read_json.return_value = {
            "dates": ["2013-02-28 17:01:45"],
            "metrics": {
                "ExampleMetric": [
                    {"value": 10, "start": "2013-02-28 17:01:45", "end": "2013-02-28 17:01:45", "status": "yellow"}
                ]
            },
            "statuses": []
        }
        history = CompactHistory('history_file_name.json')

        class ExampleMetric(object):
            """ Fake a metric. """
            @staticmethod
            def numerical_value():
                """ Return the value. """
                return 10

            @staticmethod
            def stable_id():
                """ Return the stable metric id. """
                return 'ExampleMetric'

            @staticmethod
            def status():
                """ Return the metric status. """
                return 'green'

        history.add_metrics(datetime.datetime(2015, 1, 1), [ExampleMetric()])

        self.assertTrue(history)
        mock_write_json.assert_called_once_with({
            'dates': ['2013-02-28 17:01:45', '2015-01-01 00:00:00'],
            'metrics': {'ExampleMetric': [
                {'value': 10, 'start': '2013-02-28 17:01:45', 'end': '2013-02-28 17:01:45', 'status': 'yellow'},
                {'start': '2015-01-01 00:00:00', 'end': '2015-01-01 00:00:00', 'status': 'green', 'value': 10}]},
            'statuses': [{'green': 1}]}, 'history_file_name.json')