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 and Pierre-Narcisi committed Oct 28, 2024
1 parent da9eea4 commit a487cfa
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 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
6 changes: 5 additions & 1 deletion backend/geonature/tests/test_gn_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,11 @@ def test_datasets_permissions(self, app, datasets, users):
qs = select(TDatasets).where(TDatasets.id_dataset.in_(ds_ids))
assert set(sc(dsc.filter_by_scope(0, query=qs)).unique().all()) == set([])
assert set(sc(dsc.filter_by_scope(1, query=qs)).unique().all()) == set(
[datasets["own_dataset"], datasets["own_dataset_not_activated"]]
[
datasets["own_dataset"],
datasets["own_dataset_not_activated"],
datasets["private"],
]
)
assert set(sc(dsc.filter_by_scope(2, query=qs)).unique().all()) == set(
[
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()


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

0 comments on commit a487cfa

Please sign in to comment.