diff --git a/etc/corrections.schema.json b/etc/corrections.schema.json new file mode 100644 index 000000000..8bb79ac94 --- /dev/null +++ b/etc/corrections.schema.json @@ -0,0 +1,31 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "required": ["corrections"], + "properties": { + "corrections": { + "type": "array", + "items": { + "type": "object", + "properties": { + "primary_key": { + "type": "string" + }, + "loc": { + "type": "integer" + }, + "correction_comment": { + "type": "string" + }, + "module": { + "type": "string" + }, + "subject": { + "type": "string" + } + }, + "required": ["primary_key", "correction_comment", "module", "subject"] + } + } + } +} \ No newline at end of file diff --git a/etc/default_data.schema.json b/etc/default_data.schema.json new file mode 100644 index 000000000..f6e224e52 --- /dev/null +++ b/etc/default_data.schema.json @@ -0,0 +1,146 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "required": ["users", "releases", "companies", "repos"], + "properties": { + "users": { + "type": "array", + "items": { + "type": "object", + "properties": { + "launchpad_id": { + "type": "string" + }, + "user_name": { + "type": "string" + }, + "emails": { + "type": "array", + "items": { + "type": "string", + "pattern": "[\\w\\d_\\.-]+@([\\w\\d_\\.-]+\\.)+[\\w]+" + }, + "minItems": 1 + }, + "companies": { + "type": "array", + "items": { + "type": "object", + "properties": { + "company_name": { + "type": "string" + }, + "end_date": { + "type": ["string", "null"] + } + } + } + } + }, + "required": ["launchpad_id", "user_name", "emails"], + "additionalProperties": false + } + }, + "releases": { + "type": "array", + "items": { + "type": "object", + "properties": { + "release_name": { + "type": "string" + }, + "end_date": { + "type": "string", + "pattern": "20\\d{2}-\\w{3}-[0-3]\\d" + } + }, + "required": ["release_name", "end_date"], + "additionalProperties": false + } + }, + "repos": { + "type": "array", + "items": { + "type": "object", + "properties": { + "uri": { + "type": "string" + }, + "project_type": { + "type": "string" + }, + "project_group": { + "type": "string" + }, + "module": { + "type": "string" + }, + "branches": { + "type": "array", + "items": { + "type": "string" + } + }, + "releases": { + "type": "array", + "items": { + "type": "object", + "properties": { + "tag_from": { + "type": "string" + }, + "tag_to": { + "type": "string" + }, + "release_name": { + "type": "string" + } + }, + "required": ["tag_from", "tag_to", "release_name"] + } + } + }, + "required": ["uri", "project_type", "module", "branches"], + "additionalProperties": false + } + }, + "companies": { + "type": "array", + "items": { + "type": "object", + "properties": { + "company_name": { + "type": "string" + }, + "domains": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "required": ["company_name", "domains"], + "additionalProperties": false + } + }, + "project_sources": { + "type": "array", + "items": { + "type": "object", + "properties": { + "organization": { + "type": "string" + }, + "project_type": { + "type": "string" + }, + "project_group": { + "type": ["string", "null"] + } + }, + "required": ["organization", "project_type"], + "additionalProperties": false + } + } + } +} \ No newline at end of file diff --git a/etc/test_default_data.json b/etc/test_default_data.json index bd6a4dacb..d3466a4ef 100644 --- a/etc/test_default_data.json +++ b/etc/test_default_data.json @@ -3,7 +3,7 @@ { "launchpad_id": "foo", "user_name": "Pupkin", - "emails": ["a@a"], + "emails": ["user@test.org"], "companies": [ { "company_name": "Uno", diff --git a/test-requirements.txt b/test-requirements.txt index 881c03712..2b77eba81 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -7,6 +7,7 @@ hacking>=0.5.3,<0.7 coverage discover fixtures>=0.3.12 +jsonschema mock python-subunit testrepository>=0.0.13 diff --git a/tests/unit/test_config_files.py b/tests/unit/test_config_files.py new file mode 100644 index 000000000..7e751ca54 --- /dev/null +++ b/tests/unit/test_config_files.py @@ -0,0 +1,39 @@ +# Copyright (c) 2013 Mirantis 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 json + +import jsonschema +import testtools + + +class TestConfigFiles(testtools.TestCase): + def setUp(self): + super(TestConfigFiles, self).setUp() + + def _read_file(self, file_name): + with open(file_name, 'r') as content_file: + content = content_file.read() + return json.loads(content) + + def test_corrections(self): + corrections = self._read_file('etc/corrections.json') + schema = self._read_file('etc/corrections.schema.json') + jsonschema.validate(corrections, schema) + + def test_default_data(self): + default_data = self._read_file('etc/default_data.json') + schema = self._read_file('etc/default_data.schema.json') + jsonschema.validate(default_data, schema)