MCPcopy
hub / github.com/django/django / test_callable_field_default

Method test_callable_field_default

tests/model_forms/tests.py:3131–3177  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3129 )
3130
3131 def test_callable_field_default(self):
3132 class PublicationDefaultsForm(forms.ModelForm):
3133 class Meta:
3134 model = PublicationDefaults
3135 fields = ("title", "date_published", "mode", "category")
3136
3137 self.maxDiff = 2000
3138 form = PublicationDefaultsForm()
3139 today_str = str(datetime.date.today())
3140 self.assertHTMLEqual(
3141 form.as_p(),
3142 """
3143 <p><label for="id_title">Title:</label>
3144 <input id="id_title" maxlength="30" name="title" type="text" required>
3145 </p>
3146 <p><label for="id_date_published">Date published:</label>
3147 <input id="id_date_published" name="date_published" type="text" value="{0}"
3148 required>
3149 <input id="initial-id_date_published" name="initial-date_published"
3150 type="hidden" value="{0}">
3151 </p>
3152 <p><label for="id_mode">Mode:</label> <select id="id_mode" name="mode">
3153 <option value="di" selected>direct</option>
3154 <option value="de">delayed</option></select>
3155 <input id="initial-id_mode" name="initial-mode" type="hidden" value="di">
3156 </p>
3157 <p>
3158 <label for="id_category">Category:</label>
3159 <select id="id_category" name="category">
3160 <option value="1">Games</option>
3161 <option value="2">Comics</option>
3162 <option value="3" selected>Novel</option></select>
3163 <input id="initial-id_category" name="initial-category" type="hidden"
3164 value="3">
3165 """.format(today_str),
3166 )
3167 empty_data = {
3168 "title": "",
3169 "date_published": today_str,
3170 "initial-date_published": today_str,
3171 "mode": "di",
3172 "initial-mode": "di",
3173 "category": "3",
3174 "initial-category": "3",
3175 }
3176 bound_form = PublicationDefaultsForm(empty_data)
3177 self.assertFalse(bound_form.has_changed())
3178
3179
3180class ModelFormCustomErrorTests(SimpleTestCase):

Callers

nothing calls this directly

Calls 5

assertHTMLEqualMethod · 0.80
as_pMethod · 0.80
formatMethod · 0.45
has_changedMethod · 0.45

Tested by

no test coverage detected