Add mockapi source files and tests
Some checks failed
CI / build (push) Has been cancelled
CI / test (push) Has been cancelled

This commit is contained in:
2026-03-22 21:59:13 +00:00
parent 9504a6edfc
commit 730be92a3d

View File

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