117 lines
3.8 KiB
Python
117 lines
3.8 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test script to verify that S7P projects also get global configurations applied
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
|
|
# Add src to path so we can import the modules
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src"))
|
|
|
|
from models.config_model import Config
|
|
from services.project_discovery_service import ProjectDiscoveryService
|
|
from models.project_model import ProjectManager
|
|
|
|
|
|
def test_s7p_project_global_config():
|
|
"""Test that S7P projects get global configurations applied"""
|
|
|
|
# Create a temporary config
|
|
config = Config()
|
|
|
|
# Create project manager
|
|
project_manager = ProjectManager()
|
|
|
|
# Create discovery service
|
|
discovery_service = ProjectDiscoveryService(config, project_manager)
|
|
|
|
# Test S7P project creation
|
|
print("Testing S7P project creation...")
|
|
obs_dir = {
|
|
"path": "D:\\Test\\ObservationDir",
|
|
"type": "siemens_s7",
|
|
"description": "Test S7 observation directory",
|
|
}
|
|
|
|
# Simulate an S7P file path
|
|
s7p_file_path = "D:\\Test\\ObservationDir\\TestProject\\TestProject.s7p"
|
|
|
|
# Create the S7P project
|
|
s7p_project = discovery_service._create_project_from_s7p(s7p_file_path, obs_dir)
|
|
|
|
if s7p_project:
|
|
print("✅ S7P project created successfully")
|
|
|
|
# Check if global configurations were applied
|
|
project_dict = s7p_project.to_dict()
|
|
schedule_config_keys = list(project_dict["schedule_config"].keys())
|
|
has_backup_options = "backup_options" in project_dict
|
|
|
|
print(f"Schedule config keys: {schedule_config_keys}")
|
|
print(f"Has backup_options: {has_backup_options}")
|
|
|
|
# Verify specific global settings
|
|
schedule_config = project_dict["schedule_config"]
|
|
backup_options = project_dict.get("backup_options", {})
|
|
|
|
print(
|
|
f"Retry delay hours: {schedule_config.get('retry_delay_hours', 'MISSING')}"
|
|
)
|
|
print(
|
|
f"Backup timeout: {schedule_config.get('backup_timeout_minutes', 'MISSING')}"
|
|
)
|
|
print(
|
|
f"Min backup interval: {schedule_config.get('min_backup_interval_minutes', 'MISSING')}"
|
|
)
|
|
print(f"Min free space: {schedule_config.get('min_free_space_mb', 'MISSING')}")
|
|
print(
|
|
f"Compression level: {backup_options.get('compression_level', 'MISSING')}"
|
|
)
|
|
print(f"Hash algorithm: {backup_options.get('hash_algorithm', 'MISSING')}")
|
|
|
|
# Check if all expected keys are present
|
|
expected_schedule_keys = [
|
|
"schedule",
|
|
"schedule_time",
|
|
"enabled",
|
|
"next_scheduled_backup",
|
|
"retry_delay_hours",
|
|
"backup_timeout_minutes",
|
|
"min_backup_interval_minutes",
|
|
"min_free_space_mb",
|
|
]
|
|
|
|
expected_backup_keys = [
|
|
"compression_level",
|
|
"include_subdirectories",
|
|
"preserve_directory_structure",
|
|
"hash_algorithm",
|
|
"hash_includes",
|
|
"backup_type",
|
|
"process_priority",
|
|
"sequential_execution",
|
|
"filename_format",
|
|
"date_format",
|
|
]
|
|
|
|
missing_schedule_keys = [
|
|
key for key in expected_schedule_keys if key not in schedule_config
|
|
]
|
|
missing_backup_keys = [
|
|
key for key in expected_backup_keys if key not in backup_options
|
|
]
|
|
|
|
if not missing_schedule_keys and not missing_backup_keys:
|
|
print("✅ ALL global configurations successfully applied to S7P project!")
|
|
else:
|
|
print(f"❌ Missing schedule keys: {missing_schedule_keys}")
|
|
print(f"❌ Missing backup keys: {missing_backup_keys}")
|
|
|
|
else:
|
|
print("❌ Failed to create S7P project")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
test_s7p_project_global_config()
|