Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

18163 AGM location change update filer and validations #2258

Merged
merged 8 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion legal-api/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ minio==7.0.2
PyPDF2==1.26.0
reportlab==3.6.12
html-sanitizer==1.9.3
git+https://github.com/bcgov/business-schemas.git@2.18.13#egg=registry_schemas
git+https://github.com/bcgov/business-schemas.git@2.18.14#egg=registry_schemas

2 changes: 1 addition & 1 deletion legal-api/requirements/bcregistry-libraries.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
git+https://github.com/bcgov/business-schemas.git@2.18.13#egg=registry_schemas
git+https://github.com/bcgov/business-schemas.git@2.18.14#egg=registry_schemas
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from http import HTTPStatus
from typing import Dict, Final, Optional

import pycountry
from flask_babel import _ as babel # noqa: N813, I004, I001; importing camelcase '_' as a name
# noqa: I003
from legal_api.errors import Error
Expand All @@ -42,19 +41,6 @@ def validate(business: Business, filing: Dict) -> Optional[Error]:
else:
msg.append({'error': 'Invalid AGM year.', 'path': agm_year_path})

address = filing['filing']['agmLocationChange']['newAgmLocation']
country_code = address.get('addressCountry').upper() # country is a required field in schema
region = (address.get('addressRegion') or '').upper()

agm_location_path: Final = '/filing/agmLocationChange/newAgmLocation'
country = pycountry.countries.get(alpha_2=country_code)
if not country:
msg.append({'error': 'Invalid country.', 'path': f'{agm_location_path}/addressCountry'})
elif country_code in ('CA', 'US'):
if country_code == 'CA' and region == 'BC':
msg.append({'error': 'Region should not be BC.', 'path': f'{agm_location_path}/addressRegion'})
elif not pycountry.subdivisions.get(code=f'{country_code}-{region}'):
msg.append({'error': 'Invalid region.', 'path': f'{agm_location_path}/addressRegion'})
if msg:
return Error(HTTPStatus.BAD_REQUEST, msg)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,45 +64,3 @@ def test_validate_agm_year(session, mocker, test_name, expected_code, message):
assert message == err.msg[0]['error']
else:
assert not err


@pytest.mark.parametrize(
'test_name, expected_code, message',
[
('FAIL_NO_COUNTRY', HTTPStatus.UNPROCESSABLE_ENTITY, None),
('FAIL_INVALID_COUNTRY', HTTPStatus.BAD_REQUEST, 'Invalid country.'),
('FAIL_REGION_BC', HTTPStatus.BAD_REQUEST, 'Region should not be BC.'),
('FAIL_INVALID_REGION', HTTPStatus.BAD_REQUEST, 'Invalid region.'),
('FAIL_INVALID_US_REGION', HTTPStatus.BAD_REQUEST, 'Invalid region.'),
('SUCCESS', None, None)
]
)
def test_validate_agm_location(session, mocker, test_name, expected_code, message):
"""Assert validate agm location."""
business = factory_business(identifier='BC1234567', entity_type='BC', founding_date=datetime.utcnow())
filing = copy.deepcopy(FILING_HEADER)
filing['filing']['agmLocationChange'] = copy.deepcopy(AGM_LOCATION_CHANGE)
filing['filing']['header']['name'] = 'agmLocationChange'

if test_name == 'FAIL_NO_COUNTRY':
del filing['filing']['agmLocationChange']['newAgmLocation']['addressCountry']
elif test_name == 'FAIL_INVALID_COUNTRY':
filing['filing']['agmLocationChange']['newAgmLocation']['addressCountry'] = 'NONE'
elif test_name == 'FAIL_REGION_BC':
filing['filing']['agmLocationChange']['newAgmLocation']['addressRegion'] = 'BC'
elif test_name == 'FAIL_INVALID_REGION':
filing['filing']['agmLocationChange']['newAgmLocation']['addressRegion'] = ''
elif test_name == 'FAIL_INVALID_US_REGION':
filing['filing']['agmLocationChange']['newAgmLocation']['addressCountry'] = 'US'
filing['filing']['agmLocationChange']['newAgmLocation']['addressRegion'] = ''

filing['filing']['agmLocationChange']['year'] = str(LegislationDatetime.now().year)
err = validate(business, filing)

# validate outcomes
if test_name != 'SUCCESS':
assert expected_code == err.code
if message:
assert message == err.msg[0]['error']
else:
assert not err
2 changes: 1 addition & 1 deletion queue_services/entity-filer/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ urllib3==1.26.11
minio==7.0.2
PyPDF2==1.26.0
reportlab==3.6.1
git+https://github.com/bcgov/business-schemas.git@2.18.13#egg=registry_schemas
git+https://github.com/bcgov/business-schemas.git@2.18.14#egg=registry_schemas
git+https://github.com/bcgov/lear.git#egg=legal_api&subdirectory=legal-api
git+https://github.com/bcgov/lear.git#egg=entity_queue_common&subdirectory=queue_services/common
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
git+https://github.com/bcgov/business-schemas.git@2.18.13#egg=registry_schemas
git+https://github.com/bcgov/business-schemas.git@2.18.14#egg=registry_schemas
git+https://github.com/bcgov/lear.git#egg=legal_api&subdirectory=legal-api
git+https://github.com/bcgov/lear.git#egg=entity_queue_common&subdirectory=queue_services/common
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@

def process(filing: Dict, filing_meta: FilingMeta):
"""Render the agm location change filing into the model objects."""
address = filing['agmLocationChange']['newAgmLocation']
filing_meta.agm_location_change = {
'year': filing['agmLocationChange']['year'],
'newAgmLocation': {
'addressCountry': address.get('addressCountry').upper(),
'addressRegion': (address.get('addressRegion') or '').upper(),
'addressCity': address.get('addressCity')
}
'agmLocation': filing['agmLocationChange']['agmLocation'],
'reason': filing['agmLocationChange']['reason']
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,5 @@ async def test_worker_agm_location_change(app, session, mocker):

agm_location_change = final_filing.meta_data.get('agmLocationChange')
assert filing_json['filing']['agmLocationChange']['year'] == agm_location_change.get('year')
agm_location = agm_location_change.get('newAgmLocation')
assert filing_json['filing']['agmLocationChange']['newAgmLocation']['addressCountry'] == \
agm_location.get('addressCountry')
assert filing_json['filing']['agmLocationChange']['newAgmLocation']['addressRegion'] == \
agm_location.get('addressRegion')
assert filing_json['filing']['agmLocationChange']['newAgmLocation']['addressCity'] == \
agm_location.get('addressCity')
assert filing_json['filing']['agmLocationChange']['agmLocation'] == agm_location_change.get('agmLocation')
assert filing_json['filing']['agmLocationChange']['reason'] == agm_location_change.get('reason')
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once bcgov/business-schemas#146 gets merged, I will update the business schema version in the requirements so that the example data gets updated.

Loading