generated from bcgov/bcrs-template-ui
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from bcgov/2622-comments
2622 add comments schema
- Loading branch information
Showing
7 changed files
with
232 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,18 @@ | ||
flask | ||
jsonschema | ||
requests | ||
strict-rfc3339 | ||
Click==7.0 | ||
Flask==1.1.1 | ||
Jinja2==2.11.1 | ||
MarkupSafe==1.1.1 | ||
Werkzeug==1.0.0 | ||
attrs==19.1.0 | ||
certifi==2019.11.28 | ||
chardet==3.0.4 | ||
idna==2.8 | ||
importlib-metadata==1.5.0 | ||
itsdangerous==1.1.0 | ||
jsonschema==3.2.0 | ||
pyrsistent==0.15.7 | ||
requests==2.22.0 | ||
six==1.14.0 | ||
strict-rfc3339==0.7 | ||
urllib3==1.25.8 | ||
zipp==2.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$id": "https://bcrs.gov.bc.ca/.well_known/schemas/comment", | ||
"type": "object", | ||
"title": "The Comment Schema", | ||
"required": [ | ||
"comment" | ||
], | ||
"properties": { | ||
"comment": { | ||
"type": "object", | ||
"oneOf": [ | ||
{ | ||
"required": [ | ||
"comment", | ||
"filingId", | ||
"submitterId" | ||
] | ||
}, | ||
{ | ||
"required": [ | ||
"comment", | ||
"businessId", | ||
"submitterId" | ||
] | ||
} | ||
], | ||
"properties": { | ||
"comment": { | ||
"type": "string", | ||
"max_length": 4096 | ||
}, | ||
"filingId": { | ||
"type": "integer", | ||
"title": "The id of the filing.", | ||
"examples": [ | ||
2304 | ||
] | ||
}, | ||
"businessId": { | ||
"type": "integer", | ||
"title": "The id of the business.", | ||
"examples": [ | ||
151 | ||
] | ||
}, | ||
"submitterId": { | ||
"type": "integer", | ||
"title": "The id of the submitter.", | ||
"examples": [ | ||
4 | ||
] | ||
}, | ||
"timestamp": { | ||
"type": ["string", "null"], | ||
"format": "date-time", | ||
"title": "The timestamp of the comment", | ||
"examples": [ | ||
"2020-01-01T00:00:00+00:00" | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
# Copyright © 2019 Province of British Columbia | ||
# | ||
# 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 Suite to ensure comments added onto filings and businesses are valid.""" | ||
import copy | ||
|
||
from registry_schemas import validate | ||
from registry_schemas.example_data import COMMENT_BUSINESS, COMMENT_FILING | ||
|
||
|
||
def test_valid_comment_filing(): | ||
"""Assert that the schema is performing as expected for filing comments.""" | ||
is_valid, errors = validate(COMMENT_FILING, 'comment') | ||
|
||
if errors: | ||
for err in errors: | ||
print(err.message) | ||
print(errors) | ||
|
||
assert is_valid | ||
|
||
|
||
def test_valid_comment_business(): | ||
"""Assert that the schema is performing as expected for business comments.""" | ||
comment = copy.deepcopy(COMMENT_BUSINESS) | ||
|
||
is_valid, errors = validate(comment, 'comment') | ||
|
||
if errors: | ||
for err in errors: | ||
print(err.message) | ||
print(errors) | ||
|
||
assert is_valid | ||
|
||
|
||
def test_valid_no_timestamp(): | ||
"""Assert that the schema does not require a timestamp.""" | ||
# check with timestamp set to null | ||
comment = copy.deepcopy(COMMENT_FILING) | ||
comment['comment']['timestamp'] = None | ||
is_valid, errors = validate(comment, 'comment') | ||
if errors: | ||
for err in errors: | ||
print(err.message) | ||
print(errors) | ||
assert is_valid | ||
|
||
# check with timestamp removed entirely | ||
del comment['comment']['timestamp'] | ||
is_valid, errors = validate(comment, 'comment') | ||
if errors: | ||
for err in errors: | ||
print(err.message) | ||
print(errors) | ||
assert is_valid | ||
|
||
|
||
def test_invalid_filing_and_business_id(): | ||
"""Assert that schema fails with both filing and business id set.""" | ||
comment = copy.deepcopy(COMMENT_FILING) | ||
comment['comment']['businessId'] = 1 | ||
is_valid, errors = validate(comment, 'comment') | ||
|
||
if errors: | ||
for err in errors: | ||
print(err.message) | ||
print(errors) | ||
|
||
assert not is_valid | ||
|
||
|
||
def test_invalid_no_filing_or_business_id(): | ||
"""Assert that one of business or filing id is required.""" | ||
# check that setting an id to null fails | ||
comment = copy.deepcopy(COMMENT_FILING) | ||
comment['comment']['filingId'] = None | ||
is_valid, errors = validate(comment, 'comment') | ||
if errors: | ||
for err in errors: | ||
print(err.message) | ||
print(errors) | ||
assert not is_valid | ||
|
||
# check that having neither id in the json at all fails | ||
del comment['comment']['filingId'] | ||
is_valid, errors = validate(comment, 'comment') | ||
if errors: | ||
for err in errors: | ||
print(err.message) | ||
print(errors) | ||
assert not is_valid | ||
|
||
|
||
def test_invalid_no_submitter(): | ||
"""Assert that submitter id is required.""" | ||
# check with submitterId set to null | ||
comment = copy.deepcopy(COMMENT_FILING) | ||
comment['comment']['submitterId'] = None | ||
is_valid, errors = validate(comment, 'comment') | ||
if errors: | ||
for err in errors: | ||
print(err.message) | ||
print(errors) | ||
assert not is_valid | ||
|
||
# check with submitterId removed entirely | ||
del comment['comment']['submitterId'] | ||
is_valid, errors = validate(comment, 'comment') | ||
if errors: | ||
for err in errors: | ||
print(err.message) | ||
print(errors) | ||
assert not is_valid |