Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
Added schema-based validation for default data and corrections
Browse files Browse the repository at this point in the history
Part of bug 1210519

Change-Id: I7b5104b25fecc6a7da7c025bf48f72885c1fbebc
  • Loading branch information
Ilya Shakhat committed Aug 9, 2013
1 parent f665058 commit f92dc49
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 1 deletion.
31 changes: 31 additions & 0 deletions etc/corrections.schema.json
Original file line number Diff line number Diff line change
@@ -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"]
}
}
}
}
146 changes: 146 additions & 0 deletions etc/default_data.schema.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}
2 changes: 1 addition & 1 deletion etc/test_default_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"launchpad_id": "foo",
"user_name": "Pupkin",
"emails": ["a@a"],
"emails": ["user@test.org"],
"companies": [
{
"company_name": "Uno",
Expand Down
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ hacking>=0.5.3,<0.7
coverage
discover
fixtures>=0.3.12
jsonschema
mock
python-subunit
testrepository>=0.0.13
Expand Down
39 changes: 39 additions & 0 deletions tests/unit/test_config_files.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit f92dc49

Please sign in to comment.