def test_canonical_change(self): """Make sure canonical can be properly changed.""" form = DomainForm( { 'domain': 'example.com', 'canonical': True }, project=self.project, ) self.assertTrue(form.is_valid()) domain = form.save() self.assertEqual(domain.domain, 'example.com') form = DomainForm( { 'domain': 'example2.com', 'canonical': True }, project=self.project, ) self.assertFalse(form.is_valid()) self.assertEqual(form.errors['canonical'][0], 'Only 1 Domain can be canonical at a time.') form = DomainForm( { 'domain': 'example2.com', 'canonical': True }, project=self.project, instance=domain, ) self.assertTrue(form.is_valid()) domain = form.save() self.assertEqual(domain.domain, 'example2.com')
def test_canonical_change(self): """Make sure canonical can be properly changed.""" form = DomainForm( {'domain': 'example.com', 'canonical': True}, project=self.project, ) self.assertTrue(form.is_valid()) domain = form.save() self.assertEqual(domain.domain, 'example.com') form = DomainForm( {'domain': 'example2.com', 'canonical': True}, project=self.project, ) self.assertFalse(form.is_valid()) self.assertEqual(form.errors['canonical'][0], 'Only 1 Domain can be canonical at a time.') form = DomainForm( {'domain': 'example2.com', 'canonical': True}, project=self.project, instance=domain, ) self.assertTrue(form.is_valid()) domain = form.save() self.assertEqual(domain.domain, 'example2.com')
def test_domain_with_path(self): form = DomainForm( {'domain': 'domain.com/foo/bar'}, project=self.project, ) self.assertTrue(form.is_valid()) domain = form.save() self.assertEqual(domain.domain, 'domain.com')
def test_https(self): """Make sure https is an admin-only attribute""" form = DomainForm({'domain': 'example.com', 'canonical': True}, project=self.project) self.assertTrue(form.is_valid()) domain = form.save() self.assertFalse(domain.https) form = DomainForm({'domain': 'example.com', 'canonical': True, 'https': True}, project=self.project) self.assertFalse(form.is_valid())