1
1
import os
2
2
import textwrap
3
+ from readthedocs .core .utils .filesystem import safe_rmtree
3
4
from os .path import exists
4
5
from unittest import mock
5
6
from unittest .mock import Mock , patch
6
7
7
8
import django_dynamic_fixture as fixture
9
+ from django_dynamic_fixture import get
8
10
from django .contrib .auth .models import User
9
11
from django .test import TestCase
10
12
11
- from readthedocs .builds .constants import BRANCH , EXTERNAL , TAG
13
+ from readthedocs .builds .constants import BRANCH , EXTERNAL , STABLE , TAG
12
14
from readthedocs .builds .models import Version
13
15
from readthedocs .config import ALL
14
16
from readthedocs .doc_builder .environments import LocalBuildEnvironment
@@ -46,8 +48,8 @@ def setUp(self):
46
48
self .build_environment = LocalBuildEnvironment (api_client = mock .MagicMock ())
47
49
48
50
def tearDown (self ):
49
- repo = self . project .vcs_repo ( environment = self . build_environment )
50
- repo . make_clean_working_dir ( )
51
+ # Remove all the files created by the test for this project.
52
+ safe_rmtree ( self . project . doc_path )
51
53
super ().tearDown ()
52
54
53
55
def test_git_lsremote (self ):
@@ -72,7 +74,8 @@ def test_git_lsremote(self):
72
74
create_git_tag (repo_path , "v02" , annotated = True )
73
75
create_git_tag (repo_path , "release-ünîø∂é" )
74
76
75
- repo = self .project .vcs_repo (environment = self .build_environment )
77
+ version = self .project .versions .first ()
78
+ repo = self .project .vcs_repo (environment = self .build_environment , version = version )
76
79
# create the working dir if it not exists. It's required to ``cwd`` to
77
80
# execute the command
78
81
repo .check_working_dir ()
@@ -95,7 +98,8 @@ def test_git_lsremote_tags_only(self):
95
98
create_git_tag (repo_path , "v02" , annotated = True )
96
99
create_git_tag (repo_path , "release-ünîø∂é" )
97
100
98
- repo = self .project .vcs_repo (environment = self .build_environment )
101
+ version = self .project .versions .first ()
102
+ repo = self .project .vcs_repo (environment = self .build_environment , version = version )
99
103
# create the working dir if it not exists. It's required to ``cwd`` to
100
104
# execute the command
101
105
repo .check_working_dir ()
@@ -127,7 +131,8 @@ def test_git_lsremote_branches_only(self):
127
131
for branch in branches :
128
132
create_git_branch (repo_path , branch )
129
133
130
- repo = self .project .vcs_repo (environment = self .build_environment )
134
+ version = self .project .versions .first ()
135
+ repo = self .project .vcs_repo (environment = self .build_environment , version = version )
131
136
# create the working dir if it not exists. It's required to ``cwd`` to
132
137
# execute the command
133
138
repo .check_working_dir ()
@@ -142,7 +147,8 @@ def test_git_lsremote_branches_only(self):
142
147
)
143
148
144
149
def test_git_update_and_checkout (self ):
145
- repo = self .project .vcs_repo (environment = self .build_environment )
150
+ version = self .project .versions .first ()
151
+ repo = self .project .vcs_repo (environment = self .build_environment , version = version )
146
152
code , _ , _ = repo .update ()
147
153
self .assertEqual (code , 0 )
148
154
@@ -153,11 +159,12 @@ def test_git_update_and_checkout(self):
153
159
self .assertTrue (exists (repo .working_dir ))
154
160
155
161
def test_git_checkout_invalid_revision (self ):
156
- repo = self .project .vcs_repo (environment = self .build_environment )
162
+ version = self .project .versions .first ()
163
+ repo = self .project .vcs_repo (environment = self .build_environment , version = version )
157
164
repo .update ()
158
- version = "invalid-revision"
165
+ branch = "invalid-revision"
159
166
with self .assertRaises (RepositoryError ) as e :
160
- repo .checkout (version )
167
+ repo .checkout (branch )
161
168
self .assertEqual (
162
169
e .exception .message_id ,
163
170
RepositoryError .FAILED_TO_CHECKOUT ,
@@ -167,10 +174,17 @@ def test_check_for_submodules(self):
167
174
"""
168
175
Test that we can get a branch called 'submodule' containing a valid submodule.
169
176
"""
177
+ version = get (
178
+ Version ,
179
+ project = self .project ,
180
+ type = BRANCH ,
181
+ identifier = "submodule" ,
182
+ verbose_name = "submodule" ,
183
+ )
184
+
170
185
repo = self .project .vcs_repo (
171
186
environment = self .build_environment ,
172
- version_type = BRANCH ,
173
- version_identifier = "submodule" ,
187
+ version = version ,
174
188
)
175
189
176
190
repo .update ()
@@ -182,10 +196,16 @@ def test_check_for_submodules(self):
182
196
183
197
def test_check_submodule_urls (self ):
184
198
"""Test that a valid submodule is found in the 'submodule' branch."""
199
+ version = get (
200
+ Version ,
201
+ project = self .project ,
202
+ type = BRANCH ,
203
+ identifier = "submodule" ,
204
+ verbose_name = "submodule" ,
205
+ )
185
206
repo = self .project .vcs_repo (
186
207
environment = self .build_environment ,
187
- version_type = BRANCH ,
188
- version_identifier = "submodule" ,
208
+ version = version ,
189
209
)
190
210
repo .update ()
191
211
repo .checkout ("submodule" )
@@ -204,20 +224,24 @@ def test_git_update_with_external_version(self, fetch):
204
224
verbose_name = "1234" , # pr number
205
225
)
206
226
repo = self .project .vcs_repo (
207
- verbose_name = version .verbose_name ,
208
- version_type = version .type ,
209
- version_identifier = version .identifier ,
227
+ version = version ,
210
228
environment = self .build_environment ,
211
229
)
212
230
repo .update ()
213
231
fetch .assert_called_once ()
214
232
215
233
def test_submodule_without_url_is_included (self ):
216
234
"""Test that an invalid submodule isn't listed."""
235
+ version = get (
236
+ Version ,
237
+ project = self .project ,
238
+ type = BRANCH ,
239
+ identifier = "submodule" ,
240
+ verbose_name = "submodule" ,
241
+ )
217
242
repo = self .project .vcs_repo (
218
243
environment = self .build_environment ,
219
- version_type = BRANCH ,
220
- version_identifier = "submodule" ,
244
+ version = version ,
221
245
)
222
246
repo .update ()
223
247
repo .checkout ("submodule" )
@@ -237,10 +261,16 @@ def test_submodule_without_url_is_included(self):
237
261
self .assertEqual (submodules , ["foobar" , "not-valid-path" ])
238
262
239
263
def test_parse_submodules (self ):
264
+ version = get (
265
+ Version ,
266
+ project = self .project ,
267
+ type = BRANCH ,
268
+ identifier = "submodule" ,
269
+ verbose_name = "submodule" ,
270
+ )
240
271
repo = self .project .vcs_repo (
241
272
environment = self .build_environment ,
242
- version_type = BRANCH ,
243
- version_identifier = "submodule" ,
273
+ version = version ,
244
274
)
245
275
repo .update ()
246
276
repo .checkout ("submodule" )
@@ -290,10 +320,16 @@ def test_parse_submodules(self):
290
320
291
321
def test_skip_submodule_checkout (self ):
292
322
"""Test that a submodule is listed as available."""
323
+ version = get (
324
+ Version ,
325
+ project = self .project ,
326
+ type = BRANCH ,
327
+ identifier = "submodule" ,
328
+ verbose_name = "submodule" ,
329
+ )
293
330
repo = self .project .vcs_repo (
294
331
environment = self .build_environment ,
295
- version_type = BRANCH ,
296
- version_identifier = "submodule" ,
332
+ version = version ,
297
333
)
298
334
repo .update ()
299
335
repo .checkout ("submodule" )
@@ -303,8 +339,7 @@ def test_git_fetch_with_external_version(self):
303
339
"""Test that fetching an external build (PR branch) correctly executes."""
304
340
version = fixture .get (Version , project = self .project , type = EXTERNAL , active = True )
305
341
repo = self .project .vcs_repo (
306
- verbose_name = version .verbose_name ,
307
- version_type = version .type ,
342
+ version = version ,
308
343
environment = self .build_environment ,
309
344
)
310
345
repo .update ()
@@ -323,9 +358,17 @@ def test_update_without_branch_name(self):
323
358
repo_path = self .project .repo
324
359
create_git_branch (repo_path , "develop" )
325
360
361
+ version = get (
362
+ Version ,
363
+ project = self .project ,
364
+ type = BRANCH ,
365
+ identifier = "develop" ,
366
+ verbose_name = "develop" ,
367
+ )
368
+
326
369
repo = self .project .vcs_repo (
327
370
environment = self .build_environment ,
328
- version_type = BRANCH ,
371
+ version = version ,
329
372
)
330
373
repo .update ()
331
374
@@ -345,11 +388,19 @@ def test_special_tag_stable(self):
345
388
repo_path = self .project .repo
346
389
latest_actual_commit_hash = get_git_latest_commit_hash (repo_path , "master" )
347
390
391
+ version = get (
392
+ Version ,
393
+ project = self .project ,
394
+ type = TAG ,
395
+ identifier = latest_actual_commit_hash ,
396
+ verbose_name = "stable" ,
397
+ slug = STABLE ,
398
+ machine = True ,
399
+ )
400
+
348
401
repo = self .project .vcs_repo (
349
402
environment = self .build_environment ,
350
- version_type = TAG ,
351
- version_machine = True ,
352
- version_identifier = latest_actual_commit_hash ,
403
+ version = version ,
353
404
)
354
405
repo .update ()
355
406
0 commit comments