def test_keys_include_formset_prefix(self): formset = ContactFormSet() empty_data = empty_form_data(formset) for field_name in empty_data: self.assertTrue(formset.prefix in field_name)
def test_returns_empty_form_fields_without_prefix_stub(self): formset = ContactFormSet() empty_data = empty_form_data(formset) for field_name in empty_data: self.assertFalse('__prefix__' in field_name)
def test_returns_all_fields(self): formset = ContactFormSet() empty_data = empty_form_data(formset) for field in formset.empty_form.fields: self.assertTrue([k for k in empty_data if k.endswith(field)])
def test_index_can_be_specified(self): formset = ContactFormSet() empty_data = empty_form_data(formset, index=42) for field_name in empty_data: self.assertTrue("42" in field_name.split("-"), "Field name (%s) does not use specified index." % field_name)
def test_hidden_initial_fields_included(self): formset = ContactFormSet() empty_data = empty_form_data(formset) # we know that the first_name field in our test form wants to # include the initial value in a hidden field self.assertEqual(empty_data["initial-form-1-first_name"], "Larry")
def test_index_can_be_specified(self): formset = ContactFormSet() empty_data = empty_form_data(formset, index=42) for field_name in empty_data: self.assertTrue( '42' in field_name.split('-'), "Field name (%s) does not use specified index." % field_name)
def test_contains_next_form_index(self): formset = ContactFormSet() empty_data = empty_form_data(formset) for field_name in empty_data: self.assertTrue( str(len(formset.initial_forms) + 1) in field_name.split('-'), "Field name (%s) does not include next empty form index." % field_name)
def test_contains_next_form_index(self): formset = ContactFormSet() empty_data = empty_form_data(formset) for field_name in empty_data: self.assertTrue( str(len(formset.initial_forms) + 1) in field_name.split("-"), "Field name (%s) does not include next empty form index." % field_name, )
def test_hidden_initial_fields_included(self): formset = ContactFormSet() empty_data = empty_form_data(formset) # we know that the first_name field in our test form wants to # include the initial value in a hidden field self.assertEqual( empty_data['initial-form-1-first_name'], 'Larry', )
def test_returns_dict(self): formset = ContactFormSet() self.assertIsInstance(empty_form_data(formset), dict)