refactor to remove config_files in favor of db
This commit is contained in:
@@ -13,7 +13,7 @@ from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
from web.app import create_app
|
||||
from web.models import Base, Scan
|
||||
from web.models import Base, Scan, ScanConfig
|
||||
from web.utils.settings import PasswordManager, SettingsManager
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ def sample_scan_report():
|
||||
'title': 'Test Scan',
|
||||
'scan_time': '2025-11-14T10:30:00Z',
|
||||
'scan_duration': 125.5,
|
||||
'config_file': '/app/configs/test.yaml',
|
||||
'config_id': 1,
|
||||
'sites': [
|
||||
{
|
||||
'name': 'Test Site',
|
||||
@@ -199,6 +199,53 @@ def sample_invalid_config_file(tmp_path):
|
||||
return str(config_file)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_db_config(db):
|
||||
"""
|
||||
Create a sample database config for testing.
|
||||
|
||||
Args:
|
||||
db: Database session fixture
|
||||
|
||||
Returns:
|
||||
ScanConfig model instance with ID
|
||||
"""
|
||||
import json
|
||||
|
||||
config_data = {
|
||||
'title': 'Test Scan',
|
||||
'sites': [
|
||||
{
|
||||
'name': 'Test Site',
|
||||
'ips': [
|
||||
{
|
||||
'address': '192.168.1.10',
|
||||
'expected': {
|
||||
'ping': True,
|
||||
'tcp_ports': [22, 80, 443],
|
||||
'udp_ports': [53],
|
||||
'services': ['ssh', 'http', 'https']
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
scan_config = ScanConfig(
|
||||
title='Test Scan',
|
||||
config_data=json.dumps(config_data),
|
||||
created_at=datetime.utcnow(),
|
||||
updated_at=datetime.utcnow()
|
||||
)
|
||||
|
||||
db.add(scan_config)
|
||||
db.commit()
|
||||
db.refresh(scan_config)
|
||||
|
||||
return scan_config
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def app():
|
||||
"""
|
||||
@@ -269,7 +316,7 @@ def sample_scan(db):
|
||||
scan = Scan(
|
||||
timestamp=datetime.utcnow(),
|
||||
status='completed',
|
||||
config_file='/app/configs/test.yaml',
|
||||
config_id=1,
|
||||
title='Test Scan',
|
||||
duration=125.5,
|
||||
triggered_by='test',
|
||||
|
||||
Reference in New Issue
Block a user