def test_form_field_classes(self): form = tm_forms.TaskForm() self.assertTrue( isinstance(form.fields['creator'], tm_fields.UserModelChoiceField)) self.assertTrue(form.fields['creator'].disabled) self.assertEquals( form.fields['creator'].label_from_instance(self.ivanov), self.ivanov.get_full_name()) self.assertTrue( isinstance(form.fields['assigned_to'], tm_fields.UserModelChoiceField)) self.assertEquals( form.fields['assigned_to'].label_from_instance(self.ivanov), self.ivanov.get_full_name()) self.assertTrue(form.fields['tags'], tm_fields.TagsField)
def test_field_tags_instance_as_initial(self): form = tm_forms.TaskForm(instance=self.task) self.assertEquals(form.initial['tags'], 'task|test')
def test_field_tags_validators_validate_tags(self): form = tm_forms.TaskForm() self.assertEquals(form.fields['tags'].validators[2], tm_fields.validate_tags)
def test_field_tags_validators_regex(self): form = tm_forms.TaskForm() regex_validator = form.fields['tags'].validators[1] self.assertTrue(isinstance(regex_validator, validators.RegexValidator)) self.assertTrue(regex_validator.inverse_match, )
def test_field_tags_required(self): form = tm_forms.TaskForm() self.assertFalse(form.fields['tags'].required)
def test_field_tags_help_text(self): form = tm_forms.TaskForm() self.assertEquals(form.fields['tags'].help_text, 'Separate each tag by "|"')
def test_field_tags_type(self): form = tm_forms.TaskForm() self.assertTrue(form.fields['tags'], forms.CharField)
def test_field_assigned_to_queryset(self): form = tm_forms.TaskForm() self.assertEquals(len(form.fields['assigned_to'].queryset), 2) self.assertEquals(set(form.fields['assigned_to'].queryset), {self.ivanov, self.petrov})
def test_field_creator_queryset(self): form = tm_forms.TaskForm() self.assertEquals(len(form.fields['creator'].queryset), 2) self.assertEquals(set(form.fields['creator'].queryset), {self.ivanov, self.petrov})
def test_form_model(self): form = tm_forms.TaskForm() self.assertEquals(form.Meta().model, tm_models.Task)
def test_form_fields(self): form = tm_forms.TaskForm() self.assertEquals(form.Meta().fields, ('name', 'description', 'status', 'creator', 'assigned_to', 'tags'))