Add mockapi source files and tests
This commit is contained in:
@@ -22,19 +22,11 @@ class Config:
|
||||
strict_validation: bool = False
|
||||
error_probability: float = 0.0
|
||||
error_code: int = 500
|
||||
|
||||
config_path: Optional[str] = None
|
||||
|
||||
@classmethod
|
||||
def load(cls, config_path: Optional[str] = None) -> "Config":
|
||||
"""Load configuration from file and environment.
|
||||
|
||||
Args:
|
||||
config_path: Path to mockapi.yaml config file
|
||||
|
||||
Returns:
|
||||
Config instance with loaded values
|
||||
"""
|
||||
"""Load configuration from file and environment."""
|
||||
config = cls()
|
||||
|
||||
if config_path:
|
||||
@@ -62,11 +54,7 @@ class Config:
|
||||
|
||||
@classmethod
|
||||
def _load_from_env(cls) -> Dict[str, Any]:
|
||||
"""Load configuration from environment variables.
|
||||
|
||||
Returns:
|
||||
Dictionary of configuration values
|
||||
"""
|
||||
"""Load configuration from environment variables."""
|
||||
config = {}
|
||||
|
||||
if port := os.environ.get("MOCKAPI_PORT"):
|
||||
@@ -88,14 +76,7 @@ class Config:
|
||||
|
||||
@classmethod
|
||||
def _load_from_file(cls, config_path: str) -> Dict[str, Any]:
|
||||
"""Load configuration from YAML file.
|
||||
|
||||
Args:
|
||||
config_path: Path to the config file
|
||||
|
||||
Returns:
|
||||
Dictionary of configuration values
|
||||
"""
|
||||
"""Load configuration from YAML file."""
|
||||
try:
|
||||
with open(config_path, "r") as f:
|
||||
data = yaml.safe_load(f) or {}
|
||||
@@ -129,11 +110,7 @@ class Config:
|
||||
return {}
|
||||
|
||||
def to_dict(self) -> Dict[str, Any]:
|
||||
"""Convert config to dictionary.
|
||||
|
||||
Returns:
|
||||
Dictionary representation of config
|
||||
"""
|
||||
"""Convert config to dictionary."""
|
||||
return {
|
||||
"port": self.port,
|
||||
"host": self.host,
|
||||
@@ -149,12 +126,5 @@ class Config:
|
||||
|
||||
|
||||
def load_config(config_path: Optional[str] = None) -> Config:
|
||||
"""Load configuration from file and environment.
|
||||
|
||||
Args:
|
||||
config_path: Optional path to config file
|
||||
|
||||
Returns:
|
||||
Config instance
|
||||
"""
|
||||
return Config.load(config_path)
|
||||
"""Load configuration from file and environment."""
|
||||
return Config.load(config_path)
|
||||
|
||||
Reference in New Issue
Block a user