#26843: empty_label argument on ModelChoiceField is not tested
-------------------------------------+-------------------------------------
     Reporter:  smarlowucf           |                    Owner:
         Type:                       |  smarlowucf
  Cleanup/optimization               |                   Status:  assigned
    Component:  Testing framework    |                  Version:  master
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
  ModelChoiceField,Tests,empty_label |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  1                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by smarlowucf):

 Hi,

 In searching the test base I couldn't find anywhere that explicitly tested
 the use of `empty_label`. There are many spots where the default value is
 tested. For example
 
[https://github.com/django/django/blob/master/tests/model_forms/tests.py#L2411].

 Forcing a different value will cause all of those tests to fail. However,
 it seems beneficial to test the explicit use of the argument.

 {{{
 apple = Inventory.objects.create(barcode=86, name='Apple')
 pear = Inventory.objects.create(barcode=22, name='Pear')
 core = Inventory.objects.create(barcode=87, name='Core', parent=apple)

 field = forms.ModelChoiceField(Inventory.objects.all(), empty_label=None)
 self.assertEqual(tuple(field.choices), (
     (apple.id, 'Apple'),
     (core.id, 'Core'),
     (pear.id, 'Pear')))

 field = forms.ModelChoiceField(Inventory.objects.all(),
 empty_label='Select One')
 self.assertEqual(tuple(field.choices), (
     ("", 'Select One'),
     (apple.id, 'Apple'),
     (core.id, 'Core'),
     (pear.id, 'Pear')))
 }}}

 It's possible I'm overlooking existing tests, but the ones I found were
 just implicitly testing the default value, like the example above.

--
Ticket URL: <https://code.djangoproject.com/ticket/26843#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/068.f09033d11aaac7a0094626c0240335d7%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to