Merge "Add unit test coverage for panels"

This commit is contained in:
Jenkins 2015-11-19 22:05:17 +00:00 committed by Gerrit Code Review
commit fd09f80b1e
7 changed files with 211 additions and 1 deletions

View File

@ -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)),
}

View File

View 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)

View 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)

View 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)

View 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)

View 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)