fix: Enhance argument handling in seed data script and add unit tests
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user