Skip to content

Commit 3b73185

Browse files
committed
HARMONY-2168: Make sure the environment variable ENVIRONMENT does not override the harmony environment used in client configuration.
1 parent ddef65f commit 3b73185

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ dmypy.json
134134
examples/*.tif
135135
examples/*.png
136136

137+
# Place to put notebooks that will not be published
138+
examples/demo_notebooks/
139+
137140
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
138141
__pypackages__/
139142

harmony/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def __getattribute__(self, name: str) -> str:
9393
The value of the referenced attribute
9494
"""
9595
var = os.getenv(name.upper())
96-
if var is None:
96+
if var is None or name == 'environment':
9797
try:
9898
var = object.__getattribute__(self, name)
9999
except AttributeError:

tests/test_client.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from harmony.request import BBox, Collection, LinkType, Request, Dimension, CapabilitiesRequest, \
1515
AddLabelsRequest, DeleteLabelsRequest, JobsRequest
1616
from harmony.client import Client, ProcessingFailedException, DEFAULT_JOB_LABEL
17+
from harmony.config import Environment
1718

1819

1920
@pytest.fixture()
@@ -1826,4 +1827,22 @@ def test_get_jobs():
18261827
assert len(responses.calls) == 1
18271828
assert responses.calls[0].request.method == 'GET'
18281829
assert responses.calls[0].request.url == expected_url
1829-
assert result == expected_result
1830+
assert result == expected_result
1831+
1832+
def test_client_environment_not_affected_by_env_var():
1833+
os.environ['ENVIRONMENT'] = 'UAT'
1834+
client = Client(should_validate_auth=False)
1835+
1836+
assert client.config.environment == Environment.PROD
1837+
assert client.config.harmony_hostname == 'harmony.earthdata.nasa.gov'
1838+
1839+
del os.environ['ENVIRONMENT']
1840+
1841+
def test_client_custom_environment_not_affected_by_env_var():
1842+
os.environ['ENVIRONMENT'] = 'PROD'
1843+
client = Client(should_validate_auth=False, env=Environment.UAT)
1844+
1845+
assert client.config.environment == Environment.UAT
1846+
assert client.config.harmony_hostname == 'harmony.uat.earthdata.nasa.gov'
1847+
1848+
del os.environ['ENVIRONMENT']

tests/test_config.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
import os
23

34
from harmony.config import Config, Environment
45

@@ -78,3 +79,31 @@ def test_edl_validation_url_matches_environment(env, url):
7879
config = Config(env)
7980

8081
assert config.edl_validation_url == url
82+
83+
def test_config_environment_not_affected_by_env_var():
84+
os.environ['ENVIRONMENT'] = 'UAT'
85+
86+
# Make sure default is production
87+
config = Config()
88+
89+
assert config.environment == Environment.PROD
90+
assert config.harmony_hostname == 'harmony.earthdata.nasa.gov'
91+
92+
del os.environ['ENVIRONMENT']
93+
94+
def test_config_custom_environment_not_affected_by_env_var():
95+
os.environ['ENVIRONMENT'] = 'PROD'
96+
config = Config(environment=Environment.UAT)
97+
98+
assert config.environment == Environment.UAT
99+
assert config.harmony_hostname == 'harmony.uat.earthdata.nasa.gov'
100+
101+
del os.environ['ENVIRONMENT']
102+
103+
def test_config_other_env_vars_still_work():
104+
os.environ['CUSTOM_VAR'] = 'test_value'
105+
config = Config()
106+
107+
assert config.CUSTOM_VAR == 'test_value'
108+
109+
del os.environ['CUSTOM_VAR']

0 commit comments

Comments
 (0)