From 8b5b2886b2646b917fd92bdfe78630175342291b Mon Sep 17 00:00:00 2001 From: Mariana Date: Tue, 12 Nov 2024 15:40:05 +0000 Subject: [PATCH] Updated test_autocomplete_widget.py --- .../admin_widgets/test_autocomplete_widget.py | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/tests/admin_widgets/test_autocomplete_widget.py b/tests/admin_widgets/test_autocomplete_widget.py index fb17f71d8c..265a45d95c 100644 --- a/tests/admin_widgets/test_autocomplete_widget.py +++ b/tests/admin_widgets/test_autocomplete_widget.py @@ -17,7 +17,6 @@ class AlbumForm(forms.ModelForm): Album._meta.get_field("band"), admin.site, attrs={"class": "my-class"}, - option_attrs={"data-test": "custom", "class": "other"}, ), "featuring": AutocompleteSelect( Album._meta.get_field("featuring"), @@ -26,6 +25,20 @@ class AlbumForm(forms.ModelForm): } +class ReleaseEventForm(forms.ModelForm): + class Meta: + model = ReleaseEvent + fields = ["album"] + widgets = { + "album": AutocompleteSelect( + ReleaseEvent._meta.get_field("album"), + admin.site, + attrs={"class": "my-class"}, + option_attrs={"data-test": "custom", "class": "other"}, + ), + } + + class NotRequiredBandForm(forms.Form): band = ModelChoiceField( queryset=Album.objects.all(), @@ -200,15 +213,16 @@ class AutocompleteMixinTests(TestCase): def test_option_attrs(self): beatles = Band.objects.create(name="The Beatles", style="rock") - form = AlbumForm(initial={"band": beatles.uuid}) - widget = form["band"].field.widget.render(name="my_field", value=beatles.uuid) + rubber_soul = Album.objects.create(name="Rubber Soul", band=beatles) + form = ReleaseEventForm(initial={"album": rubber_soul.pk}) + widget = form["album"].field.widget.render(name="my_field", value=rubber_soul.pk) self.assertInHTML( - f'', + 'data-placeholder="" lang="en" selected>Rubber Soul', widget, )