Skip to content

Commit

Permalink
21202 Add additional checks to disable NR related functionality when …
Browse files Browse the repository at this point in the history
…disable-nr-check flag is on (bcgov#2693)
  • Loading branch information
argush3 authored May 16, 2024
1 parent 6415714 commit fc5568b
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from legal_api.core.filing import Filing
from legal_api.errors import Error
from legal_api.models import Business
from legal_api.services import namex
from legal_api.services import flags, namex
from legal_api.services.utils import get_bool, get_str

from .common_validations import (
Expand Down Expand Up @@ -75,6 +75,11 @@ def share_structure_validation(filing):

def company_name_validation(filing):
"""Validate company name."""
# This is added specifically for the sandbox environment.
# i.e. NR check should only ever have feature flag disabled for sandbox environment.
if flags.is_on('disable-nr-check'):
return []

msg = []
nr_path: Final = '/filing/alteration/nameRequest/nrNumber'
if nr_number := get_str(filing, nr_path):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from legal_api.errors import Error
from legal_api.models import Business
from legal_api.services import MinioService, namex
from legal_api.services import MinioService, flags, namex
from legal_api.services.utils import get_str
from legal_api.utils.datetime import datetime as dt

Expand Down Expand Up @@ -234,6 +234,11 @@ def validate_name_request(filing_json: dict, # pylint: disable=too-many-locals
filing_type: str,
accepted_request_types: list = None) -> list:
"""Validate name request section."""
# This is added specifically for the sandbox environment.
# i.e. NR check should only ever have feature flag disabled for sandbox environment.
if flags.is_on('disable-nr-check'):
return []

nr_path = f'/filing/{filing_type}/nameRequest'
nr_number_path = f'{nr_path}/nrNumber'
legal_name_path = f'{nr_path}/legalName'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
import pycountry
from flask_babel import _ as babel # noqa: N813, I004, I001, I003

from legal_api.core.filing import Filing as coreFiling # noqa: I001
from legal_api.errors import Error
from legal_api.models import Business, Filing
from legal_api.services import namex
from legal_api.services import flags, namex
from legal_api.services.utils import get_str
from legal_api.utils.datetime import datetime as dt

from legal_api.core.filing import Filing as coreFiling # noqa: I001
from .common_validations import ( # noqa: I001
validate_court_order,
validate_name_request,
Expand Down Expand Up @@ -359,6 +359,11 @@ def validate_correction_effective_date(filing: dict, corrected_filing: dict) ->

def validate_correction_name_request(filing: dict, corrected_filing: dict) -> Optional[list]:
"""Validate correction of Name Request."""
# This is added specifically for the sandbox environment.
# i.e. NR check should only ever have feature flag disabled for sandbox environment.
if flags.is_on('disable-nr-check'):
return []

nr_path = '/filing/incorporationApplication/nameRequest/nrNumber'
nr_number = get_str(corrected_filing.json, nr_path)
new_nr_number = get_str(filing, nr_path)
Expand Down
9 changes: 9 additions & 0 deletions legal-api/src/legal_api/services/namex.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ def is_date_past_expiration(nr_json, date_time):
@staticmethod
def get_approved_name(nr_json) -> str:
"""Get an approved name from nr json, if any."""
from . import flags # pylint: disable=import-outside-toplevel

# This is added specifically for the sandbox environment.
# i.e. NR check should only ever have feature flag disabled for sandbox environment.
if flags.is_on('disable-nr-check'):
return next((name['name'] for name in nr_json['names']
if name['state']
in ['APPROVED', 'CONDITION']), None)

nr_name = None
state_to_check = None
nr_state = nr_json['state']
Expand Down
20 changes: 16 additions & 4 deletions legal-api/tests/unit/resources/v1/test_name_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,19 @@ def test_validate_nr_consent_required_received():

def test_get_approved_name():
"""Get Approved/Conditional Approved name."""
nr_name = namex.get_approved_name(nr_consumable_approved)
assert nr_name == nr_consumable_approved['names'][0]['name']
nr_name = namex.get_approved_name(nr_consumable_conditional)
assert nr_name == nr_consumable_conditional['names'][1]['name']
with patch.object(flags, 'is_on', return_value=False):
nr_name = namex.get_approved_name(nr_consumable_approved)
assert nr_name == nr_consumable_approved['names'][0]['name']
nr_name = namex.get_approved_name(nr_consumable_conditional)
assert nr_name == nr_consumable_conditional['names'][1]['name']


def test_get_approved_name_skips_nr_state_check():
"""Get Approved/Conditional Approved name for NR has already been consumed."""
nr_consumed_approved = copy.deepcopy(nr_consumable_approved)
nr_consumed_approved['state'] = 'CONSUMED'
with patch.object(flags, 'is_on', return_value=True):
nr_name = namex.get_approved_name(nr_consumable_approved)
assert nr_name == nr_consumable_approved['names'][0]['name']
nr_name = namex.get_approved_name(nr_consumable_conditional)
assert nr_name == nr_consumable_conditional['names'][1]['name']
20 changes: 16 additions & 4 deletions legal-api/tests/unit/resources/v2/test_name_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,19 @@ def test_validate_nr_consent_required_received_skips_nr_check():

def test_get_approved_name():
"""Get Approved/Conditional Approved name."""
nr_name = namex.get_approved_name(nr_consumable_approved)
assert nr_name == nr_consumable_approved['names'][0]['name']
nr_name = namex.get_approved_name(nr_consumable_conditional)
assert nr_name == nr_consumable_conditional['names'][1]['name']
with patch.object(flags, 'is_on', return_value=False):
nr_name = namex.get_approved_name(nr_consumable_approved)
assert nr_name == nr_consumable_approved['names'][0]['name']
nr_name = namex.get_approved_name(nr_consumable_conditional)
assert nr_name == nr_consumable_conditional['names'][1]['name']


def test_get_approved_name_skips_nr_state_check():
"""Get Approved/Conditional Approved name for NR has already been consumed."""
nr_consumed_approved = copy.deepcopy(nr_consumable_approved)
nr_consumed_approved['state'] = 'CONSUMED'
with patch.object(flags, 'is_on', return_value=True):
nr_name = namex.get_approved_name(nr_consumable_approved)
assert nr_name == nr_consumable_approved['names'][0]['name']
nr_name = namex.get_approved_name(nr_consumable_conditional)
assert nr_name == nr_consumable_conditional['names'][1]['name']

0 comments on commit fc5568b

Please sign in to comment.