mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-05 10:29:28 +02:00
Added GenericRelationFilter
This commit is contained in:
parent
ab3bc96783
commit
b363d1117c
2 changed files with 94 additions and 0 deletions
|
@ -67,3 +67,39 @@ def test_generic_relation_field_validation_error(payload, expected_error, factor
|
|||
|
||||
with pytest.raises(fields.serializers.ValidationError, match=expected_error):
|
||||
f.to_internal_value(payload)
|
||||
|
||||
|
||||
def test_generic_relation_filter_target_type(factories):
|
||||
user = factories["users.User"]()
|
||||
note = factories["moderation.Note"](target=user)
|
||||
factories["moderation.Note"](target=factories["music.Artist"]())
|
||||
f = fields.GenericRelationFilter(
|
||||
"target",
|
||||
{
|
||||
"user": {
|
||||
"queryset": user.__class__.objects.all(),
|
||||
"id_attr": "username",
|
||||
"id_field": fields.serializers.CharField(),
|
||||
}
|
||||
},
|
||||
)
|
||||
qs = f.filter(note.__class__.objects.all(), "user")
|
||||
assert list(qs) == [note]
|
||||
|
||||
|
||||
def test_generic_relation_filter_target_type_and_id(factories):
|
||||
user = factories["users.User"]()
|
||||
note = factories["moderation.Note"](target=user)
|
||||
factories["moderation.Note"](target=factories["users.User"]())
|
||||
f = fields.GenericRelationFilter(
|
||||
"target",
|
||||
{
|
||||
"user": {
|
||||
"queryset": user.__class__.objects.all(),
|
||||
"id_attr": "username",
|
||||
"id_field": fields.serializers.CharField(),
|
||||
}
|
||||
},
|
||||
)
|
||||
qs = f.filter(note.__class__.objects.all(), "user:{}".format(user.username))
|
||||
assert list(qs) == [note]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue