-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_dashjson.py
More file actions
executable file
·126 lines (105 loc) · 4.66 KB
/
test_dashjson.py
File metadata and controls
executable file
·126 lines (105 loc) · 4.66 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env python
from unittest import TestCase, main
from unittest.mock import Mock
from dashjson import TimeboardHandler, ScreenboardHandler
import json
import textwrap
class TestTimeboardHandler(TestCase):
def setUp(self):
self.api_mock = Mock()
self.handler = TimeboardHandler(self.api_mock)
def tearDown(self):
pass
def test_fromjson(self):
timeboard_str = textwrap.dedent('''\
{
"dash": {
"graphs": [
{
"definition": {
"viz": "timeseries",
"requests": [
{
"q": "avg:system.cpu.user{*}",
"style": {
"palette": "dog_classic",
"width": "normal",
"type": "solid"
},
"type": "line"
}
]
},
"title": "Avg of system.cpu.user over *"
}
],
"template_variables": [],
"description": "test timeboard description",
"title": "Test Timeboard Title",
"new_id": "xyz-5q5-abc",
"id": 4711
}
}
''')
dash_json = json.loads(timeboard_str)
new_board = False
self.handler.fromjson(dash_json, new_board)
self.api_mock.update.assert_called_with(4711, title='Test Timeboard Title', description='test timeboard description', graphs=dash_json['dash']['graphs'], template_variables=[])
new_board = True
self.handler.fromjson(dash_json, new_board)
self.api_mock.create.assert_called_with(title='Test Timeboard Title', description='test timeboard description', graphs=dash_json['dash']['graphs'], template_variables=[])
def test_tojson(self):
self.handler.tojson(4711)
self.api_mock.get.assert_called_once_with(4711)
class TestScreenboardHandler(TestCase):
def setUp(self):
self.api_mock = Mock()
self.handler = ScreenboardHandler(self.api_mock)
def tearDown(self):
pass
def test_fromjson(self):
screenboard_str = textwrap.dedent('''\
{
"board_title": "Test Screenboard Title",
"description": "test screenboard description",
"widgets": [
{
"board_id": 4711,
"title_align": "left",
"title_size": 16,
"title": true,
"generated_title": "system.load.1",
"title_text": "",
"height": 13,
"tile_def": {
"viz": "query_value",
"requests": [
{
"q": "avg:system.load.1{*}",
"aggregator": "avg",
"style": {
"width": "normal",
"palette": "dog_classic",
"type": "solid"
},
"type": null
}
]
}
}
],
"id": 4711
}
''')
dash_json = json.loads(screenboard_str)
new_board = False
self.handler.fromjson(dash_json, new_board)
self.api_mock.update.assert_called_with(4711, board_title='Test Screenboard Title', widgets=dash_json['widgets'], template_variables=[])
new_board = True
self.handler.fromjson(dash_json, new_board)
self.api_mock.create.assert_called_with(board_title='Test Screenboard Title', widgets=dash_json['widgets'], template_variables=[])
def test_tojson(self):
self.handler.tojson(4711)
self.api_mock.get.assert_called_once_with(4711)
if __name__ == '__main__':
main()