Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5c521ee

Browse files
Merge pull request #4769 from benjamin-bc-gov/33534_use_common_lear_packages
33534 use common lear packages
2 parents 603ef76 + 0888855 commit 5c521ee

20 files changed

Lines changed: 196 additions & 37 deletions

File tree

python/common/business-registry-common/src/business_common/utils/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class BaseEnum(str, Enum, metaclass=BaseMeta):
3232
"""Replace autoname from Enum class."""
3333

3434
@classmethod
35-
def get_enum_by_value(cls, value: str):
35+
def get_enum_by_value(cls, value: str) -> str | None:
3636
"""Return the enum by value."""
3737
for enum_value in cls:
3838
if enum_value.value == value:
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright © 2025 Province of British Columbia
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""Tests for Error and BusinessException."""
15+
import pytest
16+
17+
from business_common.errors.errors import Error
18+
from business_common.exceptions.business_exception import BusinessException
19+
20+
21+
def test_error():
22+
"""Assert Error stores code and message list."""
23+
error = Error(400, [{"message": "Bad Request"}])
24+
assert error.code == 400
25+
assert error.msg == [{"message": "Bad Request"}]
26+
27+
28+
def test_business_exception():
29+
"""Assert BusinessException stores error/status_code and is raiseable."""
30+
with pytest.raises(BusinessException) as exc_info:
31+
raise BusinessException("not found", 404)
32+
assert exc_info.value.error == "not found"
33+
assert exc_info.value.status_code == 404
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright © 2025 Province of British Columbia
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""Tests for BaseEnum and BaseMeta utilities."""
15+
from business_common.utils.base import BaseEnum
16+
17+
18+
class SampleEnum(BaseEnum):
19+
"""Sample enum for testing."""
20+
21+
FOO = "foo"
22+
BAR = "bar"
23+
24+
25+
def test_get_enum_by_value():
26+
"""Assert get_enum_by_value returns the member or None."""
27+
assert SampleEnum.get_enum_by_value("foo") == SampleEnum.FOO
28+
assert SampleEnum.get_enum_by_value("bar") == SampleEnum.BAR
29+
assert SampleEnum.get_enum_by_value("unknown") is None
30+
31+
32+
def test_base_meta_contains():
33+
"""Assert 'in' operator works for valid and invalid values."""
34+
assert "foo" in SampleEnum
35+
assert "unknown" not in SampleEnum
36+
assert SampleEnum.FOO == "foo"
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Copyright © 2025 Province of British Columbia
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""Tests for LegislationDatetime utilities."""
15+
from datetime import date
16+
17+
import pytest
18+
from flask import Flask
19+
20+
from business_common.utils.legislation_datetime import LegislationDatetime
21+
22+
23+
@pytest.fixture
24+
def app():
25+
"""Minimal Flask app with LEGISLATIVE_TIMEZONE configured."""
26+
_app = Flask(__name__)
27+
_app.config["LEGISLATIVE_TIMEZONE"] = "America/Vancouver"
28+
return _app
29+
30+
31+
def test_static_helpers():
32+
"""Assert context-free helpers work correctly."""
33+
assert LegislationDatetime.format_as_next_legislation_day("2021-08-04") == "August 05, 2021"
34+
assert LegislationDatetime.is_future("2099-01-01T00:00:00+00:00") is True
35+
assert LegislationDatetime.is_future("2000-01-01T00:00:00+00:00") is False
36+
37+
38+
def test_now_methods(app):
39+
"""Assert now(), datenow(), and tomorrow helpers return expected values."""
40+
with app.app_context():
41+
assert LegislationDatetime.now().tzinfo is not None
42+
assert isinstance(LegislationDatetime.datenow(), date)
43+
midnight = LegislationDatetime.tomorrow_midnight()
44+
assert midnight.hour == 0
45+
assert midnight.minute == 0
46+
assert midnight.second == 0
47+
assert LegislationDatetime.tomorrow_one_minute_after_midnight().minute == 1
48+
49+
50+
def test_timezone_conversions(app):
51+
"""Assert legislation ↔ UTC conversion methods return correct timezones."""
52+
with app.app_context():
53+
leg_dt = LegislationDatetime.as_legislation_timezone_from_date_str("2021-08-05")
54+
assert leg_dt is not None
55+
utc_dt = LegislationDatetime.as_utc_timezone_from_legislation_date_str("2021-08-05")
56+
assert utc_dt.tzname() in ("GMT", "UTC")
57+
assert LegislationDatetime.as_utc_timezone(leg_dt).tzname() in ("GMT", "UTC")
58+
59+
60+
def test_format_methods(app):
61+
"""Assert all format_as_* methods return expected strings."""
62+
with app.app_context():
63+
dt = LegislationDatetime.as_legislation_timezone_from_date_str("2021-08-05")
64+
assert "Pacific time" in LegislationDatetime.format_as_report_string(dt)
65+
assert "12:01" in LegislationDatetime.format_as_report_expiry_string(dt)
66+
assert "11:59" in LegislationDatetime.format_as_report_expiry_string_1159(dt)
67+
assert LegislationDatetime.format_as_legislation_date(dt) == "2021-08-05"

queue_services/business-filer/poetry.lock

Lines changed: 39 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

queue_services/business-filer/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ dependencies = [
2323
"cloud-sql-connector @ git+https://github.com/bcgov/sbc-connect-common.git@main#subdirectory=python/cloud-sql-connector",
2424
"gunicorn (>=23.0.0,<24.0.0)",
2525
"business-registry-account @ git+https://github.com/bcgov/lear.git@main#subdirectory=python/common/business-registry-account",
26+
"business-registry-common @ git+https://github.com/bcgov/lear.git@main#subdirectory=python/common/business-registry-common",
2627
]
2728

2829
[tool.poetry]

queue_services/business-filer/src/business_filer/filing_processors/change_of_address.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
"""File processing rules and actions for the change of address."""
3535
from datetime import UTC
3636

37+
from business_common.utils import datetime
3738
from business_model.models import BatchProcessing, Business
3839
from datedelta import datedelta
3940

40-
from business_filer.common.datetime import datetime
4141
from business_filer.filing_meta import FilingMeta
4242
from business_filer.filing_processors.filing_components import create_address, update_address
4343

queue_services/business-filer/src/business_filer/filing_processors/consent_continuation_out.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636

3737
import datedelta
3838
import dpath
39+
from business_common.utils import LegislationDatetime
3940
from business_model.models import Business, Comment, ConsentContinuationOut, Filing
4041

41-
from business_filer.common.legislation_datetime import LegislationDatetime
4242
from business_filer.filing_meta import FilingMeta
4343
from business_filer.filing_processors.filing_components import filings
4444

queue_services/business-filer/src/business_filer/filing_processors/continuation_in.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
"""File processing rules and actions for the continuation in of a business."""
1515
import copy
1616

17+
from business_common.utils import LegislationDatetime
1718
from business_model.models import Business, Document, DocumentType, Filing, Jurisdiction
1819

19-
from business_filer.common.legislation_datetime import LegislationDatetime
2020
from business_filer.exceptions import QueueException
2121
from business_filer.filing_meta import FilingMeta
2222
from business_filer.filing_processors.filing_components import aliases, business_info, documents, filings, shares

queue_services/business-filer/src/business_filer/filing_processors/continuation_out.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
from contextlib import suppress
3636

3737
import dpath
38+
from business_common.utils import LegislationDatetime
3839
from business_model.models import Business, Comment, DocumentType, Filing
3940

40-
from business_filer.common.legislation_datetime import LegislationDatetime
4141
from business_filer.filing_meta import FilingMeta
4242
from business_filer.filing_processors.filing_components import documents, filings
4343

0 commit comments

Comments
 (0)