From 7a94c9eeeeb327265676e6899a8ef646ea8ffe67 Mon Sep 17 00:00:00 2001 From: Ken'ichi Ohmichi Date: Thu, 6 Apr 2017 11:37:48 -0700 Subject: [PATCH] Make the schema of default_data hard-coded default_data.schema.json can be used for checking the config file default_data.json. The check will be able to block an error on stackalytics-processor internally. The schema should not exist as a config file, so this patch makes the schema hard-coded. NOTE: The copyright of schema.py comes from the initial version of default_data.schema.json: I7b5104b25fecc6a7da7c025bf48f72885c1fbebc Change-Id: Ia98c6d9ce2cec3bac80ff9159f854b1a65b6a4d8 --- .../processor/schema.py | 39 +++++++++++++------ stackalytics/tests/unit/test_config_files.py | 4 +- 2 files changed, 30 insertions(+), 13 deletions(-) rename etc/default_data.schema.json => stackalytics/processor/schema.py (86%) diff --git a/etc/default_data.schema.json b/stackalytics/processor/schema.py similarity index 86% rename from etc/default_data.schema.json rename to stackalytics/processor/schema.py index 1a639cebe..fb2e877dd 100644 --- a/etc/default_data.schema.json +++ b/stackalytics/processor/schema.py @@ -1,4 +1,19 @@ -{ +# 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. + +default_data = { "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "required": ["users", "releases", "companies", "repos", "project_types"], @@ -31,7 +46,8 @@ "type": "array", "items": { "type": "string", - "pattern": "^[a-z\\d_\\.\\+-]+@([a-z\\d\\.-]+\\.)*(([a-z]+)|\\(none\\))$" + "pattern": ("^[a-z\\d_\\.\\+-]+@([a-z\\d\\.-]+\\.)" + "*(([a-z]+)|\\(none\\))$") }, "minItems": 1 }, @@ -48,13 +64,13 @@ } }, "required": ["company_name", "end_date"], - "additionalProperties": false + "additionalProperties": False }, "minItems": 1 } }, "required": ["user_name", "emails"], - "additionalProperties": false + "additionalProperties": False } }, "releases": { @@ -73,7 +89,7 @@ } }, "required": ["release_name", "end_date"], - "additionalProperties": false + "additionalProperties": False } }, "repos": { @@ -122,7 +138,7 @@ } }, "required": ["uri", "module", "organization"], - "additionalProperties": false + "additionalProperties": False } }, "companies": { @@ -148,7 +164,7 @@ } }, "required": ["company_name", "domains"], - "additionalProperties": false + "additionalProperties": False } }, "project_sources": { @@ -185,7 +201,7 @@ } }, "required": ["organization"], - "additionalProperties": false + "additionalProperties": False } }, "module_groups": { @@ -205,7 +221,7 @@ } }, "required": ["module_group_name", "modules"], - "additionalProperties": false + "additionalProperties": False } }, "mail_lists": { @@ -244,14 +260,15 @@ } }, "required": ["id", "title", "modules"], - "additionalProperties": false + "additionalProperties": False } } }, "definitions": { "date_format": { "type": ["string", "null"], - "pattern": "^20\\d{2}-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-[0-3]\\d$" + "pattern": ("^20\\d{2}-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|" + "Nov|Dec)-[0-3]\\d$") } } } diff --git a/stackalytics/tests/unit/test_config_files.py b/stackalytics/tests/unit/test_config_files.py index acb447a67..6395071b0 100644 --- a/stackalytics/tests/unit/test_config_files.py +++ b/stackalytics/tests/unit/test_config_files.py @@ -23,6 +23,7 @@ import six import testtools from stackalytics.processor import normalizer +from stackalytics.processor import schema as coded_schema IGNORED_COMPANIES = ['*robots', 'April', 'Chelsio Communications', @@ -97,9 +98,8 @@ class TestConfigFiles(testtools.TestCase): def _verify_default_data_by_schema(self, file_name): default_data = self._read_file(file_name) - schema = self._read_file('etc/default_data.schema.json') try: - jsonschema.validate(default_data, schema) + jsonschema.validate(default_data, coded_schema.default_data) except jsonschema.ValidationError as e: self.fail(e)