Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
magopian committed Oct 9, 2024
1 parent b4c2e2d commit c87b5e2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions udata/core/badges/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions udata/core/badges/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")

Expand Down
4 changes: 2 additions & 2 deletions udata/tests/api/test_reuses_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit c87b5e2

Please sign in to comment.