17
17
data_path = Path (__file__ ).parent .resolve () / 'data'
18
18
19
19
20
+ @pytest .mark .sphinx
20
21
@pytest .mark .django_db
21
- class TestEmbedAPI :
22
+ class BaseTestEmbedAPISphinx :
22
23
23
24
@pytest .fixture (autouse = True )
24
25
def setup_method (self , settings ):
@@ -57,6 +58,9 @@ def _get_html_content(self, html_file):
57
58
section_content = [PyQuery (html_file .open ().read ()).outerHtml ()]
58
59
return section_content
59
60
61
+ def get (self , client , * args , ** kwargs ):
62
+ return client .get (* args , ** kwargs )
63
+
60
64
def test_invalid_arguments (self , client ):
61
65
query_params = (
62
66
{
@@ -72,7 +76,7 @@ def test_invalid_arguments(self, client):
72
76
73
77
api_endpoint = reverse ('api_embed' )
74
78
for param in query_params :
75
- r = client .get (api_endpoint , param )
79
+ r = self .get (client , api_endpoint , param )
76
80
assert r .status_code == status .HTTP_400_BAD_REQUEST
77
81
78
82
@mock .patch ('readthedocs.embed.views.build_media_storage' )
@@ -123,7 +127,7 @@ def test_valid_arguments(self, storage_mock, client):
123
127
)
124
128
api_endpoint = reverse ('api_embed' )
125
129
for param in query_params :
126
- r = client .get (api_endpoint , param )
130
+ r = self .get (client , api_endpoint , param )
127
131
assert r .status_code == status .HTTP_200_OK
128
132
129
133
@mock .patch ('readthedocs.embed.views.build_media_storage' )
@@ -137,7 +141,8 @@ def test_embed_unknown_section(self, storage_mock, client):
137
141
html_file = html_file ,
138
142
)
139
143
140
- response = client .get (
144
+ response = self .get (
145
+ client ,
141
146
reverse ('api_embed' ),
142
147
{
143
148
'project' : self .project .slug ,
@@ -184,7 +189,8 @@ def test_embed_sphinx(self, storage_mock, section, client):
184
189
html_file = html_file ,
185
190
)
186
191
187
- response = client .get (
192
+ response = self .get (
193
+ client ,
188
194
reverse ('api_embed' ),
189
195
{
190
196
'project' : self .project .slug ,
@@ -234,7 +240,7 @@ def test_embed_sphinx(self, storage_mock, section, client):
234
240
]
235
241
)
236
242
@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 ):
238
244
json_file = data_path / 'sphinx/bibtex/page.json'
239
245
html_file = data_path / 'sphinx/bibtex/page.html'
240
246
@@ -244,11 +250,15 @@ def test_embed_sphinx_bibtex(self, storage_mock, section):
244
250
html_file = html_file ,
245
251
)
246
252
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
+ }
252
262
)
253
263
254
264
section_content = self ._get_html_content (
@@ -267,7 +277,7 @@ def test_embed_sphinx_bibtex(self, storage_mock, section):
267
277
'meta' : {
268
278
'project' : 'project' ,
269
279
'version' : 'latest' ,
270
- 'doc' : None ,
280
+ 'doc' : 'index' ,
271
281
'section' : section ,
272
282
},
273
283
}
@@ -294,7 +304,7 @@ def test_embed_sphinx_bibtex(self, storage_mock, section):
294
304
]
295
305
)
296
306
@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 ):
298
308
# TODO: render definition lists as a definition list with one element.
299
309
json_file = data_path / 'sphinx/glossary/page.json'
300
310
html_file = data_path / 'sphinx/glossary/page.html'
@@ -305,11 +315,15 @@ def test_embed_sphinx_glossary(self, storage_mock, section):
305
315
html_file = html_file ,
306
316
)
307
317
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
+ }
313
327
)
314
328
315
329
section_content = self ._get_html_content (
@@ -325,56 +339,25 @@ def test_embed_sphinx_glossary(self, storage_mock, section):
325
339
'meta' : {
326
340
'project' : 'project' ,
327
341
'version' : 'latest' ,
328
- 'doc' : None ,
342
+ 'doc' : 'index' ,
329
343
'section' : section ,
330
344
},
331
345
}
332
346
347
+ assert response .status_code == status .HTTP_200_OK
333
348
assert response .data == expected
334
349
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
- )
342
350
343
- self .version .documentation_type = MKDOCS
344
- self .version .save ()
351
+ class TestEmbedAPISphinx (BaseTestEmbedAPISphinx ):
345
352
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
355
354
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
- }
378
355
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