Skip to content

Commit 4a096a9

Browse files
committed
Merge pull request #1532 from rtfd/refactor-test-fixtures
Make test fixtures explicit
2 parents 53e2949 + 5cb0934 commit 4a096a9

15 files changed

+212
-229
lines changed

readthedocs/rtd_tests/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
class RTDTestCase(TestCase):
1414
def setUp(self):
15+
self.original_DOCROOT = settings.DOCROOT
1516
self.cwd = os.path.dirname(__file__)
1617
self.build_dir = os.path.join(self.cwd, 'builds')
1718
log.info("build dir: %s" % self.build_dir)
@@ -21,6 +22,7 @@ def setUp(self):
2122

2223
def tearDown(self):
2324
shutil.rmtree(self.build_dir)
25+
settings.DOCROOT = self.original_DOCROOT
2426

2527

2628
@patch('readthedocs.projects.views.private.trigger_build', lambda x, basic: None)

readthedocs/rtd_tests/factories/__init__.py

Whitespace-only changes.

readthedocs/rtd_tests/factories/comments_factories.py

Lines changed: 0 additions & 68 deletions
This file was deleted.

readthedocs/rtd_tests/factories/general_factories.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

readthedocs/rtd_tests/factories/projects_factories.py

Lines changed: 0 additions & 36 deletions
This file was deleted.

readthedocs/rtd_tests/tests/test_backend.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99

1010

1111
class TestGitBackend(RTDTestCase):
12-
fixtures = ['eric.json']
13-
1412
def setUp(self):
1513
git_repo = make_test_git()
1614
super(TestGitBackend, self).setUp()
17-
self.eric = User.objects.get(username='eric')
15+
self.eric = User(username='eric')
16+
self.eric.set_password('test')
17+
self.eric.save()
1818
self.project = Project.objects.create(
1919
name="Test Project",
2020
repo_type="git",
@@ -75,12 +75,12 @@ def test_parse_git_tags(self):
7575

7676

7777
class TestHgBackend(RTDTestCase):
78-
fixtures = ['eric.json']
79-
8078
def setUp(self):
8179
hg_repo = make_test_hg()
8280
super(TestHgBackend, self).setUp()
83-
self.eric = User.objects.get(username='eric')
81+
self.eric = User(username='eric')
82+
self.eric.set_password('test')
83+
self.eric.save()
8484
self.project = Project.objects.create(
8585
name="Test Project",
8686
repo_type="hg",

readthedocs/rtd_tests/tests/test_builds.py

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
import subprocess
33

44
from django.test import TestCase
5+
from django_dynamic_fixture import get
6+
from django_dynamic_fixture import fixture
57
import mock
68

9+
from readthedocs.projects.models import Project
710
from readthedocs.projects.tasks import build_docs
8-
from readthedocs.rtd_tests.factories.projects_factories import ProjectFactory
911
from readthedocs.rtd_tests.mocks.paths import fake_paths_lookup
1012
from readthedocs.doc_builder.loader import get_builder_class
1113

@@ -35,8 +37,14 @@ class BuildTests(TestCase):
3537
@mock.patch('slumber.Resource')
3638
@mock.patch('os.chdir')
3739
@mock.patch('readthedocs.projects.models.Project.api_versions')
40+
@mock.patch('readthedocs.vcs_support.utils.NonBlockingLock.__enter__')
3841
@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):
4048

4149
# subprocess mock logic
4250

@@ -46,7 +54,11 @@ def test_build(self, mock_Popen, mock_api_versions, mock_chdir, mock_apiv2_downl
4654
mock_Popen.return_value = mock_process
4755
mock_Popen.side_effect = build_subprocess_side_effect
4856

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()])
5062

5163
version = project.versions.all()[0]
5264
mock_api_versions.return_value = [version]
@@ -77,7 +89,10 @@ def test_build(self, mock_Popen, mock_api_versions, mock_chdir, mock_apiv2_downl
7789
def test_builder_comments(self):
7890

7991
# Normal build
80-
project = ProjectFactory(allow_comments=True)
92+
project = get(Project,
93+
documentation_type='sphinx',
94+
allow_comments=True,
95+
versions=[fixture()])
8196
version = project.versions.all()[0]
8297
builder_class = get_builder_class(project.documentation_type)
8398
builder = builder_class(version)
@@ -86,7 +101,10 @@ def test_builder_comments(self):
86101
def test_builder_no_comments(self):
87102

88103
# Normal build
89-
project = ProjectFactory(allow_comments=False)
104+
project = get(Project,
105+
documentation_type='sphinx',
106+
allow_comments=False,
107+
versions=[fixture()])
90108
version = project.versions.all()[0]
91109
builder_class = get_builder_class(project.documentation_type)
92110
builder = builder_class(version)
@@ -95,13 +113,15 @@ def test_builder_no_comments(self):
95113
@mock.patch('slumber.Resource')
96114
@mock.patch('os.chdir')
97115
@mock.patch('subprocess.Popen')
116+
@mock.patch('readthedocs.vcs_support.utils.NonBlockingLock.__enter__')
98117
@mock.patch('readthedocs.doc_builder.backends.sphinx.HtmlBuilder.build')
99118
@mock.patch('readthedocs.doc_builder.backends.sphinx.PdfBuilder.build')
100119
@mock.patch('readthedocs.doc_builder.backends.sphinx.EpubBuilder.build')
101120
def test_build_respects_pdf_flag(self,
102121
EpubBuilder_build,
103122
PdfBuilder_build,
104123
HtmlBuilder_build,
124+
mock_NonBlockingLock_enter,
105125
mock_Popen,
106126
mock_chdir,
107127
mock_apiv2_downloads):
@@ -114,9 +134,13 @@ def test_build_respects_pdf_flag(self,
114134
mock_Popen.return_value = mock_process
115135
mock_Popen.side_effect = build_subprocess_side_effect
116136

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()])
120144
version = project.versions.all()[0]
121145

122146
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,
139163
@mock.patch('slumber.Resource')
140164
@mock.patch('os.chdir')
141165
@mock.patch('subprocess.Popen')
166+
@mock.patch('readthedocs.vcs_support.utils.NonBlockingLock.__enter__')
142167
@mock.patch('readthedocs.doc_builder.backends.sphinx.HtmlBuilder.build')
143168
@mock.patch('readthedocs.doc_builder.backends.sphinx.PdfBuilder.build')
144169
@mock.patch('readthedocs.doc_builder.backends.sphinx.EpubBuilder.build')
145170
def test_build_respects_epub_flag(self,
146171
EpubBuilder_build,
147172
PdfBuilder_build,
148173
HtmlBuilder_build,
174+
mock_NonBlockingLock_enter,
149175
mock_Popen,
150176
mock_chdir,
151177
mock_apiv2_downloads):
@@ -158,9 +184,13 @@ def test_build_respects_epub_flag(self,
158184
mock_Popen.return_value = mock_process
159185
mock_Popen.side_effect = build_subprocess_side_effect
160186

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()])
164194
version = project.versions.all()[0]
165195

166196
conf_path = os.path.join(project.checkout_path(version.slug), project.conf_py_file)

readthedocs/rtd_tests/tests/test_celery.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616
class TestCeleryBuilding(RTDTestCase):
1717

1818
"""These tests run the build functions directly. They don't use celery"""
19-
fixtures = ['eric.json']
2019

2120
def setUp(self):
2221
repo = make_test_git()
2322
self.repo = repo
2423
super(TestCeleryBuilding, self).setUp()
25-
self.eric = User.objects.get(username='eric')
24+
self.eric = User(username='eric')
25+
self.eric.set_password('test')
26+
self.eric.save()
2627
self.project = Project.objects.create(
2728
name="Test Project",
2829
repo_type="git",

0 commit comments

Comments
 (0)