Coverage for benefits / enrollment_littlepay / migrations / 0004_littlepayconfig.py: 63%

15 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-02-13 19:35 +0000

1# Generated by Django 5.1.7 on 2025-07-14 09:21 

2 

3import django.db.models.deletion 

4from django.db import migrations, models 

5 

6import benefits.core.models.common 

7import benefits.secrets 

8 

9 

10def migrate_littlepay_config(apps, schema_editor): 

11 OldLittlepayConfig = apps.get_model("enrollment_littlepay", "OldLittlepayConfig") 

12 LittlepayConfig = apps.get_model("enrollment_littlepay", "NewLittlepayConfig") 

13 

14 for old_config in OldLittlepayConfig.objects.all(): 14 ↛ 15line 14 didn't jump to line 15 because the loop on line 14 never started

15 new_config = LittlepayConfig.objects.create( 

16 environment=old_config.environment, 

17 agency_slug=old_config.agency_slug, 

18 audience=old_config.audience, 

19 client_id=old_config.client_id, 

20 client_secret_name=old_config.client_secret_name, 

21 ) 

22 

23 if hasattr(old_config, "transitagency"): 

24 new_config.transit_agency = old_config.transitagency 

25 

26 new_config.save() 

27 

28 

29class Migration(migrations.Migration): 

30 

31 dependencies = [ 

32 ("core", "0054_transitprocessorconfig"), 

33 ("enrollment_littlepay", "0003_rename_littlepayconfig_oldlittlepayconfig"), 

34 ] 

35 

36 operations = [ 

37 migrations.CreateModel( 

38 name="NewLittlepayConfig", 

39 fields=[ 

40 ( 

41 "transitprocessorconfig_ptr", 

42 models.OneToOneField( 

43 auto_created=True, 

44 on_delete=django.db.models.deletion.CASCADE, 

45 parent_link=True, 

46 primary_key=True, 

47 serialize=False, 

48 to="core.transitprocessorconfig", 

49 ), 

50 ), 

51 ( 

52 "audience", 

53 models.TextField( 

54 blank=True, 

55 default="", 

56 help_text="This agency's audience value used to access the TransitProcessor's API.", 

57 ), 

58 ), 

59 ( 

60 "client_id", 

61 models.TextField( 

62 blank=True, 

63 default="", 

64 help_text="This agency's client_id value used to access the TransitProcessor's API.", 

65 ), 

66 ), 

67 ( 

68 "client_secret_name", 

69 benefits.core.models.common.SecretNameField( 

70 blank=True, 

71 default="", 

72 help_text="The name of the secret containing this agency's client_secret value used to access the TransitProcessor's API.", # noqa 

73 max_length=127, 

74 validators=[benefits.secrets.SecretNameValidator()], 

75 ), 

76 ), 

77 ], 

78 bases=("core.transitprocessorconfig",), 

79 ), 

80 migrations.RunPython(migrate_littlepay_config), 

81 ]