diff --git a/readthedocs/embed/tests/test_api.py b/readthedocs/embed/tests/test_api.py index b2cad77d128..1f771ee1b8b 100644 --- a/readthedocs/embed/tests/test_api.py +++ b/readthedocs/embed/tests/test_api.py @@ -18,7 +18,7 @@ @pytest.mark.django_db -class TestEmbedAPI: +class BaseTestEmbedAPI: @pytest.fixture(autouse=True) def setup_method(self, settings): @@ -36,6 +36,10 @@ def setup_method(self, settings): settings.USE_SUBDOMAIN = True settings.PUBLIC_DOMAIN = 'readthedocs.io' + def get(self, client, *args, **kwargs): + """Wrapper around ``client.get`` to be overridden in the proxied api tests.""" + return client.get(*args, **kwargs) + def _mock_open(self, content): @contextmanager def f(*args, **kwargs): @@ -70,9 +74,9 @@ def test_invalid_arguments(self, client): }, ) - api_endpoint = reverse('api_embed') + api_endpoint = reverse('embed_api') for param in query_params: - r = client.get(api_endpoint, param) + r = self.get(client, api_endpoint, param) assert r.status_code == status.HTTP_400_BAD_REQUEST @mock.patch('readthedocs.embed.views.build_media_storage') @@ -121,9 +125,9 @@ def test_valid_arguments(self, storage_mock, client): 'section': 'title-one', }, ) - api_endpoint = reverse('api_embed') + api_endpoint = reverse('embed_api') for param in query_params: - r = client.get(api_endpoint, param) + r = self.get(client, api_endpoint, param) assert r.status_code == status.HTTP_200_OK @mock.patch('readthedocs.embed.views.build_media_storage') @@ -137,8 +141,9 @@ def test_embed_unknown_section(self, storage_mock, client): html_file=html_file, ) - response = client.get( - reverse('api_embed'), + response = self.get( + client, + reverse('embed_api'), { 'project': self.project.slug, 'version': self.version.slug, @@ -184,8 +189,9 @@ def test_embed_sphinx(self, storage_mock, section, client): html_file=html_file, ) - response = client.get( - reverse('api_embed'), + response = self.get( + client, + reverse('embed_api'), { 'project': self.project.slug, 'version': self.version.slug, @@ -233,8 +239,9 @@ def test_embed_mkdocs(self, storage_mock, client): self.version.documentation_type = MKDOCS self.version.save() - response = client.get( - reverse('api_embed'), + response = self.get( + client, + reverse('embed_api'), { 'project': self.project.slug, 'version': self.version.slug, @@ -268,3 +275,18 @@ def test_embed_mkdocs(self, storage_mock, client): assert response.status_code == status.HTTP_200_OK assert response.data == expected + + +class TestEmbedAPI(BaseTestEmbedAPI): + + pass + + +@pytest.mark.proxito +class TestProxiedEmbedAPI(BaseTestEmbedAPI): + + host = 'project.readthedocs.io' + + def get(self, client, *args, **kwargs): + r = client.get(*args, HTTP_HOST=self.host, **kwargs) + return r diff --git a/readthedocs/embed/urls.py b/readthedocs/embed/urls.py index 8431d5cc432..ff2041c3159 100644 --- a/readthedocs/embed/urls.py +++ b/readthedocs/embed/urls.py @@ -4,5 +4,5 @@ urlpatterns = [ - url(r'', EmbedAPI.as_view(), name='api_embed'), + url(r'', EmbedAPI.as_view(), name='embed_api'), ]