Skip to content

Commit

Permalink
test: add missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rekyungmin committed Sep 16, 2021
1 parent eefaec5 commit 9b63964
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ class Settings(BaseSettings):
test_default_env_file = """\
debug_mode=true
host=localhost
port=8000
Port=8000
"""

test_prod_env_file = """\
Expand Down Expand Up @@ -857,6 +857,32 @@ class Settings(BaseSettings):
assert s.port == 8000


@pytest.mark.skipif(not dotenv, reason='python-dotenv not installed')
def test_read_process_env_vars(env):
assert EnvSettingsSource._read_process_env_vars(True) == os.environ
env.set('CaseSensitiveVariable', '')
assert EnvSettingsSource._read_process_env_vars(False) != os.environ


@pytest.mark.skipif(not dotenv, reason='python-dotenv not installed')
def test_read_dotenv_vars(tmp_path):
base_env = tmp_path / '.env'
base_env.write_text(test_default_env_file)
prod_env = tmp_path / '.env.prod'
prod_env.write_text(test_prod_env_file)

assert EnvSettingsSource._read_dotenv_vars(
env_files=[prod_env, base_env], env_file_encoding='utf8', case_sensitive=False
) == {'debug_mode': 'false', 'host': 'https://example.com/services', 'port': '8000'}
assert EnvSettingsSource._read_dotenv_vars(
env_files=[prod_env, base_env], env_file_encoding='utf8', case_sensitive=True
) == {'debug_mode': 'false', 'host': 'https://example.com/services', 'Port': '8000'}
assert EnvSettingsSource._read_dotenv_vars(
env_files=[prod_env, 'does_not_exist_file'], env_file_encoding='utf8', case_sensitive=False
) == {'debug_mode': 'false', 'host': 'https://example.com/services'}
assert EnvSettingsSource._read_dotenv_vars(env_files=None, env_file_encoding=None, case_sensitive=False) == {}


@pytest.mark.skipif(dotenv, reason='python-dotenv is installed')
def test_dotenv_not_installed(tmp_path):
p = tmp_path / '.env'
Expand Down

0 comments on commit 9b63964

Please sign in to comment.