This commit removes the OPC server integration from the Model Manager, including related activities, repositories, metrics, and configuration. It also adds code quality tools such as Ruff (linting/formatting), mypy (type checking), and Bandit (security analysis) along with a validation script and CI/CD integration for automated code validation. The README has been updated to reflect these changes.
113 lines
3.5 KiB
Python
113 lines
3.5 KiB
Python
from os import environ
|
|
from model_manager.utils.connectors_config import (build_mlflow_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_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
|
|
}
|