Browse Source

Add unit test coverage for panels

This also fixes a bug with our valueName field in a singlestat panel.

Change-Id: I4df8d130fce45cf58b01808997fc561cf8c4b42d
Signed-off-by: Paul Belanger <pabelanger@redhat.com>
tags/0.0.4^2
Paul Belanger 3 years ago
parent
commit
3b5ba508f7

+ 1
- 1
grafana_dashboards/schema/panel/singlestat.py View File

@@ -60,7 +60,7 @@ class Singlestat(Base):
60 60
             v.Required(
61 61
                 'valueFontSize', default='80%'): v.All(
62 62
                     v.Match(r'^[1-9]?[0]{1}%$|^1[0-9]?[0]{1}%$|^200%$')),
63
-            v.Required('valueName', default='avg'): v.All(
63
+            v.Required('valueName', default='avg'): v.Any(
64 64
                 'avg', 'current', 'max', 'min', 'total'),
65 65
             v.Optional('decimals'): v.All(int, v.Range(min=0, max=12)),
66 66
         }

+ 0
- 0
tests/schema/panels/__init__.py View File


+ 35
- 0
tests/schema/panels/test_base.py View File

@@ -0,0 +1,35 @@
1
+# Copyright 2015 Red Hat, Inc.
2
+#
3
+# Licensed under the Apache License, Version 2.0 (the "License");
4
+# you may not use this file except in compliance with the License.
5
+# You may obtain a copy of the License at
6
+#
7
+# http://www.apache.org/licenses/LICENSE-2.0
8
+#
9
+# Unless required by applicable law or agreed to in writing, software
10
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+# License for the specific language governing permissions and limitations
13
+# under the License.
14
+
15
+from testtools import TestCase
16
+
17
+from grafana_dashboards.schema.panel.base import Base
18
+
19
+
20
+class TestCaseBase(TestCase):
21
+
22
+    def setUp(self):
23
+        super(TestCaseBase, self).setUp()
24
+        self.schema = Base().get_schema()
25
+
26
+    def test_defaults(self):
27
+        # Ensure default values get parsed correctly.
28
+        defaults = {
29
+            'editable': True,
30
+            'error': False,
31
+            'span': 12,
32
+            'title': 'foobar',
33
+            'type': 'text',
34
+        }
35
+        self.assertEqual(self.schema(defaults), defaults)

+ 39
- 0
tests/schema/panels/test_dashlist.py View File

@@ -0,0 +1,39 @@
1
+# Copyright 2015 Red Hat, Inc.
2
+#
3
+# Licensed under the Apache License, Version 2.0 (the "License");
4
+# you may not use this file except in compliance with the License.
5
+# You may obtain a copy of the License at
6
+#
7
+# http://www.apache.org/licenses/LICENSE-2.0
8
+#
9
+# Unless required by applicable law or agreed to in writing, software
10
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+# License for the specific language governing permissions and limitations
13
+# under the License.
14
+
15
+from testtools import TestCase
16
+
17
+from grafana_dashboards.schema.panel.dashlist import Dashlist
18
+
19
+
20
+class TestCaseDashlist(TestCase):
21
+
22
+    def setUp(self):
23
+        super(TestCaseDashlist, self).setUp()
24
+        self.schema = Dashlist().get_schema()
25
+
26
+    def test_defaults(self):
27
+        # Ensure default values get parsed correctly.
28
+        defaults = {
29
+            'editable': True,
30
+            'error': False,
31
+            'limit': 10,
32
+            'mode': 'starred',
33
+            'query': '',
34
+            'span': 12,
35
+            'tag': '',
36
+            'title': 'foobar',
37
+            'type': 'dashlist',
38
+        }
39
+        self.assertEqual(self.schema(defaults), defaults)

+ 47
- 0
tests/schema/panels/test_graph.py View File

@@ -0,0 +1,47 @@
1
+# Copyright 2015 Red Hat, Inc.
2
+#
3
+# Licensed under the Apache License, Version 2.0 (the "License");
4
+# you may not use this file except in compliance with the License.
5
+# You may obtain a copy of the License at
6
+#
7
+# http://www.apache.org/licenses/LICENSE-2.0
8
+#
9
+# Unless required by applicable law or agreed to in writing, software
10
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+# License for the specific language governing permissions and limitations
13
+# under the License.
14
+
15
+from testtools import TestCase
16
+
17
+from grafana_dashboards.schema.panel.graph import Graph
18
+
19
+
20
+class TestCaseGraph(TestCase):
21
+
22
+    def setUp(self):
23
+        super(TestCaseGraph, self).setUp()
24
+        self.schema = Graph().get_schema()
25
+
26
+    def test_defaults(self):
27
+        # Ensure default values get parsed correctly.
28
+        defaults = {
29
+            'bars': False,
30
+            'editable': True,
31
+            'error': False,
32
+            'fill': 1,
33
+            'lines': True,
34
+            'linewidth': 2,
35
+            'percentage': False,
36
+            'pointradius': 5,
37
+            'points': False,
38
+            'span': 12,
39
+            'stack': False,
40
+            'steppedLine': False,
41
+            'targets': [],
42
+            'title': 'foobar',
43
+            'type': 'graph',
44
+            'x-axis': True,
45
+            'y-axis': True,
46
+        }
47
+        self.assertEqual(self.schema(defaults), defaults)

+ 52
- 0
tests/schema/panels/test_singlestat.py View File

@@ -0,0 +1,52 @@
1
+# Copyright 2015 Red Hat, Inc.
2
+#
3
+# Licensed under the Apache License, Version 2.0 (the "License");
4
+# you may not use this file except in compliance with the License.
5
+# You may obtain a copy of the License at
6
+#
7
+# http://www.apache.org/licenses/LICENSE-2.0
8
+#
9
+# Unless required by applicable law or agreed to in writing, software
10
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+# License for the specific language governing permissions and limitations
13
+# under the License.
14
+
15
+from testtools import TestCase
16
+
17
+from grafana_dashboards.schema.panel.singlestat import Singlestat
18
+
19
+
20
+class TestCaseSinglestat(TestCase):
21
+
22
+    def setUp(self):
23
+        super(TestCaseSinglestat, self).setUp()
24
+        self.schema = Singlestat().get_schema()
25
+
26
+    def test_defaults(self):
27
+        # Ensure default values get parsed correctly.
28
+        defaults = {
29
+            'colorBackground': False,
30
+            'colorValue': False,
31
+            'editable': True,
32
+            'error': False,
33
+            'maxDataPoints': 100,
34
+            'postfix': '',
35
+            'postfixFontSize': '50%',
36
+            'prefix': '',
37
+            'prefixFontSize': '50%',
38
+            'span': 12,
39
+            'sparkline': {
40
+                'fillColor': 'rgba(31, 118, 189, 0.18)',
41
+                'full': False,
42
+                'lineColor': 'rgb(31, 120, 193)',
43
+                'show': False
44
+            },
45
+            'targets': [],
46
+            'thresholds': '',
47
+            'title': 'foobar',
48
+            'type': 'singlestat',
49
+            'valueFontSize': '80%',
50
+            'valueName': 'avg',
51
+        }
52
+        self.assertEqual(self.schema(defaults), defaults)

+ 37
- 0
tests/schema/panels/test_text.py View File

@@ -0,0 +1,37 @@
1
+# Copyright 2015 Red Hat, Inc.
2
+#
3
+# Licensed under the Apache License, Version 2.0 (the "License");
4
+# you may not use this file except in compliance with the License.
5
+# You may obtain a copy of the License at
6
+#
7
+# http://www.apache.org/licenses/LICENSE-2.0
8
+#
9
+# Unless required by applicable law or agreed to in writing, software
10
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+# License for the specific language governing permissions and limitations
13
+# under the License.
14
+
15
+from testtools import TestCase
16
+
17
+from grafana_dashboards.schema.panel.text import Text
18
+
19
+
20
+class TestCaseText(TestCase):
21
+
22
+    def setUp(self):
23
+        super(TestCaseText, self).setUp()
24
+        self.schema = Text().get_schema()
25
+
26
+    def test_defaults(self):
27
+        # Ensure default values get parsed correctly.
28
+        defaults = {
29
+            'content': 'junk',
30
+            'editable': True,
31
+            'error': False,
32
+            'mode': 'markdown',
33
+            'span': 12,
34
+            'title': 'foobar',
35
+            'type': 'text',
36
+        }
37
+        self.assertEqual(self.schema(defaults), defaults)

Loading…
Cancel
Save