diff --git a/legal-api/Makefile b/legal-api/Makefile index e50bef1227..ca42d47f57 100644 --- a/legal-api/Makefile +++ b/legal-api/Makefile @@ -57,12 +57,12 @@ pylint: ## Linting with pylint fi flake8: ## Linting with flake8 - . venv/bin/activate && flake8 src/$(PROJECT_NAME) + . .venv/bin/activate && flake8 src/$(PROJECT_NAME) lint: pylint flake8 ## run all lint type scripts test: ## Unit testing - . venv/bin/activate && pytest + . .venv/bin/activate && pytest mac-cov: test ## Run the coverage report and display in a browser window (mac) @open -a "Google Chrome" htmlcov/index.html diff --git a/legal-api/src/legal_api/services/digital_credentials_utils.py b/legal-api/src/legal_api/services/digital_credentials_utils.py index 2c4efc40cf..d752e3d3f3 100644 --- a/legal-api/src/legal_api/services/digital_credentials_utils.py +++ b/legal-api/src/legal_api/services/digital_credentials_utils.py @@ -19,10 +19,6 @@ from flask import current_app from legal_api.models import Party, User -from legal_api.services.flags import Flags - - -flags = Flags() DBC_ENABLED_BUSINESS_TYPES_FLAG = 'dbc-enabled-business-types' @@ -30,6 +26,9 @@ def determine_allowed_business_types(valid_registration_types: List[str], valid_incorporation_types: List[str]) -> List[str]: """Determine if the business type is allowed for digital credentials based on flags.""" + # Import inside function to avoid circular dependency and ensure app context is available + from legal_api.services import flags + if not flags.is_on(DBC_ENABLED_BUSINESS_TYPES_FLAG): current_app.logger.warning('%s is OFF', DBC_ENABLED_BUSINESS_TYPES_FLAG) return [] diff --git a/legal-api/tests/unit/services/test_digital_credentials_helpers_and_utils.py b/legal-api/tests/unit/services/test_digital_credentials_helpers_and_utils.py index 97ce0ad618..48202d32be 100644 --- a/legal-api/tests/unit/services/test_digital_credentials_helpers_and_utils.py +++ b/legal-api/tests/unit/services/test_digital_credentials_helpers_and_utils.py @@ -59,8 +59,8 @@ def test_determine_allowed_business_types(app, monkeypatch, flag_value, valid_re """Test filtering of allowed business types based on flag values.""" # Mock flag values - monkeypatch.setattr('legal_api.services.digital_credentials_utils.flags.is_on', lambda _: True) - monkeypatch.setattr('legal_api.services.digital_credentials_utils.flags.value', lambda _: flag_value) + monkeypatch.setattr('legal_api.services.flags.is_on', lambda _: True) + monkeypatch.setattr('legal_api.services.flags.value', lambda _: flag_value) with app.app_context(): result = determine_allowed_business_types(valid_registration_types, valid_incorporation_types) @@ -82,8 +82,8 @@ def test_determine_allowed_business_types_invalid_flags(app, monkeypatch, flag_v """Test filtering of allowed business types based on flag values.""" # Mock flag values - monkeypatch.setattr('legal_api.services.digital_credentials_utils.flags.is_on', lambda _: True) - monkeypatch.setattr('legal_api.services.digital_credentials_utils.flags.value', lambda _: flag_value) + monkeypatch.setattr('legal_api.services.flags.is_on', lambda _: True) + monkeypatch.setattr('legal_api.services.flags.value', lambda _: flag_value) with app.app_context(): result = determine_allowed_business_types(valid_registration_types, valid_incorporation_types) @@ -93,7 +93,7 @@ def test_determine_allowed_business_types_missing_flag(app, monkeypatch): """Test filtering of allowed business types based on flag value not set.""" # Mock flag values - monkeypatch.setattr('legal_api.services.digital_credentials_utils.flags.is_on', lambda _: False) + monkeypatch.setattr('legal_api.services.flags.is_on', lambda _: False) with app.app_context(): result = determine_allowed_business_types(['SP', 'GP'], ['BEN'])