This commit renames the 'laborious' package to 'model_manager' across the entire project. This includes renaming directories, modules, references in code, configuration files, and documentation to reflect the new package name. This change improves clarity and consistency within the project.
162 lines
4.9 KiB
Python
162 lines
4.9 KiB
Python
from os import environ
|
|
from model_manager.utils.connectors_config import (build_mlflow_config,
|
|
build_opc_config,
|
|
build_postgres_config,
|
|
build_mongodb_config)
|
|
|
|
|
|
def test_build_mlflow_config_with_env_vars():
|
|
# Arrange
|
|
environ['MLFLOW_HOST'] = 'http://test-host'
|
|
environ['MLFLOW_PORT'] = '8080'
|
|
environ['MLFLOW_USERNAME'] = 'test-user'
|
|
environ['MLFLOW_PASSWORD'] = 'test-pass'
|
|
|
|
# Act
|
|
config = build_mlflow_config()
|
|
|
|
# Assert
|
|
assert config['host'] == 'http://test-host'
|
|
assert config['port'] == 8080
|
|
assert config['username'] == 'test-user'
|
|
assert config['password'] == 'test-pass'
|
|
|
|
|
|
def test_build_mlflow_config_with_defaults():
|
|
# Arrange
|
|
# Clear any existing env vars
|
|
environ.pop('MLFLOW_HOST', None)
|
|
environ.pop('MLFLOW_PORT', None)
|
|
environ.pop('MLFLOW_USERNAME', None)
|
|
environ.pop('MLFLOW_PASSWORD', None)
|
|
|
|
# Act
|
|
config = build_mlflow_config()
|
|
|
|
# Assert
|
|
assert config['host'] == 'http://localhost'
|
|
assert config['port'] == 5080
|
|
assert config['username'] == 'aignosi'
|
|
assert config['password'] == 'aignosi'
|
|
|
|
|
|
def test_build_opc_config_with_env_vars():
|
|
# Arrange
|
|
environ['OPC_CONFIG'] = '{"opc": {"name": "test-opc", "url": "opc.tcp://test:4840"}}'
|
|
|
|
# Act
|
|
config = build_opc_config()
|
|
|
|
# Assert
|
|
assert config['opc']['name'] == 'test-opc'
|
|
assert config['opc']['url'] == 'opc.tcp://test:4840'
|
|
|
|
|
|
def test_build_opc_config_with_individual_env_vars():
|
|
# Arrange
|
|
environ.pop('OPC_CONFIG', None)
|
|
environ['OPC_ID'] = '1'
|
|
environ['OPC_URL'] = 'opc.tcp://test:4840'
|
|
environ['OPC_SERVER_URI'] = 'opc.tcp://test:4840'
|
|
environ['OPC_RECONNECTION_INTERVAL'] = '300'
|
|
|
|
# Act
|
|
config = build_opc_config()
|
|
|
|
# Assert
|
|
assert config['1']['id'] == '1'
|
|
assert config['1']['url'] == 'opc.tcp://test:4840'
|
|
assert config['1']['server_uri'] == 'opc.tcp://test:4840'
|
|
assert config['1']['reconnection_interval'] == 300
|
|
|
|
|
|
def test_build_opc_config_with_defaults():
|
|
# Arrange
|
|
environ.pop('OPC_CONFIG', None)
|
|
environ.pop('OPC_ID', None)
|
|
environ.pop('OPC_URL', None)
|
|
environ.pop('OPC_SERVER_URI', None)
|
|
environ.pop('OPC_RECONNECTION_INTERVAL', None)
|
|
|
|
# Act
|
|
config = build_opc_config()
|
|
|
|
# Assert
|
|
assert config['1']['id'] == '1'
|
|
assert config['1']['url'] == 'opc.tcp://localhost:4840'
|
|
assert config['1']['server_uri'] == 'opc.tcp://localhost:4840'
|
|
assert config['1']['reconnection_interval'] == 120
|
|
|
|
|
|
def test_build_postgres_config_with_env_vars():
|
|
# Arrange
|
|
environ['POSTGRES_HOST'] = 'test-host'
|
|
environ['POSTGRES_PORT'] = '5433'
|
|
environ['POSTGRES_USER'] = 'test-user'
|
|
environ['POSTGRES_PASSWORD'] = 'test-pass'
|
|
environ['POSTGRES_DBNAME'] = 'test-db'
|
|
environ['POSTGRES_MIN_CONNECTIONS'] = '10'
|
|
environ['POSTGRES_MAX_CONNECTIONS'] = '30'
|
|
|
|
# Act
|
|
config = build_postgres_config()
|
|
|
|
# Assert
|
|
assert config['host'] == 'test-host'
|
|
assert config['port'] == 5433
|
|
assert config['user'] == 'test-user'
|
|
assert config['password'] == 'test-pass'
|
|
assert config['dbname'] == 'test-db'
|
|
assert config['min_connections'] == 10
|
|
assert config['max_connections'] == 30
|
|
|
|
|
|
def test_build_postgres_config_with_defaults():
|
|
# Arrange
|
|
environ.pop('POSTGRES_HOST', None)
|
|
environ.pop('POSTGRES_PORT', None)
|
|
environ.pop('POSTGRES_USER', None)
|
|
environ.pop('POSTGRES_PASSWORD', None)
|
|
environ.pop('POSTGRES_DBNAME', None)
|
|
environ.pop('POSTGRES_MIN_CONNECTIONS', None)
|
|
environ.pop('POSTGRES_MAX_CONNECTIONS', None)
|
|
|
|
# Act
|
|
config = build_postgres_config()
|
|
|
|
# Assert
|
|
assert config['host'] == 'localhost'
|
|
assert config['port'] == 5432
|
|
assert config['user'] == 'sientia'
|
|
assert config['password'] == 'sientia'
|
|
assert config['dbname'] == 'sientia'
|
|
assert config['min_connections'] == 5
|
|
assert config['max_connections'] == 20
|
|
|
|
|
|
def test_build_mongo_db_config_with_env_vars():
|
|
environ['MONGODB_USERNAME'] = 'sientia1'
|
|
environ['MONGODB_PASSWORD'] = 'sientia1'
|
|
environ['MONGODB_URL'] = 'localhost:27018'
|
|
environ['MONGODB_DATABASE_NAME'] = 'test_db'
|
|
environ['MONGODB_TTL_INDEX_HOURS'] = '1'
|
|
|
|
assert build_mongodb_config() == {
|
|
'connection_string': 'mongodb://sientia1:sientia1@localhost:27018',
|
|
'database_name': 'test_db',
|
|
'ttl_index_seconds': 3600
|
|
}
|
|
|
|
|
|
def test_build_mongo_db_config_with_defaults():
|
|
environ.pop('MONGODB_USERNAME', None)
|
|
environ.pop('MONGODB_PASSWORD', None)
|
|
environ.pop('MONGODB_DATABASE_NAME', None)
|
|
environ.pop('MONGODB_URL', None)
|
|
environ.pop('MONGODB_TTL_INDEX_HOURS', None)
|
|
assert build_mongodb_config() == {
|
|
'connection_string': 'mongodb://root:wKZDbMNU1c@localhost:27018',
|
|
'database_name': 'sientia',
|
|
'ttl_index_seconds': 3600
|
|
}
|