Skip to content

Commit

Permalink
fix partial code smells
Browse files Browse the repository at this point in the history
Signed-off-by: Hongjing Chen <[email protected]>
  • Loading branch information
chenhongjing committed Nov 15, 2023
1 parent 71a1025 commit a1835a2
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
# noqa: I003

AGM_EXTENSION_PATH = '/filing/agmExtension'
EXPIRED_ERROR = 'Allotted period to request extension has expired.'
GRANT_FAILURE = 'Fail to grant extension.'


def validate(business: Business, filing: Dict) -> Optional[Error]:
Expand Down Expand Up @@ -59,13 +61,13 @@ def first_agm_validation(business: Business, filing: Dict) -> list:
now = LegislationDatetime.datenow()
latest_ext_date = founding_date + relativedelta(months=18, days=5)
if now > latest_ext_date:
msg.append({'error': 'Allotted period to request extension has expired.',
msg.append({'error': EXPIRED_ERROR,
'path': f'{AGM_EXTENSION_PATH}/isFirstAgm'})
else:
total_approved_ext = get_int(filing, f'{AGM_EXTENSION_PATH}/totalApprovedExt')
extension_duration = get_int(filing, f'{AGM_EXTENSION_PATH}/extensionDuration')
if total_approved_ext != 6 or extension_duration != 6:
msg.append({'error': babel('Fail to grant extension.')})
msg.append({'error': babel(GRANT_FAILURE)})
else:
# first AGM, second extension or more
if not (curr_ext_expire_date_str := get_str(filing, f'{AGM_EXTENSION_PATH}/expireDateCurrExt')):
Expand All @@ -80,7 +82,7 @@ def first_agm_validation(business: Business, filing: Dict) -> list:
msg.append({'error': 'Company has received the maximum 12 months of allowable extensions.',
'path': f'{AGM_EXTENSION_PATH}/expireDateCurrExt'})
elif now > curr_ext_expire_date + relativedelta(days=5):
msg.append({'error': 'Allotted period to request extension has expired.',
msg.append({'error': EXPIRED_ERROR,
'path': f'{AGM_EXTENSION_PATH}/expireDateCurrExt'})
else:
total_approved_ext = get_int(filing, f'{AGM_EXTENSION_PATH}/totalApprovedExt')
Expand All @@ -92,7 +94,7 @@ def first_agm_validation(business: Business, filing: Dict) -> list:

if expected_total_approved_ext != total_approved_ext or\
expected_extension_duration != extension_duration:
msg.append({'error': babel('Fail to grant extension.')})
msg.append({'error': babel(GRANT_FAILURE)})

return msg

Expand All @@ -114,13 +116,13 @@ def subsequent_agm_validation(filing: Dict) -> list:
now = LegislationDatetime.datenow()
latest_ext_date = prev_agm_ref_date + relativedelta(months=15, days=5)
if now > latest_ext_date:
msg.append({'error': 'Allotted period to request extension has expired.',
msg.append({'error': EXPIRED_ERROR,
'path': f'{AGM_EXTENSION_PATH}/prevAgmRefDate'})
else:
total_approved_ext = get_int(filing, f'{AGM_EXTENSION_PATH}/totalApprovedExt')
extension_duration = get_int(filing, f'{AGM_EXTENSION_PATH}/extensionDuration')
if total_approved_ext != 6 or extension_duration != 6:
msg.append({'error': babel('Fail to grant extension.')})
msg.append({'error': babel(GRANT_FAILURE)})
else:
# subsequent AGM, second extension or more
if not (curr_ext_expire_date_str := get_str(filing, f'{AGM_EXTENSION_PATH}/expireDateCurrExt')):
Expand All @@ -137,7 +139,7 @@ def subsequent_agm_validation(filing: Dict) -> list:
msg.append({'error': 'Company has received the maximum 12 months of allowable extensions.',
'path': f'{AGM_EXTENSION_PATH}/expireDateCurrExt'})
elif now > curr_ext_expire_date + relativedelta(days=5):
msg.append({'error': 'Allotted period to request extension has expired.',
msg.append({'error': EXPIRED_ERROR,
'path': f'{AGM_EXTENSION_PATH}/expireDateCurrExt'})
else:
total_approved_ext = get_int(filing, f'{AGM_EXTENSION_PATH}/totalApprovedExt')
Expand All @@ -148,7 +150,7 @@ def subsequent_agm_validation(filing: Dict) -> list:

if expected_total_approved_ext != total_approved_ext or\
expected_extension_duration != extension_duration:
msg.append({'error': babel('Fail to grant extension.')})
msg.append({'error': babel(GRANT_FAILURE)})

return msg

Expand Down

0 comments on commit a1835a2

Please sign in to comment.