fix: Enhance argument handling in seed data script and add unit tests
Some checks failed
Run Tests / e2e tests (push) Failing after 2s
Run Tests / lint tests (push) Failing after 2s
Run Tests / unit tests (push) Failing after 2s

This commit is contained in:
2025-10-27 15:12:50 +01:00
parent 8bb5456864
commit 573e255769
2 changed files with 67 additions and 9 deletions

View File

@@ -135,24 +135,36 @@ def run_with_namespace(
*,
config: Optional[DatabaseConfig] = None,
) -> None:
if not hasattr(args, "verbose"):
args.verbose = 0
if not hasattr(args, "dry_run"):
args.dry_run = False
_configure_logging(args)
if not any((args.currencies, args.units, args.theme, args.defaults)):
currencies = bool(getattr(args, "currencies", False))
units = bool(getattr(args, "units", False))
theme = bool(getattr(args, "theme", False))
defaults = bool(getattr(args, "defaults", False))
dry_run = bool(getattr(args, "dry_run", False))
if not any((currencies, units, theme, defaults)):
logger.info("No seeding options provided; exiting")
return
config = config or DatabaseConfig.from_env()
with psycopg2.connect(config.application_dsn()) as conn:
conn.autocommit = True
with conn.cursor() as cursor:
if args.currencies:
_seed_currencies(cursor, dry_run=args.dry_run)
if args.units:
_seed_units(cursor, dry_run=args.dry_run)
if args.theme:
_seed_theme(cursor, dry_run=args.dry_run)
if args.defaults:
_seed_defaults(cursor, dry_run=args.dry_run)
if currencies:
_seed_currencies(cursor, dry_run=dry_run)
if units:
_seed_units(cursor, dry_run=dry_run)
if theme:
_seed_theme(cursor, dry_run=dry_run)
if defaults:
_seed_defaults(cursor, dry_run=dry_run)
def _seed_currencies(cursor, *, dry_run: bool) -> None: