Files
orion/powershell_migration_script.ps1
2025-09-19 16:54:13 +02:00

113 lines
5.3 KiB
PowerShell

# migrate_tests.ps1 - PowerShell script to migrate your test structure
Write-Host "🚀 Starting test structure migration..." -ForegroundColor Cyan
# Create new directory structure
Write-Host "📁 Creating directory structure..." -ForegroundColor Yellow
$directories = @(
"tests\fixtures",
"tests\unit", "tests\unit\models", "tests\unit\utils", "tests\unit\services",
"tests\integration", "tests\integration\api", "tests\integration\api\v1", "tests\integration\security",
"tests\performance",
"tests\system",
"tests\test_data", "tests\test_data\csv"
)
foreach ($dir in $directories) {
New-Item -Path $dir -ItemType Directory -Force | Out-Null
Write-Host " Created: $dir" -ForegroundColor Gray
}
# Create __init__.py files
Write-Host "📄 Creating __init__.py files..." -ForegroundColor Yellow
$initFiles = @(
"tests\fixtures\__init__.py",
"tests\unit\__init__.py", "tests\unit\models\__init__.py", "tests\unit\utils\__init__.py", "tests\unit\services\__init__.py",
"tests\integration\__init__.py", "tests\integration\api\__init__.py", "tests\integration\api\v1\__init__.py", "tests\integration\security\__init__.py",
"tests\performance\__init__.py",
"tests\system\__init__.py"
)
foreach ($file in $initFiles) {
New-Item -Path $file -ItemType File -Force | Out-Null
Write-Host " Created: $file" -ForegroundColor Gray
}
# Create conftest.py files for each test category
Write-Host "⚙️ Creating conftest.py files..." -ForegroundColor Yellow
$conftestFiles = @(
"tests\unit\conftest.py",
"tests\integration\conftest.py",
"tests\performance\conftest.py",
"tests\system\conftest.py"
)
foreach ($file in $conftestFiles) {
New-Item -Path $file -ItemType File -Force | Out-Null
Write-Host " Created: $file" -ForegroundColor Gray
}
# Backup original files
Write-Host "💾 Backing up original files..." -ForegroundColor Yellow
New-Item -Path "tests\backup" -ItemType Directory -Force | Out-Null
if (Test-Path "tests\conftest.py") {
Copy-Item "tests\conftest.py" "tests\backup\" -Force
Write-Host " Backed up: conftest.py" -ForegroundColor Gray
}
Get-ChildItem "tests\test_*.py" -ErrorAction SilentlyContinue | ForEach-Object {
Copy-Item $_.FullName "tests\backup\" -Force
Write-Host " Backed up: $($_.Name)" -ForegroundColor Gray
}
# Create sample test data file
Write-Host "📊 Creating sample test data..." -ForegroundColor Yellow
$csvContent = @"
product_id,title,price,currency,brand,marketplace
TEST001,Sample Product 1,19.99,EUR,TestBrand,TestMarket
TEST002,Sample Product 2,29.99,EUR,TestBrand,TestMarket
TEST003,Sample Product 3,39.99,USD,AnotherBrand,TestMarket
"@
$csvContent | Out-File -FilePath "tests\test_data\csv\sample_products.csv" -Encoding UTF8
Write-Host " Created: sample_products.csv" -ForegroundColor Gray
Write-Host "✅ Directory structure created!" -ForegroundColor Green
Write-Host ""
Write-Host "📋 Next steps:" -ForegroundColor Cyan
Write-Host "1. Copy the fixture files I provided to tests\fixtures\" -ForegroundColor White
Write-Host "2. Update tests\conftest.py with the new version" -ForegroundColor White
Write-Host "3. Move test files to their new locations:" -ForegroundColor White
Write-Host " - test_database.py → tests\unit\models\test_database_models.py" -ForegroundColor Gray
Write-Host " - test_utils.py → tests\unit\utils\test_data_processing.py" -ForegroundColor Gray
Write-Host " - test_admin_service.py → tests\unit\services\" -ForegroundColor Gray
Write-Host " - test_admin.py → tests\integration\api\v1\test_admin_endpoints.py" -ForegroundColor Gray
Write-Host " - test_pagination.py → tests\integration\api\v1\" -ForegroundColor Gray
Write-Host " - test_performance.py → tests\performance\test_api_performance.py" -ForegroundColor Gray
Write-Host " - test_error_handling.py → tests\system\" -ForegroundColor Gray
Write-Host " - Split test_security.py into security subdirectory" -ForegroundColor Gray
Write-Host ""
Write-Host "4. Update imports in moved test files" -ForegroundColor White
Write-Host "5. Add pytest markers to test classes" -ForegroundColor White
Write-Host "6. Update pytest.ini with the enhanced configuration" -ForegroundColor White
Write-Host ""
Write-Host "🧪 Test the migration with:" -ForegroundColor Cyan
Write-Host "pytest tests\unit -v" -ForegroundColor Yellow
Write-Host "pytest tests\integration -v" -ForegroundColor Yellow
Write-Host "pytest -m unit" -ForegroundColor Yellow
Write-Host ""
Write-Host "🔧 Quick test commands after migration:" -ForegroundColor Cyan
Write-Host "pytest -m unit # Fast unit tests" -ForegroundColor White
Write-Host "pytest -m integration # Integration tests" -ForegroundColor White
Write-Host "pytest -m `"not slow`" # Skip slow tests" -ForegroundColor White
Write-Host "pytest tests\unit\models\ # Model tests only" -ForegroundColor White
Write-Host "pytest --cov=app --cov-report=html # Coverage report" -ForegroundColor White
Write-Host ""
Write-Host "✨ Migration structure ready! Follow the steps above to complete the migration." -ForegroundColor Green
Write-Host "📚 All your original files are backed up in tests\backup\" -ForegroundColor Green
# Optional: Pause to let user read the output
Write-Host ""
Write-Host "Press any key to continue..." -ForegroundColor DarkGray
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")