diff --git a/udata/core/badges/factories.py b/udata/core/badges/factories.py index c3904e08a..b632730fc 100644 --- a/udata/core/badges/factories.py +++ b/udata/core/badges/factories.py @@ -8,8 +8,8 @@ def badge_factory(model_): class BadgeFactory(ModelFactory): class Meta: - model = get_badge(model_.__badges__.keys()) + model = get_badge(model_.__badges__) - kind = FuzzyChoice(model_.__badges__.keys()) + kind = FuzzyChoice(model_.__badges__) return BadgeFactory diff --git a/udata/core/badges/models.py b/udata/core/badges/models.py index b7b353e96..b29f3ccb9 100644 --- a/udata/core/badges/models.py +++ b/udata/core/badges/models.py @@ -3,7 +3,7 @@ from mongoengine.signals import post_save -from udata.api_fields import field +from udata.api_fields import field, generate_fields from udata.auth import current_user from udata.core.badges.fields import badge_fields from udata.mongo import db @@ -17,8 +17,9 @@ def get_badge(choices=None): + @generate_fields(default_filterable_field="kind") class Badge(db.EmbeddedDocument): - kind = db.StringField(required=True, choices=choices) + kind = db.StringField(required=True, choices=list(choices.keys()) if choices else None) created = db.DateTimeField(default=datetime.utcnow, required=True) created_by = db.ReferenceField("User") diff --git a/udata/tests/api/test_reuses_api.py b/udata/tests/api/test_reuses_api.py index 2782a9f1e..12e92b554 100644 --- a/udata/tests/api/test_reuses_api.py +++ b/udata/tests/api/test_reuses_api.py @@ -132,12 +132,12 @@ def test_reuse_api_list_with_filters(self, api): assert400(response) # filter on organization badge - response = api.get(url_for("api.reuses", organization_badge=org_constants.PUBLIC_SERVICE)) + response = api.get(url_for("api.reuses", organization_badges=org_constants.PUBLIC_SERVICE)) assert200(response) assert len(response.json["data"]) == 1 assert response.json["data"][0]["id"] == str(org_reuse_public_service.id) - response = api.get(url_for("api.reuses", organization_badge="bad-badge")) + response = api.get(url_for("api.reuses", organization_badges="bad-badge")) assert400(response) def test_reuse_api_list_filter_private(self, api) -> None: