|
1 | 1 | """Test core util functions."""
|
2 | 2 |
|
3 |
| -import os |
| 3 | +from unittest import mock |
4 | 4 |
|
5 | 5 | import pytest
|
6 |
| -from unittest import mock |
7 |
| -from django.http import Http404 |
8 | 6 | from django.test import TestCase
|
9 | 7 | from django_dynamic_fixture import get
|
10 |
| -from unittest.mock import call |
11 | 8 |
|
12 |
| -from readthedocs.builds.constants import LATEST, BUILD_STATE_BUILDING |
13 |
| -from readthedocs.builds.models import Version, Build |
14 |
| -from readthedocs.core.utils import slugify, trigger_build, prepare_build |
15 |
| -from readthedocs.core.utils.general import wipe_version_via_slugs |
| 9 | +from readthedocs.builds.constants import BUILD_STATE_BUILDING, LATEST |
| 10 | +from readthedocs.builds.models import Build, Version |
| 11 | +from readthedocs.core.utils import slugify, trigger_build |
16 | 12 | from readthedocs.doc_builder.exceptions import BuildMaxConcurrencyError
|
17 |
| -from readthedocs.projects.constants import CELERY_LOW, CELERY_MEDIUM, CELERY_HIGH |
18 |
| -from readthedocs.projects.models import Project, Feature |
19 |
| -from readthedocs.projects.tasks import remove_dirs |
| 13 | +from readthedocs.projects.constants import ( |
| 14 | + CELERY_HIGH, |
| 15 | + CELERY_LOW, |
| 16 | + CELERY_MEDIUM, |
| 17 | +) |
| 18 | +from readthedocs.projects.models import Feature, Project |
20 | 19 |
|
21 | 20 |
|
22 | 21 | class CoreUtilTests(TestCase):
|
@@ -296,58 +295,3 @@ def test_slugify(self):
|
296 | 295 | slugify('A title_-_with separated parts', dns_safe=False),
|
297 | 296 | 'a-title_-_with-separated-parts',
|
298 | 297 | )
|
299 |
| - |
300 |
| - @mock.patch('readthedocs.core.utils.general.broadcast') |
301 |
| - def test_wipe_version_via_slug(self, mock_broadcast): |
302 |
| - wipe_version_via_slugs( |
303 |
| - version_slug=self.version.slug, |
304 |
| - project_slug=self.version.project.slug |
305 |
| - ) |
306 |
| - expected_del_dirs = [ |
307 |
| - os.path.join(self.version.project.doc_path, 'checkouts', self.version.slug), |
308 |
| - os.path.join(self.version.project.doc_path, 'envs', self.version.slug), |
309 |
| - os.path.join(self.version.project.doc_path, 'conda', self.version.slug), |
310 |
| - ] |
311 |
| - |
312 |
| - mock_broadcast.assert_has_calls( |
313 |
| - [ |
314 |
| - call(type='build', task=remove_dirs, args=[(expected_del_dirs[0],)]), |
315 |
| - call(type='build', task=remove_dirs, args=[(expected_del_dirs[1],)]), |
316 |
| - call(type='build', task=remove_dirs, args=[(expected_del_dirs[2],)]), |
317 |
| - ], |
318 |
| - any_order=False |
319 |
| - ) |
320 |
| - |
321 |
| - @mock.patch('readthedocs.core.utils.general.broadcast') |
322 |
| - def test_wipe_version_via_slug_wrong_param(self, mock_broadcast): |
323 |
| - self.assertFalse(Version.objects.filter(slug='wrong-slug').exists()) |
324 |
| - with self.assertRaises(Http404): |
325 |
| - wipe_version_via_slugs( |
326 |
| - version_slug='wrong-slug', |
327 |
| - project_slug=self.version.project.slug |
328 |
| - ) |
329 |
| - mock_broadcast.assert_not_called() |
330 |
| - |
331 |
| - @mock.patch('readthedocs.core.utils.general.broadcast') |
332 |
| - def test_wipe_version_via_slugs_same_version_slug_with_diff_proj(self, mock_broadcast): |
333 |
| - project_2 = get(Project) |
334 |
| - version_2 = get(Version, project=project_2, slug=self.version.slug) |
335 |
| - wipe_version_via_slugs( |
336 |
| - version_slug=version_2.slug, |
337 |
| - project_slug=project_2.slug, |
338 |
| - ) |
339 |
| - |
340 |
| - expected_del_dirs = [ |
341 |
| - os.path.join(version_2.project.doc_path, 'checkouts', version_2.slug), |
342 |
| - os.path.join(version_2.project.doc_path, 'envs', version_2.slug), |
343 |
| - os.path.join(version_2.project.doc_path, 'conda', version_2.slug), |
344 |
| - ] |
345 |
| - |
346 |
| - mock_broadcast.assert_has_calls( |
347 |
| - [ |
348 |
| - call(type='build', task=remove_dirs, args=[(expected_del_dirs[0],)]), |
349 |
| - call(type='build', task=remove_dirs, args=[(expected_del_dirs[1],)]), |
350 |
| - call(type='build', task=remove_dirs, args=[(expected_del_dirs[2],)]), |
351 |
| - ], |
352 |
| - any_order=False |
353 |
| - ) |
0 commit comments