Skip to content

Commit 039859a

Browse files
committed
Update tests
1 parent ab997bd commit 039859a

File tree

3 files changed

+46
-63
lines changed

3 files changed

+46
-63
lines changed

pytest.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[pytest]
22
addopts = --reuse-db --strict-markers
33
markers =
4+
sphinx
45
search
5-
serve
66
proxito
77
python_files = tests.py test_*.py *_tests.py
88
filterwarnings =

readthedocs/api/v2/proxied_urls.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
api_footer_urls = [
1616
url(r'footer_html/', ProxiedFooterHTML.as_view(), name='footer_html'),
1717
url(r'search/$', ProxiedPageSearchAPIView.as_view(), name='search_api'),
18-
url(r'embed/', ProxiedEmbedAPI.as_view(), name='embed_api'),
18+
url(r'embed/', ProxiedEmbedAPI.as_view(), name='api_embed'),
1919
url(r'analytics/$', AnalyticsView.as_view(), name='analytics_api'),
2020
]
2121

readthedocs/embed/tests/test_api.py

+44-61
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
data_path = Path(__file__).parent.resolve() / 'data'
1818

1919

20+
@pytest.mark.sphinx
2021
@pytest.mark.django_db
21-
class TestEmbedAPI:
22+
class BaseTestEmbedAPISphinx:
2223

2324
@pytest.fixture(autouse=True)
2425
def setup_method(self, settings):
@@ -57,6 +58,9 @@ def _get_html_content(self, html_file):
5758
section_content = [PyQuery(html_file.open().read()).outerHtml()]
5859
return section_content
5960

61+
def get(self, client, *args, **kwargs):
62+
return client.get(*args, **kwargs)
63+
6064
def test_invalid_arguments(self, client):
6165
query_params = (
6266
{
@@ -72,7 +76,7 @@ def test_invalid_arguments(self, client):
7276

7377
api_endpoint = reverse('api_embed')
7478
for param in query_params:
75-
r = client.get(api_endpoint, param)
79+
r = self.get(client, api_endpoint, param)
7680
assert r.status_code == status.HTTP_400_BAD_REQUEST
7781

7882
@mock.patch('readthedocs.embed.views.build_media_storage')
@@ -123,7 +127,7 @@ def test_valid_arguments(self, storage_mock, client):
123127
)
124128
api_endpoint = reverse('api_embed')
125129
for param in query_params:
126-
r = client.get(api_endpoint, param)
130+
r = self.get(client, api_endpoint, param)
127131
assert r.status_code == status.HTTP_200_OK
128132

129133
@mock.patch('readthedocs.embed.views.build_media_storage')
@@ -137,7 +141,8 @@ def test_embed_unknown_section(self, storage_mock, client):
137141
html_file=html_file,
138142
)
139143

140-
response = client.get(
144+
response = self.get(
145+
client,
141146
reverse('api_embed'),
142147
{
143148
'project': self.project.slug,
@@ -184,7 +189,8 @@ def test_embed_sphinx(self, storage_mock, section, client):
184189
html_file=html_file,
185190
)
186191

187-
response = client.get(
192+
response = self.get(
193+
client,
188194
reverse('api_embed'),
189195
{
190196
'project': self.project.slug,
@@ -234,7 +240,7 @@ def test_embed_sphinx(self, storage_mock, section, client):
234240
]
235241
)
236242
@mock.patch('readthedocs.embed.views.build_media_storage')
237-
def test_embed_sphinx_bibtex(self, storage_mock, section):
243+
def test_embed_sphinx_bibtex(self, storage_mock, section, client):
238244
json_file = data_path / 'sphinx/bibtex/page.json'
239245
html_file = data_path / 'sphinx/bibtex/page.html'
240246

@@ -244,11 +250,15 @@ def test_embed_sphinx_bibtex(self, storage_mock, section):
244250
html_file=html_file,
245251
)
246252

247-
response = do_embed(
248-
project=self.project,
249-
version=self.version,
250-
section=section,
251-
path='index.html',
253+
response = self.get(
254+
client,
255+
reverse('api_embed'),
256+
{
257+
'project': self.project.slug,
258+
'version': self.version.slug,
259+
'section': section,
260+
'path': 'index.html',
261+
}
252262
)
253263

254264
section_content = self._get_html_content(
@@ -267,7 +277,7 @@ def test_embed_sphinx_bibtex(self, storage_mock, section):
267277
'meta': {
268278
'project': 'project',
269279
'version': 'latest',
270-
'doc': None,
280+
'doc': 'index',
271281
'section': section,
272282
},
273283
}
@@ -294,7 +304,7 @@ def test_embed_sphinx_bibtex(self, storage_mock, section):
294304
]
295305
)
296306
@mock.patch('readthedocs.embed.views.build_media_storage')
297-
def test_embed_sphinx_glossary(self, storage_mock, section):
307+
def test_embed_sphinx_glossary(self, storage_mock, section, client):
298308
# TODO: render definition lists as a definition list with one element.
299309
json_file = data_path / 'sphinx/glossary/page.json'
300310
html_file = data_path / 'sphinx/glossary/page.html'
@@ -305,11 +315,15 @@ def test_embed_sphinx_glossary(self, storage_mock, section):
305315
html_file=html_file,
306316
)
307317

308-
response = do_embed(
309-
project=self.project,
310-
version=self.version,
311-
section=section,
312-
path='index.html',
318+
response = self.get(
319+
client,
320+
reverse('api_embed'),
321+
{
322+
'project': self.project.slug,
323+
'version': self.version.slug,
324+
'section': section,
325+
'path': 'index.html',
326+
}
313327
)
314328

315329
section_content = self._get_html_content(
@@ -325,56 +339,25 @@ def test_embed_sphinx_glossary(self, storage_mock, section):
325339
'meta': {
326340
'project': 'project',
327341
'version': 'latest',
328-
'doc': None,
342+
'doc': 'index',
329343
'section': section,
330344
},
331345
}
332346

347+
assert response.status_code == status.HTTP_200_OK
333348
assert response.data == expected
334349

335-
@mock.patch('readthedocs.embed.views.build_media_storage')
336-
def test_embed_mkdocs(self, storage_mock, client):
337-
json_file = data_path / 'mkdocs/latest/index.json'
338-
storage_mock.exists.return_value = True
339-
storage_mock.open.side_effect = self._mock_open(
340-
json_file.open().read()
341-
)
342350

343-
self.version.documentation_type = MKDOCS
344-
self.version.save()
351+
class TestEmbedAPISphinx(BaseTestEmbedAPISphinx):
345352

346-
response = client.get(
347-
reverse('api_embed'),
348-
{
349-
'project': self.project.slug,
350-
'version': self.version.slug,
351-
'path': 'index.html',
352-
'section': 'Installation',
353-
}
354-
)
353+
pass
355354

356-
expected = {
357-
'content': mock.ANY, # too long to compare here
358-
'headers': [
359-
{'Overview': 'overview'},
360-
{'Installation': 'installation'},
361-
{'Getting Started': 'getting-started'},
362-
{'Adding pages': 'adding-pages'},
363-
{'Theming our documentation': 'theming-our-documentation'},
364-
{'Changing the Favicon Icon': 'changing-the-favicon-icon'},
365-
{'Building the site': 'building-the-site'},
366-
{'Other Commands and Options': 'other-commands-and-options'},
367-
{'Deploying': 'deploying'},
368-
{'Getting help': 'getting-help'},
369-
],
370-
'url': 'http://project.readthedocs.io/en/latest/index.html',
371-
'meta': {
372-
'project': 'project',
373-
'version': 'latest',
374-
'doc': 'index',
375-
'section': 'Installation',
376-
},
377-
}
378355

379-
assert response.status_code == status.HTTP_200_OK
380-
assert response.data == expected
356+
@pytest.mark.proxito
357+
class TestProxiedEmbedAPISphinx(BaseTestEmbedAPISphinx):
358+
359+
host = 'project.readthedocs.io'
360+
361+
def get(self, client, *args, **kwargs):
362+
r = client.get(*args, HTTP_HOST=self.host, **kwargs)
363+
return r

0 commit comments

Comments
 (0)