Beispiel #1
0
    def test_query_remove_last_None(self, prequests, config):
        response = Mock()
        response.status_code = 200
        response.json.return_value = [{
            'target': 'foo.bar',
            'datapoints': [[1, 1451391760], [None, 1451391770]]
        }]
        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)]
Beispiel #2
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 #3
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 #4
0
 def query(self):
     return GraphiteDataSource.METRIC_QUERY_CLS(**{
         'target': 'foo.bar',
         'since': '-24h',
         'until': '-12h'
     })
Beispiel #5
0
 def test_ok(self, prequests, config):
     response = Mock()
     response.status_code = 200
     prequests.get.return_value = response
     graphite = GraphiteDataSource(config)
     assert graphite.test() == True
Beispiel #6
0
 def test_requests_exception(self, prequests, config):
     prequests.get.side_effect = RequestException()
     graphite = GraphiteDataSource(config)
     assert graphite.test() == False
Beispiel #7
0
def config():
    return GraphiteDataSource.DATA_SOURCE_CONFIGURATION_CLS(**{
        'type': 'graphite',
        'name': 'datasource name',
        'url': 'http://localhost:9000'
    })
Beispiel #8
0
 def test_requests_exception(self, prequests, config, query):
     prequests.get.side_effect = RequestException()
     graphite = GraphiteDataSource(config)
     assert graphite.datapoints(query) == []