Skip to content

Commit

Permalink
Merge pull request #7 from bcgov/2622-comments
Browse files Browse the repository at this point in the history
2622 add comments schema
  • Loading branch information
thorwolpert authored Feb 12, 2020
2 parents bec77db + 5085936 commit bf6bcf3
Show file tree
Hide file tree
Showing 7 changed files with 232 additions and 6 deletions.
22 changes: 18 additions & 4 deletions requirements.txt
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
4 changes: 4 additions & 0 deletions src/registry_schemas/example_data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
CHANGE_OF_DIRECTORS,
CHANGE_OF_DIRECTORS_MAILING,
CHANGE_OF_NAME,
COMMENT_BUSINESS,
COMMENT_FILING,
CORP_CHANGE_OF_ADDRESS,
FILING_HEADER,
FILING_TEMPLATE,
Expand All @@ -43,6 +45,8 @@
'CHANGE_OF_ADDRESS',
'CHANGE_OF_DIRECTORS',
'CHANGE_OF_NAME',
'COMMENT_BUSINESS',
'COMMENT_FILING',
'CORP_CHANGE_OF_ADDRESS',
'FILING_HEADER',
'FILING_TEMPLATE',
Expand Down
18 changes: 18 additions & 0 deletions src/registry_schemas/example_data/schema_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,24 @@
}
}

COMMENT_BUSINESS = {
'comment': {
'businessId': 1,
'comment': 'This is a comment on a business.',
'timestamp': '2020-02-10T20:05:49.068272+00:00',
'submitterId': 1
}
}

COMMENT_FILING = {
'comment': {
'comment': 'This is a comment on a filing.',
'filingId': 1,
'timestamp': '2020-02-10T20:05:49.068272+00:00',
'submitterId': 1
}
}

CORP_CHANGE_OF_ADDRESS = {
'legalType': 'BC',
'offices': {
Expand Down
65 changes: 65 additions & 0 deletions src/registry_schemas/schemas/comment.json
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"
]
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/registry_schemas/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
Development release segment: .devN
"""

__version__ = '2.5.0' # pylint: disable=invalid-name
__version__ = '2.5.1' # pylint: disable=invalid-name
3 changes: 2 additions & 1 deletion tests/unit/schema_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@
('office.json'),
('incorporation.json'),
('name_request.json'),
('contact_point.json')
('contact_point.json'),
('comment.json')
]
124 changes: 124 additions & 0 deletions tests/unit/test_comments.py
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

0 comments on commit bf6bcf3

Please sign in to comment.