Skip to content

Commit

Permalink
[jk] Update test ENV value (mage-ai#5372)
Browse files Browse the repository at this point in the history
# 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:
mage-ai#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:
<!-- Optionally mention someone to let them know about this pull request
-->
  • Loading branch information
johnson-mage authored Aug 30, 2024
1 parent e967a99 commit bbe0223
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ on:
- "requirements.txt"
- "setup.py"

env:
ENV: test_mage

jobs:
check-code-quality:

Expand Down
2 changes: 1 addition & 1 deletion mage_ai/shared/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion mage_ai/shared/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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='',
Expand Down Expand Up @@ -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='',
Expand Down

0 comments on commit bbe0223

Please sign in to comment.