pytest-api/apiclient/config.py

28 lines
934 B
Python
Raw Normal View History

2024-07-20 10:47:11 +00:00
import os
from dotenv import load_dotenv
from types import MappingProxyType
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
def get_cfg(env='qa'):
environment_name = os.getenv('ENV_NAME', env)
dotenv_path = os.path.join(PROJECT_ROOT, f'.env.{environment_name}')
if not os.path.exists(dotenv_path):
raise FileNotFoundError(f"{dotenv_path} does not exist")
load_dotenv(dotenv_path)
config_dict = {
'client_id': os.getenv('CLIENT_ID'),
'client_secret': os.getenv('CLIENT_SECRET'),
'token_url': os.getenv('TOKEN_FETCH_URL'),
'login': os.getenv('LOGIN'),
'password': os.getenv('PASSWORD'),
'audience': os.getenv('AUDIENCE'),
'scopes': os.getenv('SCOPES', '').split(','),
'api_url': os.getenv('API_URL')
}
config = MappingProxyType(config_dict) # immutable dict
return config