diff --git a/grafana_dashboards/tests/__init__.py b/grafana_dashboards/schema/__init__.py similarity index 100% rename from grafana_dashboards/tests/__init__.py rename to grafana_dashboards/schema/__init__.py diff --git a/grafana_dashboards/schema/panel.py b/grafana_dashboards/schema/panel.py new file mode 100644 index 0000000..1a2b4ae --- /dev/null +++ b/grafana_dashboards/schema/panel.py @@ -0,0 +1,42 @@ +# 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. + +import voluptuous as v + + +class BasePanel(object): + + def validate(self, data): + panel = { + v.Required('editable', default=True): v.All(bool), + v.Required('error', default=False): v.All(bool), + v.Required('span', default=12): v.All(int, v.Range(min=0, max=12)), + v.Required('title'): v.All(str, v.Length(min=1)), + v.Required('type'): v.All(str), + v.Optional('id'): int, + } + panel.update(self.fields) + schema = v.Schema({ + 'panels': [panel] + }) + + return schema(data) + + +class Text(BasePanel): + fields = { + v.Required('content'): v.All(str), + v.Required('mode'): v.All(str), + v.Optional('style'): dict(), + } diff --git a/grafana_dashboards/tests/test_grafana_dashboards.py b/grafana_dashboards/tests/test_grafana_dashboards.py deleted file mode 100644 index 33b6122..0000000 --- a/grafana_dashboards/tests/test_grafana_dashboards.py +++ /dev/null @@ -1,28 +0,0 @@ -# -*- coding: utf-8 -*- - -# 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. - -""" -test_grafana_dashboards ----------------------------------- - -Tests for `grafana_dashboards` module. -""" - -from grafana_dashboards.tests import base - - -class TestGrafana_dashboards(base.TestCase): - - def test_something(self): - pass diff --git a/requirements.txt b/requirements.txt index 95137a6..8c4753b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,6 @@ pbr>=0.6,!=0.7,<1.0 Babel>=1.3 + +PyYAML>=3.1.0 +voluptuous>=0.7 diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/grafana_dashboards/tests/base.py b/tests/base.py similarity index 100% rename from grafana_dashboards/tests/base.py rename to tests/base.py diff --git a/tests/schema/__init__.py b/tests/schema/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/schema/fixtures/text-no-title.yaml b/tests/schema/fixtures/text-no-title.yaml new file mode 100644 index 0000000..156bfba --- /dev/null +++ b/tests/schema/fixtures/text-no-title.yaml @@ -0,0 +1,10 @@ +panels: + - type: text + title: no title (click here) + error: false + editable: true + span: 12 + id: 1 + mode: markdown + content: '' + style: {} diff --git a/tests/schema/test_panel.py b/tests/schema/test_panel.py new file mode 100644 index 0000000..6c7a647 --- /dev/null +++ b/tests/schema/test_panel.py @@ -0,0 +1,32 @@ +# 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. + +import os +import yaml + +from testtools import TestCase + +from grafana_dashboards.schema import panel + +FIXTURE_DIR = os.path.join(os.path.dirname(__file__), + 'fixtures') + + +class TestCaseSchemaPanel(TestCase): + def test_layouts(self): + for fn in os.listdir(os.path.join(FIXTURE_DIR)): + layout = os.path.join(FIXTURE_DIR, fn) + data = yaml.load(open(layout)) + schema = panel.Text() + schema.validate(data)