Coverage for backend/django/Economics/management/commands/import_stats_nz_indexes.py: 86%

14 statements  

« prev     ^ index     » next       coverage.py v7.10.7, created at 2026-06-23 21:51 +0000

1from pathlib import Path 

2 

3from django.core.management.base import BaseCommand, CommandError 

4 

5from Economics.reference_data.services.stats_nz_indexes import StatsNzIndexImportError, import_locked_stats_nz_indexes 

6 

7 

8class Command(BaseCommand): 

9 help = "Populate or refresh global locked Stats NZ CPI, CGPI, and PMEI Economics index data." 

10 

11 def add_arguments(self, parser): 

12 parser.add_argument( 

13 "--cpi-path", 

14 type=Path, 

15 default=None, 

16 help="Path to the locked CPI index-numbers CSV fixture.", 

17 ) 

18 parser.add_argument( 

19 "--bpi-path", 

20 type=Path, 

21 default=None, 

22 help="Path to the locked BPI CSV or ZIP fixture containing CGPI and PMEI rows.", 

23 ) 

24 

25 def handle(self, *args, **options): 

26 try: 

27 result = import_locked_stats_nz_indexes( 

28 cpi_path=options["cpi_path"], 

29 bpi_path=options["bpi_path"], 

30 ) 

31 except StatsNzIndexImportError as exc: 

32 raise CommandError(f"{exc.code}: {exc.message} {exc.context}") from exc 

33 

34 self.stdout.write( 

35 self.style.SUCCESS( 

36 "Imported Stats NZ indexes: " 

37 f"{result.series_imported} series, " 

38 f"{result.values_created} values created, " 

39 f"{result.values_updated} values updated, " 

40 f"{result.rows_imported}/{result.rows_seen} rows imported." 

41 ) 

42 )