Added schema-based validation for default data and corrections

Part of bug 1210519

Change-Id: I7b5104b25fecc6a7da7c025bf48f72885c1fbebc
This commit is contained in:
Ilya Shakhat 2013-08-09 19:15:11 +04:00
parent f66505814e
commit f92dc49334
5 changed files with 218 additions and 1 deletions

View File

@ -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"]
}
}
}
}

View File

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

View File

@ -3,7 +3,7 @@
{
"launchpad_id": "foo",
"user_name": "Pupkin",
"emails": ["a@a"],
"emails": ["user@test.org"],
"companies": [
{
"company_name": "Uno",

View File

@ -7,6 +7,7 @@ hacking>=0.5.3,<0.7
coverage
discover
fixtures>=0.3.12
jsonschema
mock
python-subunit
testrepository>=0.0.13

View File

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