Skip to content

Commit

Permalink
✅ Delete all irrelevant config variables
Browse files Browse the repository at this point in the history
Consistent with
#961 (comment)

Testing done:

```
----------------------------------------------------------------------
Ran 21 tests in 23.106s

OK
```
  • Loading branch information
shankari committed Aug 12, 2024
1 parent ec38835 commit 1a0d451
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions emission/tests/storageTests/TestTokenQueries.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
import logging
import uuid
import json
import os

#changed all script runs from os() to subprocess.run() for consistency
#TODO clean up commented out os() lines
# import os
import subprocess
import importlib

import emission.core.get_database as edb

Expand All @@ -15,6 +17,16 @@


class TestTokenQueries(unittest.TestCase):
def setUp(self):
# Delete irrelevant environment variables so that they don't mess up
# the expected comparison with the ground truth
# https://github.com/e-mission/e-mission-server/pull/961#issuecomment-2284668743
for var_name in os.environ.keys():
if not var_name.startswith("DB") and \
var_name not in ["PATH", "PYTHONPATH"]:
logging.debug("Deleting environment variable %s with value %s" % (var_name, os.environ.get(var_name)))
del os.environ[var_name]
importlib.reload(edb)

def tearDown(self):
#All tests insert tokens of length one. Delete them once the test is done.
Expand Down Expand Up @@ -158,34 +170,18 @@ def test_run_script_show(self):
sp = subprocess.run(["python3", "bin/auth/insert_tokens.py", "--show"], capture_output=True)
# The first message is displayed when we run tests locally
# The second is displayed when we run in the docker CI, since the `DB_HOST` is set to `db`
stripped_out_stdout = sp.stdout\
.replace(b"\'CONDA_EXE\': \'/root/miniconda-23.5.2/bin/conda\', ",b"")\
.replace(b"\'HOSTNAME\': \'78346225cfef\', ",b"")\
.replace(b"\'EXP_CONDA_VER\': \'23.5.2\', ",b"")\
.replace(b"\'CONDA_PREFIX\': \'/root/miniconda-23.5.2/envs/emissiontest\', ",b"")\
.replace(b"\'CONDA_PYTHON_EXE\': \'/root/miniconda-23.5.2/bin/python\', ",b"")\
.replace(b"\'PATH\': \'/root/miniconda-23.5.2/envs/emissiontest/bin:/root/miniconda-23.5.2/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\', ",b"")\
.replace(b"\'_\': \'/root/miniconda-23.5.2/envs/emissiontest/bin/python\'",b"")
self.assertIn(stripped_out_stdout,
self.assertIn(sp.stdout,
[b'Retrieved config {\'DB_HOST\': \'localhost\', \'DB_RESULT_LIMIT\': 250000}\nURL not formatted, defaulting to "Stage_database"\nConnecting to database URL localhost\nx\ny\nz\n',
b'Config file not found, returning a copy of the environment variables instead...\nRetrieved config {\'PYTHONPATH\': \'.\', \'_CE_M\': \'\', \'PWD\': \'/src/e-mission-server\', \'WEB_SERVER_HOST\': \'0.0.0.0\', \'HOME\': \'/root\', \'CONDA_PROMPT_MODIFIER\': \'(emissiontest) \', \'_CE_CONDA\': \'\', \'DB_HOST\': \'db\', \'CONDA_SHLVL\': \'1\', \'SHLVL\': \'2\', \'CONDA_DEFAULT_ENV\': \'emissiontest\', \'EXP_CONDA_VER_SUFFIX\': \'0\', \'OLDPWD\': \'/\', \'LC_CTYPE\': \'C.UTF-8\', \'KMP_DUPLICATE_LIB_OK\': \'True\', \'KMP_INIT_AT_FORK\': \'FALSE\'}\nURL not formatted, defaulting to "Stage_database"\nConnecting to database URL db\nx\ny\nz\n'
b'Config file not found, returning a copy of the environment variables instead...\nRetrieved config {\'DB_HOST\': \'db\', \'DB_RESULT_LIMIT\': 250000}\nURL not formatted, defaulting to "Stage_database"\nConnecting to database URL db\nx\ny\nz\n'
])

def test_run_script_empty(self):
sp = subprocess.run(["python3", "bin/auth/insert_tokens.py"], capture_output=True)
# The first message is displayed when we run tests locally
# The second is displayed when we run in the docker CI, since the `DB_HOST` is set to `db`
stripped_out_stdout = sp.stdout\
.replace(b"\'CONDA_EXE\': \'/root/miniconda-23.5.2/bin/conda\', ",b"")\
.replace(b"\'HOSTNAME\': \'78346225cfef\', ",b"")\
.replace(b"\'EXP_CONDA_VER\': \'23.5.2\', ",b"")\
.replace(b"\'CONDA_PREFIX\': \'/root/miniconda-23.5.2/envs/emissiontest\', ",b"")\
.replace(b"\'CONDA_PYTHON_EXE\': \'/root/miniconda-23.5.2/bin/python\', ",b"")\
.replace(b"\'PATH\': \'/root/miniconda-23.5.2/envs/emissiontest/bin:/root/miniconda-23.5.2/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\', ",b"")\
.replace(b"\'_\': \'/root/miniconda-23.5.2/envs/emissiontest/bin/python\'",b"")
self.assertIn(stripped_out_stdout,
self.assertIn(sp.stdout,
[b'Retrieved config {\'DB_HOST\': \'localhost\', \'DB_RESULT_LIMIT\': 250000}\nURL not formatted, defaulting to "Stage_database"\nConnecting to database URL localhost\nPlease provide the script with an argument. Use the "--help" option for more details\n',
b'Config file not found, returning a copy of the environment variables instead...\nRetrieved config {\'PYTHONPATH\': \'.\', \'_CE_M\': \'\', \'PWD\': \'/src/e-mission-server\', \'WEB_SERVER_HOST\': \'0.0.0.0\', \'HOME\': \'/root\', \'CONDA_PROMPT_MODIFIER\': \'(emissiontest) \', \'_CE_CONDA\': \'\', \'DB_HOST\': \'db\', \'CONDA_SHLVL\': \'1\', \'SHLVL\': \'2\', \'CONDA_DEFAULT_ENV\': \'emissiontest\', \'EXP_CONDA_VER_SUFFIX\': \'0\', \'OLDPWD\': \'/\', \'LC_CTYPE\': \'C.UTF-8\', \'KMP_DUPLICATE_LIB_OK\': \'True\', \'KMP_INIT_AT_FORK\': \'FALSE\'}\nURL not formatted, defaulting to "Stage_database"\nConnecting to database URL db\nPlease provide the script with an argument. Use the "--help" option for more details\n'
b'Config file not found, returning a copy of the environment variables instead...\nRetrieved config {\'DB_HOST\': \'db\', \'DB_RESULT_LIMIT\': 250000}\nURL not formatted, defaulting to "Stage_database"\nConnecting to database URL db\nPlease provide the script with an argument. Use the "--help" option for more details\n'
])

#test that no two options can be used together
Expand Down

0 comments on commit 1a0d451

Please sign in to comment.