From 79297d46b8a4eb9849b60e2a61a71a5a30616e78 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Wed, 7 Jun 2023 16:05:52 +0200 Subject: [PATCH] ants_hub: fix use of uwsgidecorators.spool (#78242) --- chrono/apps/ants_hub/views.py | 12 ++++++++++-- tests/ants_hub/test_manager.py | 9 ++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/chrono/apps/ants_hub/views.py b/chrono/apps/ants_hub/views.py index 4304a822..dbdd072c 100644 --- a/chrono/apps/ants_hub/views.py +++ b/chrono/apps/ants_hub/views.py @@ -14,6 +14,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import sys + from django import forms from django.contrib import messages from django.core.cache import cache @@ -236,6 +238,12 @@ class Synchronize(TemplateView): @classmethod def synchronize(cls): - from chrono.utils.spooler import ants_hub_city_push + if 'uwsgi' in sys.modules: + from django.db import connection - ants_hub_city_push.spool() + from chrono.utils.spooler import ants_hub_city_push + + tenant = getattr(connection, 'tenant', None) + ants_hub_city_push.spool(domain=getattr(tenant, 'domain_url', None)) + else: + models.City.push() diff --git a/tests/ants_hub/test_manager.py b/tests/ants_hub/test_manager.py index 219f0394..98ab3716 100644 --- a/tests/ants_hub/test_manager.py +++ b/tests/ants_hub/test_manager.py @@ -182,11 +182,14 @@ def test_delete_agenda(hub, app, admin_user, city, place, agenda, place_agenda): def test_synchronize(hub, app, admin_user, city, place, agenda, place_agenda, freezer): + hub.add( + responses.POST, + 'https://toto:@ants-hub.example.com/api/chrono/rendez-vous-disponibles/', + json={'err': 0}, + ) freezer.move_to('2023-06-01T17:12:00+02:00') login(app) resp = app.get('/manage/', status=200) resp = resp.click('ANTS') resp = resp.click('Synchronize') - with mock.patch('chrono.apps.ants_hub.views.Synchronize.synchronize') as method: - resp = resp.form.submit().follow() - assert method.called + resp = resp.form.submit().follow() -- 2.39.2