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>
This commit is contained in:
parent
7a84b4e064
commit
3b5ba508f7
@ -60,7 +60,7 @@ class Singlestat(Base):
|
||||
v.Required(
|
||||
'valueFontSize', default='80%'): v.All(
|
||||
v.Match(r'^[1-9]?[0]{1}%$|^1[0-9]?[0]{1}%$|^200%$')),
|
||||
v.Required('valueName', default='avg'): v.All(
|
||||
v.Required('valueName', default='avg'): v.Any(
|
||||
'avg', 'current', 'max', 'min', 'total'),
|
||||
v.Optional('decimals'): v.All(int, v.Range(min=0, max=12)),
|
||||
}
|
||||
|
0
tests/schema/panels/__init__.py
Normal file
0
tests/schema/panels/__init__.py
Normal file
35
tests/schema/panels/test_base.py
Normal file
35
tests/schema/panels/test_base.py
Normal file
@ -0,0 +1,35 @@
|
||||
# Copyright 2015 Red Hat, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from testtools import TestCase
|
||||
|
||||
from grafana_dashboards.schema.panel.base import Base
|
||||
|
||||
|
||||
class TestCaseBase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestCaseBase, self).setUp()
|
||||
self.schema = Base().get_schema()
|
||||
|
||||
def test_defaults(self):
|
||||
# Ensure default values get parsed correctly.
|
||||
defaults = {
|
||||
'editable': True,
|
||||
'error': False,
|
||||
'span': 12,
|
||||
'title': 'foobar',
|
||||
'type': 'text',
|
||||
}
|
||||
self.assertEqual(self.schema(defaults), defaults)
|
39
tests/schema/panels/test_dashlist.py
Normal file
39
tests/schema/panels/test_dashlist.py
Normal file
@ -0,0 +1,39 @@
|
||||
# Copyright 2015 Red Hat, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from testtools import TestCase
|
||||
|
||||
from grafana_dashboards.schema.panel.dashlist import Dashlist
|
||||
|
||||
|
||||
class TestCaseDashlist(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestCaseDashlist, self).setUp()
|
||||
self.schema = Dashlist().get_schema()
|
||||
|
||||
def test_defaults(self):
|
||||
# Ensure default values get parsed correctly.
|
||||
defaults = {
|
||||
'editable': True,
|
||||
'error': False,
|
||||
'limit': 10,
|
||||
'mode': 'starred',
|
||||
'query': '',
|
||||
'span': 12,
|
||||
'tag': '',
|
||||
'title': 'foobar',
|
||||
'type': 'dashlist',
|
||||
}
|
||||
self.assertEqual(self.schema(defaults), defaults)
|
47
tests/schema/panels/test_graph.py
Normal file
47
tests/schema/panels/test_graph.py
Normal file
@ -0,0 +1,47 @@
|
||||
# Copyright 2015 Red Hat, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from testtools import TestCase
|
||||
|
||||
from grafana_dashboards.schema.panel.graph import Graph
|
||||
|
||||
|
||||
class TestCaseGraph(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestCaseGraph, self).setUp()
|
||||
self.schema = Graph().get_schema()
|
||||
|
||||
def test_defaults(self):
|
||||
# Ensure default values get parsed correctly.
|
||||
defaults = {
|
||||
'bars': False,
|
||||
'editable': True,
|
||||
'error': False,
|
||||
'fill': 1,
|
||||
'lines': True,
|
||||
'linewidth': 2,
|
||||
'percentage': False,
|
||||
'pointradius': 5,
|
||||
'points': False,
|
||||
'span': 12,
|
||||
'stack': False,
|
||||
'steppedLine': False,
|
||||
'targets': [],
|
||||
'title': 'foobar',
|
||||
'type': 'graph',
|
||||
'x-axis': True,
|
||||
'y-axis': True,
|
||||
}
|
||||
self.assertEqual(self.schema(defaults), defaults)
|
52
tests/schema/panels/test_singlestat.py
Normal file
52
tests/schema/panels/test_singlestat.py
Normal file
@ -0,0 +1,52 @@
|
||||
# Copyright 2015 Red Hat, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from testtools import TestCase
|
||||
|
||||
from grafana_dashboards.schema.panel.singlestat import Singlestat
|
||||
|
||||
|
||||
class TestCaseSinglestat(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestCaseSinglestat, self).setUp()
|
||||
self.schema = Singlestat().get_schema()
|
||||
|
||||
def test_defaults(self):
|
||||
# Ensure default values get parsed correctly.
|
||||
defaults = {
|
||||
'colorBackground': False,
|
||||
'colorValue': False,
|
||||
'editable': True,
|
||||
'error': False,
|
||||
'maxDataPoints': 100,
|
||||
'postfix': '',
|
||||
'postfixFontSize': '50%',
|
||||
'prefix': '',
|
||||
'prefixFontSize': '50%',
|
||||
'span': 12,
|
||||
'sparkline': {
|
||||
'fillColor': 'rgba(31, 118, 189, 0.18)',
|
||||
'full': False,
|
||||
'lineColor': 'rgb(31, 120, 193)',
|
||||
'show': False
|
||||
},
|
||||
'targets': [],
|
||||
'thresholds': '',
|
||||
'title': 'foobar',
|
||||
'type': 'singlestat',
|
||||
'valueFontSize': '80%',
|
||||
'valueName': 'avg',
|
||||
}
|
||||
self.assertEqual(self.schema(defaults), defaults)
|
37
tests/schema/panels/test_text.py
Normal file
37
tests/schema/panels/test_text.py
Normal file
@ -0,0 +1,37 @@
|
||||
# Copyright 2015 Red Hat, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from testtools import TestCase
|
||||
|
||||
from grafana_dashboards.schema.panel.text import Text
|
||||
|
||||
|
||||
class TestCaseText(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestCaseText, self).setUp()
|
||||
self.schema = Text().get_schema()
|
||||
|
||||
def test_defaults(self):
|
||||
# Ensure default values get parsed correctly.
|
||||
defaults = {
|
||||
'content': 'junk',
|
||||
'editable': True,
|
||||
'error': False,
|
||||
'mode': 'markdown',
|
||||
'span': 12,
|
||||
'title': 'foobar',
|
||||
'type': 'text',
|
||||
}
|
||||
self.assertEqual(self.schema(defaults), defaults)
|
Loading…
x
Reference in New Issue
Block a user