1
1
# -*- coding: utf-8 -*-
2
+
2
3
import os
4
+ import mock
3
5
4
6
from django .test import TestCase
5
7
6
- from readthedocs .projects .models import ImportedFile , Project
7
- from readthedocs .projects .tasks import _create_imported_files , _sync_imported_files
8
+ from readthedocs .projects .models import ImportedFile , Project , HTMLFile
9
+ from readthedocs .projects .tasks import (
10
+ _create_imported_files ,
11
+ _sync_imported_files ,
12
+ _create_intersphinx_data ,
13
+ )
14
+ from readthedocs .sphinx_domains .models import SphinxDomain
8
15
9
16
10
17
base_dir = os .path .dirname (os .path .dirname (__file__ ))
@@ -16,7 +23,7 @@ class ImportedFileTests(TestCase):
16
23
def setUp (self ):
17
24
self .project = Project .objects .get (slug = 'pip' )
18
25
self .version = self .project .versions .first ()
19
-
26
+
20
27
def _manage_imported_files (self , version , path , commit , build ):
21
28
"""Helper function for the tests to create and sync ImportedFiles."""
22
29
_create_imported_files (version , path , commit , build )
@@ -26,9 +33,9 @@ def test_properly_created(self):
26
33
test_dir = os .path .join (base_dir , 'files' )
27
34
self .assertEqual (ImportedFile .objects .count (), 0 )
28
35
self ._manage_imported_files (self .version , test_dir , 'commit01' , 1 )
29
- self .assertEqual (ImportedFile .objects .count (), 3 )
36
+ self .assertEqual (ImportedFile .objects .count (), 4 )
30
37
self ._manage_imported_files (self .version , test_dir , 'commit01' , 2 )
31
- self .assertEqual (ImportedFile .objects .count (), 3 )
38
+ self .assertEqual (ImportedFile .objects .count (), 4 )
32
39
33
40
def test_update_commit (self ):
34
41
test_dir = os .path .join (base_dir , 'files' )
@@ -54,4 +61,68 @@ def test_update_content(self):
54
61
self ._manage_imported_files (self .version , test_dir , 'commit02' , 2 )
55
62
self .assertNotEqual (ImportedFile .objects .get (name = 'test.html' ).md5 , 'c7532f22a052d716f7b2310fb52ad981' )
56
63
57
- self .assertEqual (ImportedFile .objects .count (), 3 )
64
+ self .assertEqual (ImportedFile .objects .count (), 4 )
65
+
66
+ @mock .patch ('readthedocs.projects.tasks.os.path.exists' )
67
+ def test_create_intersphinx_data (self , mock_exists ):
68
+ mock_exists .return_Value = True
69
+
70
+ # Test data for objects.inv file
71
+ test_objects_inv = {
72
+ 'cpp:function' : {
73
+ 'sphinx.test.function' : [
74
+ 'dummy-proj-1' ,
75
+ 'dummy-version-1' ,
76
+ 'test.html#epub-faq' , # file generated by ``sphinx.builders.html.StandaloneHTMLBuilder``
77
+ 'dummy-func-name-1' ,
78
+ ]
79
+ },
80
+ 'py:function' : {
81
+ 'sample.test.function' : [
82
+ 'dummy-proj-2' ,
83
+ 'dummy-version-2' ,
84
+ 'test.html#sample-test-func' , # file generated by ``sphinx.builders.html.StandaloneHTMLBuilder``
85
+ 'dummy-func-name-2'
86
+ ]
87
+ },
88
+ 'js:function' : {
89
+ 'testFunction' : [
90
+ 'dummy-proj-3' ,
91
+ 'dummy-version-3' ,
92
+ 'api/#test-func' , # file generated by ``sphinx.builders.dirhtml.DirectoryHTMLBuilder``
93
+ 'dummy-func-name-3'
94
+ ]
95
+ }
96
+ }
97
+
98
+ with mock .patch (
99
+ 'sphinx.ext.intersphinx.fetch_inventory' ,
100
+ return_value = test_objects_inv
101
+ ) as mock_fetch_inventory :
102
+
103
+ test_dir = os .path .join (base_dir , 'files' )
104
+
105
+ _create_imported_files (self .version , test_dir , 'commit01' , 1 )
106
+ _create_intersphinx_data (self .version , test_dir , 'commit01' , 1 )
107
+
108
+ # there will be two html files,
109
+ # `api/index.html` and `test.html`
110
+ self .assertEqual (
111
+ HTMLFile .objects .all ().count (),
112
+ 2
113
+ )
114
+ self .assertEqual (
115
+ HTMLFile .objects .filter (path = 'api/index.html' ).count (),
116
+ 1
117
+ )
118
+
119
+ html_file_api = HTMLFile .objects .filter (path = 'api/index.html' ).first ()
120
+
121
+ self .assertEqual (
122
+ SphinxDomain .objects .all ().count (),
123
+ 3
124
+ )
125
+ self .assertEqual (
126
+ SphinxDomain .objects .filter (html_file = html_file_api ).count (),
127
+ 1
128
+ )
0 commit comments