def test_oops_there_is_more_than_one(self): Site.objects.create(hostname='example.com', is_default_site=True, root_page=Page.objects.get(pk=2)) site = Site(hostname='test.com', is_default_site=True, root_page=Page.objects.get(pk=2)) with self.assertRaises(Site.MultipleObjectsReturned): # If there already are multiple default sites, you're in trouble site.clean_fields()
def test_there_can_only_be_one(self): site = Site(hostname='test.com', is_default_site=True, root_page=Page.objects.get(pk=2)) with self.assertRaises(ValidationError): site.clean_fields()