From bbe022316886f409f917ac8d3802ec6cf9c6aaf5 Mon Sep 17 00:00:00 2001 From: Johnson Kwok <78053898+johnson-mage@users.noreply.github.com> Date: Fri, 30 Aug 2024 12:30:19 -0700 Subject: [PATCH] [jk] Update test ENV value (#5372) # Description - Using `test` as the value for the `ENV` environment variable for running unit tests could cause the test db to conflict with the metadata db used by users in their own test environments. This PR updates the value used for `ENV` in the environment for running mage's unit tests. - Should resolve this github issue: https://github.com/mage-ai/mage-ai/issues/5360 # How Has This Been Tested? Before: Using `test` for the `ENV` env var resulted in using the `test.db` file as the metadata db, even if postgres was set as the metadata db using the `MAGE_DATABASE_CONNECTION_URL` env var. After: Using `test` for the `ENV` env var did not result in using the `test.db` file as the metadata db. If postgres was set as the metadata db using the `MAGE_DATABASE_CONNECTION_URL` env var, postgres would be properly used as the metadata db. Confirmed by creating new users and verifying they were stored in the postgres db. # Checklist - [X] The PR is tagged with proper labels (bug, enhancement, feature, documentation) - [X] I have performed a self-review of my own code - [ ] I have added unit tests that prove my fix is effective or that my feature works - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation cc: --- .github/workflows/build_and_test.yml | 3 +++ mage_ai/shared/constants.py | 2 +- mage_ai/shared/environments.py | 2 +- .../data_preparation/models/block/hook/test_hook_block.py | 5 +++-- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 6491cba8902..06586a07064 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -16,6 +16,9 @@ on: - "requirements.txt" - "setup.py" +env: + ENV: test_mage + jobs: check-code-quality: diff --git a/mage_ai/shared/constants.py b/mage_ai/shared/constants.py index 48f5a0b283d..ba02ff17737 100644 --- a/mage_ai/shared/constants.py +++ b/mage_ai/shared/constants.py @@ -3,7 +3,7 @@ ENV_DEV = 'dev' ENV_PROD = 'prod' ENV_STAGING = 'staging' -ENV_TEST = 'test' +ENV_TEST = 'test_mage' VALID_ENVS = frozenset([ ENV_DEV, diff --git a/mage_ai/shared/environments.py b/mage_ai/shared/environments.py index d328da81868..b9d00fe136c 100644 --- a/mage_ai/shared/environments.py +++ b/mage_ai/shared/environments.py @@ -17,7 +17,7 @@ def is_dev(): def is_test(): - return os.getenv('ENV', None) == 'test' or any('unittest' in v for v in sys.argv) + return os.getenv('ENV', None) == 'test_mage' or any('unittest' in v for v in sys.argv) def is_production(): diff --git a/mage_ai/tests/data_preparation/models/block/hook/test_hook_block.py b/mage_ai/tests/data_preparation/models/block/hook/test_hook_block.py index 434fb053f6e..adfd978c37c 100644 --- a/mage_ai/tests/data_preparation/models/block/hook/test_hook_block.py +++ b/mage_ai/tests/data_preparation/models/block/hook/test_hook_block.py @@ -5,6 +5,7 @@ from mage_ai.data_preparation.models.block.hook.block import HookBlock from mage_ai.data_preparation.models.constants import BlockType from mage_ai.data_preparation.models.global_hooks.models import HookStatus, HookStrategy +from mage_ai.shared.constants import ENV_TEST from mage_ai.tests.api.operations.test_base import BaseApiTestCase from mage_ai.tests.factory import create_pipeline_with_blocks from mage_ai.tests.shared.mixins import build_hooks @@ -45,7 +46,7 @@ def test_execute_block(self): check_status=True, configuration={}, context={}, - env='test', + env=ENV_TEST, error_on_failure=True, mage=1, pipeline_uuid='', @@ -84,7 +85,7 @@ def test_execute_block_with_error(self): check_status=True, configuration={}, context={}, - env='test', + env=ENV_TEST, error_on_failure=True, mage=1, pipeline_uuid='',