MCPcopy
hub / github.com/django/django / test_default_foreign_key_widget

Method test_default_foreign_key_widget

tests/modeladmin/tests.py:707–738  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

705 # radio_fields behavior ###########################################
706
707 def test_default_foreign_key_widget(self):
708 # First, without any radio_fields specified, the widgets for ForeignKey
709 # and fields with choices specified ought to be a basic Select widget.
710 # ForeignKey widgets in the admin are wrapped with
711 # RelatedFieldWidgetWrapper so they need to be handled properly when
712 # type checking. For Select fields, all of the choices lists have a
713 # first entry of a translatable blank choice label.
714 blank_option = ("", get_blank_choice_label())
715 cma = ModelAdmin(Concert, self.site)
716 cmafa = cma.get_form(request)
717
718 self.assertEqual(type(cmafa.base_fields["main_band"].widget.widget), Select)
719 self.assertEqual(
720 list(cmafa.base_fields["main_band"].widget.choices),
721 [blank_option, (self.band.id, "The Doors")],
722 )
723
724 self.assertEqual(type(cmafa.base_fields["opening_band"].widget.widget), Select)
725 self.assertEqual(
726 list(cmafa.base_fields["opening_band"].widget.choices),
727 [blank_option, (self.band.id, "The Doors")],
728 )
729 self.assertEqual(type(cmafa.base_fields["day"].widget), Select)
730 self.assertEqual(
731 list(cmafa.base_fields["day"].widget.choices),
732 [blank_option, (1, "Fri"), (2, "Sat")],
733 )
734 self.assertEqual(type(cmafa.base_fields["transport"].widget), Select)
735 self.assertEqual(
736 list(cmafa.base_fields["transport"].widget.choices),
737 [blank_option, (1, "Plane"), (2, "Train"), (3, "Bus")],
738 )
739
740 def test_foreign_key_as_radio_field(self):
741 # Now specify all the fields as radio_fields. Widgets should now be

Callers

nothing calls this directly

Calls 3

get_formMethod · 0.95
get_blank_choice_labelFunction · 0.90
ModelAdminClass · 0.90

Tested by

no test coverage detected