Beispiel #1
0
 def test_query(self, prequests, config, query):
     response = Mock()
     response.status_code = 200
     response.json.return_value = [{
         'target': 'foo.bar',
         'datapoints': [[1, 1451391760]]
     }]
     prequests.get.return_value = response
     graphite = GraphiteDataSource(config)
     assert graphite.datapoints(query) == [(1, 1451391760)]
     prequests.get.assert_called_with(
         'http://localhost:9000/render',
         params={'target': 'foo.bar',
                 'from': parse_date('-24h').strftime(DATE_FORMAT),
                 'to': parse_date('-12h').strftime(DATE_FORMAT),
                 'format': 'json'}
     )
Beispiel #2
0
    def test_query_default_values(self, prequests, config):
        response = Mock()
        response.status_code = 200
        response.json.return_value = [{
            'target': 'foo.bar',
            'datapoints': [[1, 1451391760]]
        }]
        prequests.get.return_value = response
        graphite = GraphiteDataSource(config)

        # build the mvp of query to be filled with the default ones
        query = GraphiteDataSource.METRIC_QUERY_CLS(**{
            'target': 'foo.bar'
        })

        assert graphite.datapoints(query) == [(1, 1451391760)]
        prequests.get.assert_called_with(
            'http://localhost:9000/render',
            params={'target': 'foo.bar',
                    'from': parse_date('-1h').strftime(DATE_FORMAT),
                    'to': parse_date('now').strftime(DATE_FORMAT),
                    'format': 'json'}
        )
Beispiel #3
0
 def test_1min(self):
     dt = datetime.now() - timedelta(minutes=1)
     assert parse_date('-1min').minute == dt.minute
Beispiel #4
0
 def test_now(self):
     dt = datetime.now()
     # skip milisecons
     assert parse_date('now').timetuple()[:-1] == dt.timetuple()[:-1]
Beispiel #5
0
 def get_until(self):
     """ Returns the date time used to collect data until
     :return: datetime
     """
     return parse_date(self.until or 'now')
Beispiel #6
0
 def get_since(self):
     """ Returns the date time used to collect data from
     :return: datetime
     """
     return parse_date(self.since or '-1h')
Beispiel #7
0
 def test_iso8601(self):
     dt = datetime.now()
     assert parse_date(dt.strftime("%Y-%m-%dT%H:%M:%S")).timetuple()[:-1] ==\
         dt.timetuple()[:-1]
Beispiel #8
0
 def test_1d(self):
     dt = datetime.now() - timedelta(days=1)
     assert parse_date('-1d').day == dt.day
Beispiel #9
0
 def test_1d(self):
     dt = datetime.now() - timedelta(days=1)
     assert parse_date('-1d').day == dt.day
Beispiel #10
0
 def test_1h(self):
     dt = datetime.now() - timedelta(hours=1)
     assert parse_date('-1h').hour == dt.hour
Beispiel #11
0
 def test_1s(self):
     dt = datetime.now() - timedelta(seconds=1)
     assert parse_date('-1s').second == dt.second
Beispiel #12
0
 def test_1min(self):
     dt = datetime.now() - timedelta(minutes=1)
     assert parse_date('-1min').minute == dt.minute
Beispiel #13
0
 def test_now(self):
     dt = datetime.now()
     # skip milisecons
     assert parse_date('now').timetuple()[:-1] == dt.timetuple()[:-1]
Beispiel #14
0
 def get_until(self):
     """ Returns the date time used to collect data until
     :return: datetime
     """
     return parse_date(self.until or "now")
Beispiel #15
0
 def get_since(self):
     """ Returns the date time used to collect data from
     :return: datetime
     """
     return parse_date(self.since or "-1h")
Beispiel #16
0
 def test_1s(self):
     dt = datetime.now() - timedelta(seconds=1)
     assert parse_date('-1s').second == dt.second
Beispiel #17
0
 def test_1h(self):
     dt = datetime.now() - timedelta(hours=1)
     assert parse_date('-1h').hour == dt.hour
Beispiel #18
0
 def test_timestamp(self):
     dt = datetime.now()
     assert parse_date(str(round(time.mktime(dt.timetuple()), 0))).timetuple()[:-1] ==\
         dt.timetuple()[:-1]
Beispiel #19
0
 def test_timestamp(self):
     dt = datetime.now()
     assert parse_date(str(round(time.mktime(dt.timetuple()), 0))).timetuple()[:-1] ==\
         dt.timetuple()[:-1]
Beispiel #20
0
 def test_iso8601(self):
     dt = datetime.now()
     assert parse_date(dt.strftime("%Y-%m-%dT%H:%M:%S")).timetuple()[:-1] ==\
         dt.timetuple()[:-1]
Beispiel #21
0
 def test_invalid(self):
     with pytest.raises(DateTimeInvalidValue):
         parse_date("asdfasdfasdf")
Beispiel #22
0
 def test_invalid(self):
     with pytest.raises(DateTimeInvalidValue):
         parse_date("asdfasdfasdf")