This commit includes several changes: - Reorganized imports and class inheritance in activities.py, gates.py and mlflow.py for better readability and maintainability. - Improved error handling and logging in gates.py and mlflow.py. - Added input validation and filtering in gates.py to ensure data quality. - Enhanced prediction formatting and storage policy management in gates.py. - Updated metrics.py to use consistent naming conventions and labels. - Refactored connectors_config.py to use type hints and improve code clarity. - Updated conditional and MLFlow filters for better data quality checks. - Improved model repository logic for retraining and updating models. - Enhanced worker.py to include SDK metrics and improved error handling. - Refactored workflows for better modularity and error handling. - Updated tests to reflect the changes and improve test coverage.
116 lines
3.4 KiB
Python
116 lines
3.4 KiB
Python
from os import environ
|
|
|
|
from model_manager.utils.connectors_config import (
|
|
build_mlflow_config,
|
|
build_mongodb_config,
|
|
build_postgres_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,
|
|
}
|