2
2
import subprocess
3
3
4
4
from django .test import TestCase
5
+ from django_dynamic_fixture import get
6
+ from django_dynamic_fixture import fixture
5
7
import mock
6
8
9
+ from readthedocs .projects .models import Project
7
10
from readthedocs .projects .tasks import build_docs
8
- from readthedocs .rtd_tests .factories .projects_factories import ProjectFactory
9
11
from readthedocs .rtd_tests .mocks .paths import fake_paths_lookup
10
12
from readthedocs .doc_builder .loader import get_builder_class
11
13
@@ -35,8 +37,14 @@ class BuildTests(TestCase):
35
37
@mock .patch ('slumber.Resource' )
36
38
@mock .patch ('os.chdir' )
37
39
@mock .patch ('readthedocs.projects.models.Project.api_versions' )
40
+ @mock .patch ('readthedocs.vcs_support.utils.NonBlockingLock.__enter__' )
38
41
@mock .patch ('subprocess.Popen' )
39
- def test_build (self , mock_Popen , mock_api_versions , mock_chdir , mock_apiv2_downloads ):
42
+ def test_build (self ,
43
+ mock_Popen ,
44
+ mock_NonBlockingLock_enter ,
45
+ mock_api_versions ,
46
+ mock_chdir ,
47
+ mock_apiv2_downloads ):
40
48
41
49
# subprocess mock logic
42
50
@@ -46,7 +54,11 @@ def test_build(self, mock_Popen, mock_api_versions, mock_chdir, mock_apiv2_downl
46
54
mock_Popen .return_value = mock_process
47
55
mock_Popen .side_effect = build_subprocess_side_effect
48
56
49
- project = ProjectFactory (allow_comments = True )
57
+ project = get (Project ,
58
+ slug = 'project-1' ,
59
+ documentation_type = 'sphinx' ,
60
+ conf_py_file = 'test_conf.py' ,
61
+ versions = [fixture ()])
50
62
51
63
version = project .versions .all ()[0 ]
52
64
mock_api_versions .return_value = [version ]
@@ -77,7 +89,10 @@ def test_build(self, mock_Popen, mock_api_versions, mock_chdir, mock_apiv2_downl
77
89
def test_builder_comments (self ):
78
90
79
91
# Normal build
80
- project = ProjectFactory (allow_comments = True )
92
+ project = get (Project ,
93
+ documentation_type = 'sphinx' ,
94
+ allow_comments = True ,
95
+ versions = [fixture ()])
81
96
version = project .versions .all ()[0 ]
82
97
builder_class = get_builder_class (project .documentation_type )
83
98
builder = builder_class (version )
@@ -86,7 +101,10 @@ def test_builder_comments(self):
86
101
def test_builder_no_comments (self ):
87
102
88
103
# Normal build
89
- project = ProjectFactory (allow_comments = False )
104
+ project = get (Project ,
105
+ documentation_type = 'sphinx' ,
106
+ allow_comments = False ,
107
+ versions = [fixture ()])
90
108
version = project .versions .all ()[0 ]
91
109
builder_class = get_builder_class (project .documentation_type )
92
110
builder = builder_class (version )
@@ -95,13 +113,15 @@ def test_builder_no_comments(self):
95
113
@mock .patch ('slumber.Resource' )
96
114
@mock .patch ('os.chdir' )
97
115
@mock .patch ('subprocess.Popen' )
116
+ @mock .patch ('readthedocs.vcs_support.utils.NonBlockingLock.__enter__' )
98
117
@mock .patch ('readthedocs.doc_builder.backends.sphinx.HtmlBuilder.build' )
99
118
@mock .patch ('readthedocs.doc_builder.backends.sphinx.PdfBuilder.build' )
100
119
@mock .patch ('readthedocs.doc_builder.backends.sphinx.EpubBuilder.build' )
101
120
def test_build_respects_pdf_flag (self ,
102
121
EpubBuilder_build ,
103
122
PdfBuilder_build ,
104
123
HtmlBuilder_build ,
124
+ mock_NonBlockingLock_enter ,
105
125
mock_Popen ,
106
126
mock_chdir ,
107
127
mock_apiv2_downloads ):
@@ -114,9 +134,13 @@ def test_build_respects_pdf_flag(self,
114
134
mock_Popen .return_value = mock_process
115
135
mock_Popen .side_effect = build_subprocess_side_effect
116
136
117
- project = ProjectFactory (
118
- enable_pdf_build = True ,
119
- enable_epub_build = False )
137
+ project = get (Project ,
138
+ slug = 'project-1' ,
139
+ documentation_type = 'sphinx' ,
140
+ conf_py_file = 'test_conf.py' ,
141
+ enable_pdf_build = True ,
142
+ enable_epub_build = False ,
143
+ versions = [fixture ()])
120
144
version = project .versions .all ()[0 ]
121
145
122
146
conf_path = os .path .join (project .checkout_path (version .slug ), project .conf_py_file )
@@ -139,13 +163,15 @@ def test_build_respects_pdf_flag(self,
139
163
@mock .patch ('slumber.Resource' )
140
164
@mock .patch ('os.chdir' )
141
165
@mock .patch ('subprocess.Popen' )
166
+ @mock .patch ('readthedocs.vcs_support.utils.NonBlockingLock.__enter__' )
142
167
@mock .patch ('readthedocs.doc_builder.backends.sphinx.HtmlBuilder.build' )
143
168
@mock .patch ('readthedocs.doc_builder.backends.sphinx.PdfBuilder.build' )
144
169
@mock .patch ('readthedocs.doc_builder.backends.sphinx.EpubBuilder.build' )
145
170
def test_build_respects_epub_flag (self ,
146
171
EpubBuilder_build ,
147
172
PdfBuilder_build ,
148
173
HtmlBuilder_build ,
174
+ mock_NonBlockingLock_enter ,
149
175
mock_Popen ,
150
176
mock_chdir ,
151
177
mock_apiv2_downloads ):
@@ -158,9 +184,13 @@ def test_build_respects_epub_flag(self,
158
184
mock_Popen .return_value = mock_process
159
185
mock_Popen .side_effect = build_subprocess_side_effect
160
186
161
- project = ProjectFactory (
162
- enable_pdf_build = False ,
163
- enable_epub_build = True )
187
+ project = get (Project ,
188
+ slug = 'project-2' ,
189
+ documentation_type = 'sphinx' ,
190
+ conf_py_file = 'test_conf.py' ,
191
+ enable_pdf_build = False ,
192
+ enable_epub_build = True ,
193
+ versions = [fixture ()])
164
194
version = project .versions .all ()[0 ]
165
195
166
196
conf_path = os .path .join (project .checkout_path (version .slug ), project .conf_py_file )
0 commit comments