Skip to content

31783 - Add Canadian Postal Code Validation#4145

Open
meawong wants to merge 6 commits intobcgov:mainfrom
meawong:31783-Add-Validation-for-Canadian-Postal-Codes
Open

31783 - Add Canadian Postal Code Validation#4145
meawong wants to merge 6 commits intobcgov:mainfrom
meawong:31783-Add-Validation-for-Canadian-Postal-Codes

Conversation

@meawong
Copy link
Collaborator

@meawong meawong commented Mar 11, 2026

Issue #: /bcgov/entity#31783

Description of changes:

  • Update common _validate_postal_code method to validate Canadian postal code format (ex: A1A 1A1)
  • Add/Update unit tests

Ex:
image

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the lear license (Apache 2.0).

@meawong meawong self-assigned this Mar 11, 2026
)

CANADIAN_POSTAL_CODE_REGEX = re.compile(
r"^[ABCEGHJ-NPRSTVXY]\d[ABCEGHJ-NPRSTV-Z]\s?\d[ABCEGHJ-NPRSTV-Z]\d$",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

@argush3 argush3 Mar 11, 2026

Choose a reason for hiding this comment

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

so postal codes with a tab or newline would pass validation. e.g. V6B\t1A1 or V6B\n1A1

think we want to block these?

@sonarqubecloud
Copy link




@pytest.mark.parametrize('filing_type, filing_data, office_type', [
Copy link
Collaborator

Choose a reason for hiding this comment

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

cool, didn't know you could stack parameters like this!

Comment on lines +305 to +306
actual_errors = [e['error'] for e in err.msg]
assert any(expected_error['error'] in actual_errors for expected_error in expected_msg)
Copy link
Collaborator

@argush3 argush3 Mar 11, 2026

Choose a reason for hiding this comment

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

are you able to keep the original test structure and maybe update the expected error message lists for postal code related tests? Otherwise it feels like some tests that are actually failing might fall through.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants