Projet

Général

Profil

0001-multitenant-use-TENANT_DISABLE_CRON_JOBS-to-disable-.patch

Emmanuel Cazenave, 05 octobre 2021 11:57

Télécharger (3,4 ko)

Voir les différences:

Subject: [PATCH] multitenant: use TENANT_DISABLE_CRON_JOBS to disable cron for
 a specific tenant (#57527)

 .../management/commands/tenant_command.py       |  4 ++--
 tests_multitenant/test_tenant_command.py        | 17 ++++++++++++++++-
 2 files changed, 18 insertions(+), 3 deletions(-)
hobo/multitenant/management/commands/tenant_command.py
133 133
            errors = []
134 134
            for tenant in TenantMiddleware.get_tenants():
135 135
                connection.set_tenant(tenant)
136
                if getattr(settings, 'DISABLE_CRON_JOBS', False):
136
                if getattr(settings, 'TENANT_DISABLE_CRON_JOBS', False):
137 137
                    if args_verbosity.verbosity > 1 or args_namespace.force_job:
138
                        msg = 'Command %s is ignored on tenant %s because DISABLE_CRON_JOBS is set' % (
138
                        msg = 'Command %s is ignored on tenant %s because TENANT_DISABLE_CRON_JOBS is set' % (
139 139
                            app_name,
140 140
                            tenant.domain_url,
141 141
                        )
tests_multitenant/test_tenant_command.py
50 50
def test_all_tenants_disable_cron(handle, tenants, settings):
51 51
    from django.core.management import execute_from_command_line
52 52

  
53
    settings.clear_tenants_settings()
53 54
    settings.DISABLE_CRON_JOBS = True
54 55
    handle.side_effect = RecordTenant()
55 56
    execute_from_command_line(['manage.py', 'tenant_command', 'clearsessions', '--all-tenants'])
......
65 66
    disabled_tenant = tenants[0]
66 67
    with open(os.path.join(disabled_tenant.get_directory(), 'settings.json'), 'w') as fd:
67 68
        json.dump(
68
            {'DISABLE_CRON_JOBS': True},
69
            {'TENANT_DISABLE_CRON_JOBS': True},
69 70
            fd,
70 71
        )
71 72
    handle.side_effect = RecordTenant()
......
74 75
    assert len(handle.side_effect.tenants) == 1
75 76

  
76 77

  
78
@mock.patch('django.contrib.sessions.management.commands.clearsessions.Command.handle')
79
def test_all_tenants_global_disable_cron_with_force_job(handle, tenants, settings):
80
    from django.core.management import execute_from_command_line
81

  
82
    settings.clear_tenants_settings()
83
    settings.DISABLE_CRON_JOBS = True
84
    handle.side_effect = RecordTenant()
85
    execute_from_command_line(
86
        ['manage.py', 'tenant_command', 'clearsessions', '--all-tenants', '--force-job']
87
    )
88
    assert handle.call_count == 2
89
    assert len(handle.side_effect.tenants) == 2
90

  
91

  
77 92
@mock.patch('django.contrib.sessions.management.commands.clearsessions.Command.handle')
78 93
def test_one_tenant(handle, tenants, tenant_in_call=None):
79 94
    from django.core.management import execute_from_command_line
80
-