forked from brutasse/graphite-cyanite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
78 lines (66 loc) · 2.62 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from mock import patch
from unittest import TestCase
from cyanite import CyaniteFinder, chunk
from graphite_api.storage import FindQuery
class CyaniteTests(TestCase):
def test_conf(self):
config = {'cyanite': {'urls': ['http://host1:8080',
'http://host2:9090']}}
CyaniteFinder(config)
from cyanite import urls
self.assertEqual(urls.host, 'http://host1:8080')
self.assertEqual(urls.host, 'http://host2:9090')
self.assertEqual(urls.host, 'http://host1:8080')
@patch('requests.get')
def test_metrics(self, get):
get.return_value.json.return_value = [
{'path': 'foo.',
'leaf': 0},
{'path': 'foo.bar',
'leaf': 1},
]
finder = CyaniteFinder({'cyanite': {'url': 'http://host:8080'}})
query = FindQuery('foo.*', 50, 100)
branch, leaf = list(finder.find_nodes(query))
self.assertEqual(leaf.path, 'foo.bar')
self.assertEqual(branch.path, 'foo.')
get.assert_called_once_with('http://host:8080/paths',
params={'query': 'foo.*'})
get.reset_mock()
get.return_value.json.return_value = {
'from': 50,
'to': 100,
'step': 1,
'series': {'foo.bar': list(range(50))},
}
time_info, data = leaf.reader.fetch(50, 100)
self.assertEqual(time_info, (50, 100, 1))
self.assertEqual(data, list(range(50)))
get.assert_called_once_with('http://host:8080/metrics',
params={'to': 100,
'path': 'foo.bar',
'from': 50})
@patch('requests.get')
def test_fetch_multi(self, get):
get.return_value.json.return_value = [
{'path': 'foo.baz',
'leaf': 1},
{'path': 'foo.bar',
'leaf': 1},
]
finder = CyaniteFinder({'cyanite': {'url': 'http://host:8080'}})
query = FindQuery('foo.*', 50, 100)
nodes = list(finder.find_nodes(query))
get.reset_mock()
get.return_value.json.return_value = {
'from': 50,
'to': 100,
'step': 1,
'series': {'foo.bar': list(range(50)),
'foo.baz': list(range(50))},
}
time_info, series = finder.fetch_multi(nodes, 50, 100)
self.assertEqual(set(series.keys()), set(['foo.bar', 'foo.baz']))
def test_chunk(self):
mylist = range(1000, 9999)
self.assertEqual(len(list(chunk(mylist, 4))), 9000)