Skip to content

Commit

Permalink
Ensure that an environment variable is created for TestEnvInterpolation
Browse files Browse the repository at this point in the history
The previous code expect USER environment variable, but in good test
environment this requirement is not met.
  • Loading branch information
gschwind committed Sep 19, 2023
1 parent 8d83403 commit 184b344
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions tests/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,36 @@
from basic import TestBase
import os

import random

from pywps import configuration


class TestEnvInterpolation(TestBase):
"""Test cases for env variable interpolation within the configuration."""
test_value = "SOME_RANDOM_VALUE"

def setUp(self) -> None:
super().setUp()
# Generate an unused environment key
self.test_key = "SOME_RANDOM_KEY"
while self.test_key in os.environ:
self.test_key = "".join(random.choices("ABCDEFGHIJKLMNOPQRSTUVWXYZ", k=32))
os.environ[self.test_key] = self.test_value

def tearDown(self) -> None:
del os.environ[self.test_key]
super().tearDown()

def test_expand_user(self):
"""Ensure we can parse a value with the $USER entry."""
user = os.environ.get("USER")
configuration.CONFIG.read_string("[envinterpolationsection]\nuser=$USER")
assert user == configuration.CONFIG["envinterpolationsection"]["user"]
configuration.CONFIG.read_string(f"[envinterpolationsection]\nuser=${self.test_key}")
assert self.test_value == configuration.CONFIG["envinterpolationsection"]["user"]

def test_expand_user_with_some_text(self):
"""Ensure we can parse a value with the $USER entry and some more text."""
user = os.environ.get("USER")
new_user = "new_" + user
configuration.CONFIG.read_string("[envinterpolationsection]\nuser=new_${USER}")
new_user = "new_" + self.test_value
configuration.CONFIG.read_string(f"[envinterpolationsection]\nuser=new_${{{self.test_key}}}")
assert new_user == configuration.CONFIG["envinterpolationsection"]["user"]

def test_dont_expand_value_without_env_variable(self):
Expand Down

0 comments on commit 184b344

Please sign in to comment.