Skip to content

Commit

Permalink
fix(celery): make new FlaskCelery class work with import tests (#3237)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacquesfize authored Oct 23, 2024
1 parent da9eea4 commit 46a4735
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
3 changes: 1 addition & 2 deletions backend/geonature/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ def create_app(with_external_mods=True):
if "CELERY" in app.config:
from geonature.utils.celery import celery_app

# celery_app.init_app(app)
celery_app.conf.update(app.config["CELERY"])
celery_app.init_app(app)

# Emails configuration
if app.config["MAIL_CONFIG"]:
Expand Down
2 changes: 2 additions & 0 deletions backend/geonature/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
TaxrefBdcStatutText,
)
from geonature import create_app
from geonature.utils.config import config
from geonature.core.gn_commons.models import BibTablesLocation, TMedias, TModules
from geonature.core.gn_meta.models import (
CorAcquisitionFrameworkActor,
Expand Down Expand Up @@ -96,6 +97,7 @@ def open(self, *args, **kwargs):

@pytest.fixture(scope="session", autouse=True)
def app():
config["CELERY"]["task_always_eager"] = True
app = create_app()
app.testing = True
app.test_client_class = GeoNatureClient
Expand Down
5 changes: 3 additions & 2 deletions backend/geonature/utils/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class FlaskCelery(Celery):
def __init__(self, *args, **kwargs):

super(FlaskCelery, self).__init__(*args, **kwargs)
self.patch_task()

if "app" in kwargs:
self.init_app(kwargs["app"])
Expand All @@ -33,6 +32,8 @@ def __call__(self, *args, **kwargs):
def init_app(self, app):
self.app = app
self.config_from_object(app.config["CELERY"])
if not self.conf.task_always_eager:
self.patch_task()

Check warning on line 36 in backend/geonature/utils/celery.py

View check run for this annotation

Codecov / codecov/patch

backend/geonature/utils/celery.py#L36

Added line #L36 was not covered by tests


celery_app = Celery("geonature") # FIX ME
celery_app = FlaskCelery("geonature")

0 comments on commit 46a4735

Please sign in to comment.