def test_domain_resolver_translation(self): with override_settings(USE_SUBDOMAIN=False): url = resolve_domain(project=self.translation) self.assertEqual(url, 'readthedocs.org') with override_settings(USE_SUBDOMAIN=True): url = resolve_domain(project=self.translation) self.assertEqual(url, 'pip.readthedocs.org')
def test_domain_resolver_with_domain_object(self): self.domain = get(Domain, domain='docs.foobar.com', project=self.pip, canonical=True) with override_settings(USE_SUBDOMAIN=False): url = resolve_domain(project=self.pip) self.assertEqual(url, 'docs.foobar.com') with override_settings(USE_SUBDOMAIN=True): url = resolve_domain(project=self.pip) self.assertEqual(url, 'docs.foobar.com')
def test_domain_public(self): with override_settings(USE_SUBDOMAIN=False): url = resolve_domain(project=self.translation) self.assertEqual(url, 'readthedocs.org') with override_settings(USE_SUBDOMAIN=True): url = resolve_domain(project=self.translation) self.assertEqual(url, 'pip.public.readthedocs.org') # Private overrides domain with override_settings(USE_SUBDOMAIN=False): url = resolve_domain(project=self.translation, private=True) self.assertEqual(url, 'readthedocs.org') with override_settings(USE_SUBDOMAIN=True): url = resolve_domain(project=self.translation, private=True) self.assertEqual(url, 'pip.public.readthedocs.org')
def test_domain_resolver_translation_itself(self): """ Test inconsistent project/translation relationship. If a project is a translation of itself (inconsistent relationship) we still resolves the proper domain. """ # remove all possible translations relationships self.pip.translations.all().delete() # add the project as subproject of itself self.pip.translations.add(self.pip) with override_settings(USE_SUBDOMAIN=False): url = resolve_domain(project=self.pip) self.assertEqual(url, 'readthedocs.org') with override_settings(USE_SUBDOMAIN=True): url = resolve_domain(project=self.pip) self.assertEqual(url, 'pip.readthedocs.org')
def subdomain(self): """Get project subdomain from resolver.""" return resolve_domain(self)