Fix Demo enterprise
This commit is contained in:
@@ -4,76 +4,42 @@ Provides functions to locate seed data files for demo data creation
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
import os
|
||||
|
||||
|
||||
def get_seed_data_path(profile: str, filename: str, child_profile: str = None) -> Path:
|
||||
def get_seed_data_path(profile: str, filename: str, child_profile: str = None, child_id: str = None) -> Path:
|
||||
"""
|
||||
Get the path to a seed data file, searching in multiple locations.
|
||||
|
||||
Get the path to a seed data file.
|
||||
|
||||
Args:
|
||||
profile: Demo profile (professional/enterprise)
|
||||
filename: Seed data filename
|
||||
child_profile: Optional child profile for enterprise demos
|
||||
|
||||
child_profile: Not used (kept for API compatibility)
|
||||
child_id: Optional child tenant ID for enterprise child locations
|
||||
|
||||
Returns:
|
||||
Path to the seed data file
|
||||
|
||||
|
||||
Raises:
|
||||
FileNotFoundError: If seed data file cannot be found in any location
|
||||
FileNotFoundError: If seed data file cannot be found
|
||||
"""
|
||||
# Search locations in order of priority
|
||||
search_locations = []
|
||||
|
||||
# 1. First check in shared/demo/fixtures (new location)
|
||||
if child_profile:
|
||||
# Enterprise child profile
|
||||
search_locations.append(
|
||||
Path(__file__).parent.parent / "demo" / "fixtures" / profile / child_profile / filename
|
||||
)
|
||||
else:
|
||||
# Regular profile
|
||||
search_locations.append(
|
||||
Path(__file__).parent.parent / "demo" / "fixtures" / profile / filename
|
||||
)
|
||||
|
||||
# 2. Check in infrastructure/seed-data (old location)
|
||||
if child_profile:
|
||||
search_locations.append(
|
||||
Path(__file__).parent.parent.parent / "infrastructure" / "seed-data" / profile / "children" / f"{child_profile}.json"
|
||||
)
|
||||
else:
|
||||
search_locations.append(
|
||||
Path(__file__).parent.parent.parent / "infrastructure" / "seed-data" / profile / filename
|
||||
)
|
||||
|
||||
# 3. Check in infrastructure/seed-data with alternative paths
|
||||
if profile == "enterprise" and not child_profile:
|
||||
search_locations.append(
|
||||
Path(__file__).parent.parent.parent / "infrastructure" / "seed-data" / profile / "parent" / filename
|
||||
)
|
||||
# Also check the shared/demo/fixtures/enterprise/parent directory
|
||||
search_locations.append(
|
||||
Path(__file__).parent.parent / "demo" / "fixtures" / profile / "parent" / filename
|
||||
)
|
||||
|
||||
# Find the first existing file
|
||||
for file_path in search_locations:
|
||||
if file_path.exists():
|
||||
return file_path
|
||||
|
||||
# If no file found, raise an error with all searched locations
|
||||
searched_paths = "\n".join([str(p) for p in search_locations])
|
||||
raise FileNotFoundError(
|
||||
f"Seed data file not found: {filename}\n"
|
||||
f"Profile: {profile}\n"
|
||||
f"Child profile: {child_profile}\n"
|
||||
f"Searched locations:\n{searched_paths}"
|
||||
)
|
||||
base_path = Path(__file__).parent.parent / "demo" / "fixtures"
|
||||
|
||||
if child_id:
|
||||
# Enterprise child location: enterprise/children/{child_id}/{filename}
|
||||
file_path = base_path / profile / "children" / child_id / filename
|
||||
elif profile == "enterprise":
|
||||
# Enterprise parent: enterprise/parent/{filename}
|
||||
file_path = base_path / profile / "parent" / filename
|
||||
else:
|
||||
# Professional: professional/{filename}
|
||||
file_path = base_path / profile / filename
|
||||
|
||||
def get_demo_fixture_path(profile: str, filename: str, child_profile: str = None) -> Path:
|
||||
"""
|
||||
Alternative function name for backward compatibility
|
||||
"""
|
||||
return get_seed_data_path(profile, filename, child_profile)
|
||||
if not file_path.exists():
|
||||
raise FileNotFoundError(
|
||||
f"Seed data file not found: {file_path}\n"
|
||||
f"Profile: {profile}\n"
|
||||
f"Child ID: {child_id}\n"
|
||||
f"Filename: {filename}"
|
||||
)
|
||||
|
||||
return file_path
|
||||
|
||||
Reference in New Issue
Block a user