Switch to angular

This commit is contained in:
pratik
2025-10-14 23:32:38 -05:00
parent 1ce27976a9
commit f6d1412bc8
71 changed files with 5542 additions and 991 deletions

View File

@@ -23,6 +23,7 @@ sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')
from app.database import SessionLocal
from app.models.artifact import Artifact
from app.models.tag import Tag
from app.storage import get_storage_backend
from app.config import settings
@@ -48,6 +49,22 @@ TAGS = [
"integration", "unit", "e2e", "api"
]
# Predefined tags with descriptions and colors
PREDEFINED_TAGS = [
{"name": "regression", "description": "Regression tests to verify existing functionality", "color": "#FF6B6B"},
{"name": "smoke", "description": "Quick smoke tests for basic functionality", "color": "#4ECDC4"},
{"name": "critical", "description": "Critical tests that must pass", "color": "#E74C3C"},
{"name": "high-priority", "description": "High priority tests", "color": "#F39C12"},
{"name": "automated", "description": "Automated test execution", "color": "#3498DB"},
{"name": "manual", "description": "Manual test execution required", "color": "#9B59B6"},
{"name": "performance", "description": "Performance and load tests", "color": "#1ABC9C"},
{"name": "security", "description": "Security and vulnerability tests", "color": "#E67E22"},
{"name": "integration", "description": "Integration tests between components", "color": "#2ECC71"},
{"name": "unit", "description": "Unit tests for individual components", "color": "#16A085"},
{"name": "e2e", "description": "End-to-end user journey tests", "color": "#8E44AD"},
{"name": "api", "description": "API endpoint tests", "color": "#2C3E50"},
]
def generate_csv_content() -> bytes:
"""Generate random CSV test data"""
@@ -183,6 +200,49 @@ def get_file_type(filename: str) -> str:
return type_mapping.get(extension, 'binary')
async def seed_predefined_tags() -> List[int]:
"""
Seed predefined tags into the database.
Returns:
List of created tag IDs
"""
db = SessionLocal()
tag_ids = []
try:
print("Seeding predefined tags...")
for tag_data in PREDEFINED_TAGS:
# Check if tag already exists
existing_tag = db.query(Tag).filter(Tag.name == tag_data["name"]).first()
if existing_tag:
print(f" Tag '{tag_data['name']}' already exists, skipping...")
tag_ids.append(existing_tag.id)
continue
tag = Tag(
name=tag_data["name"],
description=tag_data["description"],
color=tag_data["color"]
)
db.add(tag)
db.commit()
db.refresh(tag)
tag_ids.append(tag.id)
print(f" Created tag: {tag_data['name']}")
print(f"✓ Successfully seeded {len(tag_ids)} tags")
return tag_ids
except Exception as e:
db.rollback()
print(f"✗ Error seeding tags: {e}")
raise
finally:
db.close()
async def generate_seed_data(num_artifacts: int = 50) -> List[int]:
"""
Generate and upload seed data to the database and storage.
@@ -197,7 +257,11 @@ async def generate_seed_data(num_artifacts: int = 50) -> List[int]:
artifact_ids = []
try:
print(f"Generating {num_artifacts} seed artifacts...")
# First, seed tags
print("Step 1: Seeding tags...")
await seed_predefined_tags()
print(f"\nStep 2: Generating {num_artifacts} seed artifacts...")
print(f"Deployment mode: {settings.deployment_mode}")
print(f"Storage backend: {settings.storage_backend}")
@@ -269,42 +333,54 @@ async def generate_seed_data(num_artifacts: int = 50) -> List[int]:
async def clear_all_data():
"""
Clear all artifacts from database and storage.
Clear all artifacts and tags from database and storage.
WARNING: This will delete ALL data!
"""
db = SessionLocal()
storage = get_storage_backend()
try:
print("Clearing all artifacts...")
print("Clearing all data...")
# Get all artifacts
# Clear artifacts
artifacts = db.query(Artifact).all()
count = len(artifacts)
artifact_count = len(artifacts)
if count == 0:
if artifact_count > 0:
print(f"Found {artifact_count} artifacts to delete...")
# Delete from storage and database
for i, artifact in enumerate(artifacts):
try:
# Delete from storage
object_name = artifact.storage_path.split('/')[-1]
await storage.delete_file(object_name)
except Exception as e:
print(f" Warning: Could not delete {artifact.filename} from storage: {e}")
# Delete from database
db.delete(artifact)
if (i + 1) % 10 == 0:
print(f" Deleted {i + 1}/{artifact_count} artifacts...")
db.commit()
print(f"✓ Successfully deleted {artifact_count} artifacts")
else:
print("No artifacts to delete.")
return
print(f"Found {count} artifacts to delete...")
# Clear tags
tags = db.query(Tag).all()
tag_count = len(tags)
# Delete from storage and database
for i, artifact in enumerate(artifacts):
try:
# Delete from storage
object_name = artifact.storage_path.split('/')[-1]
await storage.delete_file(object_name)
except Exception as e:
print(f" Warning: Could not delete {artifact.filename} from storage: {e}")
# Delete from database
db.delete(artifact)
if (i + 1) % 10 == 0:
print(f" Deleted {i + 1}/{count} artifacts...")
db.commit()
print(f"✓ Successfully deleted {count} artifacts")
if tag_count > 0:
print(f"Found {tag_count} tags to delete...")
for tag in tags:
db.delete(tag)
db.commit()
print(f"✓ Successfully deleted {tag_count} tags")
else:
print("No tags to delete.")
except Exception as e:
db.rollback()