예제 #1
0
    def test_recent_history_length(self, mock_read_json):
        """ Test the length of recent history of a specific metric. """
        mock_read_json.return_value = {
            "dates": ["2013-02-28 17:01:45"] * 101,
            "metrics": {
                "OpenBugsNone": [{
                    "value": 10,
                    "start": "2013-02-28 17:01:45",
                    "end": "2013-02-28 17:01:45",
                    "status": "yellow"
                }, {
                    "value": 38,
                    "start": "2013-02-28 17:16:45",
                    "end": "2013-03-05 17:16:45",
                    "status": "red"
                }]
            },
            "statuses": [{
                "yellow": 1
            }, {
                "red": 1
            }, {
                "red": 1
            }]
        }
        history = CompactHistory('history_file_name.json')

        self.assertEqual(100, len(history.recent_history('OpenBugsNone')))
예제 #2
0
    def test_recent_history_when_metric_added_later(self, mock_read_json):
        """ Test the recent history of a specific metric. """

        mock_read_json.return_value = {
            "dates": [
                "2013-01-15 12:01:00", "2013-02-28 17:01:45",
                "2013-02-28 17:16:45", "2013-03-05 17:16:45"
            ],
            "metrics": {
                "OpenBugsNone": [{
                    "value": 10,
                    "start": "2013-02-28 17:01:45",
                    "end": "2013-02-28 17:01:45",
                    "status": "yellow"
                }, {
                    "value": 38,
                    "start": "2013-02-28 17:16:45",
                    "end": "2013-03-05 17:16:45",
                    "status": "red"
                }]
            },
            "statuses": [{
                "yellow": 1
            }, {
                "red": 1
            }, {
                "red": 1
            }]
        }
        history = CompactHistory('history_file_name.json')

        self.assertEqual([None, 10, 38, 38],
                         history.recent_history('OpenBugsNone'))
예제 #3
0
    def test_recent_history(self, mock_read_json):
        """ Test that the empty history file has no recent history. """
        mock_read_json.return_value = {
            "dates": [],
            "metrics": {},
            "statuses": []
        }
        history = CompactHistory('history_file_name.json')

        self.assertEqual([], history.recent_history('metric id'))
예제 #4
0
    def test_recent_history_when_metric_added_later(self, mock_read_json):
        """ Test the recent history of a specific metric. """
        history = {
            "dates": [
                "{y}-{m:02}-{d:02} 17:16:45".format(y=DT_3AGO.year,
                                                    m=DT_3AGO.month,
                                                    d=DT_3AGO.day),
                "{y}-{m:02}-{d:02} 17:21:45".format(y=DT_3AGO.year,
                                                    m=DT_3AGO.month,
                                                    d=DT_3AGO.day),
                "{y}-{m:02}-{d:02} 17:16:45".format(y=DT_NOW.year,
                                                    m=DT_NOW.month,
                                                    d=DT_NOW.day)
            ],
            "metrics": {
                "OpenBugsNone": [{
                    "value":
                    38,
                    "start":
                    "{y}-{m:02}-{d:02} 17:21:45".format(y=DT_3AGO.year,
                                                        m=DT_3AGO.month,
                                                        d=DT_3AGO.day),
                    "end":
                    "{y}-{m:02}-{d:02} 23:59:59".format(y=DT_NOW.year,
                                                        m=DT_NOW.month,
                                                        d=DT_NOW.day),
                    "status":
                    "red"
                }]
            },
            "statuses": [{
                "yellow": 1
            }, {
                "red": 1
            }, {
                "red": 1
            }]
        }

        mock_read_json.return_value = history
        history = CompactHistory('history_file_name.json')

        self.assertEqual([None, 38, 38],
                         history.recent_history('OpenBugsNone'))
예제 #5
0
    def test_recent_history_when_metric_added_later(self, mock_read_json):
        """ Test the recent history of a specific metric. """
        history = {
            "dates": [
                "{y}-{m:02}-{d:02} 17:16:45".format(y=DT_3AGO.year, m=DT_3AGO.month, d=DT_3AGO.day),
                "{y}-{m:02}-{d:02} 17:21:45".format(y=DT_3AGO.year, m=DT_3AGO.month, d=DT_3AGO.day),
                "{y}-{m:02}-{d:02} 17:16:45".format(y=DT_NOW.year, m=DT_NOW.month, d=DT_NOW.day)
            ],
            "metrics": {"OpenBugsNone": [
                {"value": 38,
                 "start": "{y}-{m:02}-{d:02} 17:21:45".format(y=DT_3AGO.year, m=DT_3AGO.month, d=DT_3AGO.day),
                 "end": "{y}-{m:02}-{d:02} 23:59:59".format(y=DT_NOW.year, m=DT_NOW.month, d=DT_NOW.day),
                 "status": "red"}]},
            "statuses": [{"yellow": 1}, {"red": 1}, {"red": 1}]
        }

        mock_read_json.return_value = history
        history = CompactHistory('history_file_name.json')

        self.assertEqual([None, 38, 38], history.recent_history('OpenBugsNone'))
예제 #6
0
    def test_missing_recent_history(self, mock_read_json):
        """ Test the recent history of a non-existing metric. """
        mock_read_json.return_value = COMPACT_HISTORY
        history = CompactHistory('history_file_name.json')

        self.assertEqual([], history.recent_history('Non existing'))
예제 #7
0
    def test_recent_history(self, mock_read_json):
        """ Test the recent history of a specific metric. """
        mock_read_json.return_value = COMPACT_HISTORY
        history = CompactHistory('history_file_name.json')

        self.assertEqual([10, 38, 38], history.recent_history('OpenBugsNone'))
예제 #8
0
    def test_recent_history(self, mock_read_json):
        """ Test the recent history of a specific metric. """
        mock_read_json.return_value = COMPACT_HISTORY
        history = CompactHistory('history_file_name.json')

        self.assertEqual([10, 38, 38], history.recent_history('OpenBugsNone'))
예제 #9
0
    def test_recent_history(self, mock_read_json):
        """ Test that the empty history file has no recent history. """
        mock_read_json.return_value = {"dates": [], "metrics": {}, "statuses": []}
        history = CompactHistory('history_file_name.json')

        self.assertEqual([], history.recent_history('metric id'))
예제 #10
0
    def test_missing_recent_history(self, mock_read_json):
        """ Test the recent history of a non-existing metric. """
        mock_read_json.return_value = COMPACT_HISTORY
        history = CompactHistory('history_file_name.json')

        self.assertEqual([], history.recent_history('Non existing'))