def test_invalid_data(self): """ Setting custom field data for a non-applicable (or non-existent) CustomField should raise a ValidationError. """ site = Site(name='Test Site', slug='test-site') # Set custom field data site.cf['foo'] = 'abc' site.cf['bar'] = 'def' with self.assertRaises(ValidationError): site.clean() del(site.cf['bar']) site.clean()
def test_missing_required_field(self): """ Check that a ValidationError is raised if any required custom fields are not present. """ cf3 = CustomField(type=CustomFieldTypeChoices.TYPE_TEXT, name='baz', required=True) cf3.save() cf3.content_types.set([ContentType.objects.get_for_model(Site)]) site = Site(name='Test Site', slug='test-site') # Set custom field data with a required field omitted site.cf['foo'] = 'abc' with self.assertRaises(ValidationError): site.clean() site.cf['baz'] = 'def' site.clean()