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())
def test_invalid_domains(self): invalid = [ 'python..org', # FIXME: '****.foo.com', current validator says this is valid :shrug: 'invalid-.com' ] for domain in invalid: form = DomainForm( {'domain': domain}, project=self.project, ) self.assertFalse(form.is_valid(), domain)
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_valid_domains(self): domains = [ 'python.org', 'a.io', 'a.e.i.o.org', 'my.domain.com.edu', 'my-domain.fav', ] for domain in domains: form = DomainForm( {'domain': domain}, project=self.project, ) self.assertTrue(form.is_valid(), domain)
def test_invalid_domains(self): domains = [ 'python..org', '****.foo.com', 'domain', 'domain.com.', 'My domain.org', 'i.o', '[special].com', 'some_thing.org', 'invalid-.com', ] for domain in domains: form = DomainForm( {'domain': domain}, project=self.project, ) self.assertFalse(form.is_valid(), domain)
def test_public_domain_not_allowed(self): """Make sure user can not enter public domain name.""" form = DomainForm( {'domain': settings.PUBLIC_DOMAIN}, project=self.project, ) self.assertFalse(form.is_valid()) self.assertEqual(form.errors['domain'][0], f'{settings.PUBLIC_DOMAIN} is not a valid domain.') form2 = DomainForm( {'domain': 'docs.' + settings.PUBLIC_DOMAIN}, project=self.project, ) self.assertFalse(form2.is_valid()) self.assertEqual(form2.errors['domain'][0], f'{settings.PUBLIC_DOMAIN} is not a valid domain.')
def test_production_domain_not_allowed(self): """Make sure user can not enter production domain name.""" form = DomainForm( {'domain': settings.PRODUCTION_DOMAIN}, project=self.project, ) self.assertFalse(form.is_valid()) self.assertEqual( form.errors['domain'][0], f'{settings.PRODUCTION_DOMAIN} is not a valid domain.') form2 = DomainForm( {'domain': 'test.' + settings.PRODUCTION_DOMAIN}, project=self.project, ) self.assertFalse(form2.is_valid()) self.assertEqual( form2.errors['domain'][0], f'{settings.PRODUCTION_DOMAIN} is not a valid domain.')
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')