Skip to content

Add tests for build json in html feature #4237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 98 additions & 1 deletion readthedocs/rtd_tests/tests/test_celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

from readthedocs.builds.constants import BUILD_STATE_INSTALLING, BUILD_STATE_FINISHED, LATEST
from readthedocs.builds.models import Build
from readthedocs.projects.models import Project
from readthedocs.doc_builder.environments import LocalBuildEnvironment
from readthedocs.projects.models import Project, Feature
from readthedocs.projects import tasks

from readthedocs.rtd_tests.utils import make_test_git
Expand Down Expand Up @@ -153,3 +154,99 @@ def run_public(self):
'public_data': {},
'error': 'Something bad happened',
})

@patch('readthedocs.projects.models.Project.repo_nonblockinglock', new=MagicMock())
@patch('readthedocs.projects.tasks.UpdateDocsTaskStep.build_docs_epub')
@patch('readthedocs.projects.tasks.UpdateDocsTaskStep.build_docs_pdf')
@patch('readthedocs.projects.tasks.UpdateDocsTaskStep.build_docs_localmedia')
@patch('readthedocs.doc_builder.backends.sphinx.SearchBuilder.build')
@patch('readthedocs.doc_builder.backends.sphinx.HtmlBuilder.build')
@patch('readthedocs.doc_builder.backends.sphinx.HtmlBuilder.append_conf')
def test_sphinx_build_html_and_search_artifacts_separated(
self, append_conf, html_build, search_build,
build_docs_localmedia, build_docs_pdf, build_docs_epub):
"""
In a project without the ``BUILD_JSON_ARTIFACTS_WITH_HTML``
feature, the json artifacts are generated by the search build.
"""
# We don't tests this builds here
build_docs_localmedia.return_value = True
build_docs_pdf.return_value = True
build_docs_epub.return_value = True

version = self.project.versions.get(slug=LATEST)
build_env = LocalBuildEnvironment(self.project, version, record=False)

update_docs = tasks.UpdateDocsTaskStep()
update_docs.version = version
update_docs.project = self.project
update_docs.build_env = build_env

outcomes = update_docs.build_docs()

self.assertFalse(
self.project.has_feature(
Feature.BUILD_JSON_ARTIFACTS_WITH_HTML
)
)
# The html build was triggered
append_conf.assert_called_once()
html_build.assert_called_once()
# The search build was triggered
search_build.assert_called_once()
self.assertTrue(
all(outcomes.values())
)

@patch('readthedocs.projects.models.Project.repo_nonblockinglock', new=MagicMock())
@patch('readthedocs.projects.tasks.UpdateDocsTaskStep.build_docs_epub')
@patch('readthedocs.projects.tasks.UpdateDocsTaskStep.build_docs_pdf')
@patch('readthedocs.projects.tasks.UpdateDocsTaskStep.build_docs_localmedia')
@patch('readthedocs.doc_builder.backends.sphinx.SearchBuilder.build')
@patch('readthedocs.doc_builder.backends.sphinx.HtmlBuilder.build')
@patch('readthedocs.doc_builder.backends.sphinx.HtmlBuilder.append_conf')
def test_sphinx_build_html_and_search_artifacts_together(
self, append_conf, html_build, search_build,
build_docs_localmedia, build_docs_pdf, build_docs_epub):
"""
In a project with the ``BUILD_JSON_ARTIFACTS_WITH_HTML``
feature, the json artifacts are generated by the html build.
To keep compatibility with the previous behavior the search build
is skipped.
"""
# We don't tests this builds here
build_docs_localmedia.return_value = True
build_docs_pdf.return_value = True
build_docs_epub.return_value = True


feature = get(
Feature,
projects=[self.project],
feature_id=Feature.BUILD_JSON_ARTIFACTS_WITH_HTML,
)

version = self.project.versions.get(slug=LATEST)
build_env = LocalBuildEnvironment(self.project, version, record=False)

update_docs = tasks.UpdateDocsTaskStep()
update_docs.version = version
update_docs.project = self.project
update_docs.build_env = build_env

outcomes = update_docs.build_docs()

self.assertTrue(
self.project.has_feature(
Feature.BUILD_JSON_ARTIFACTS_WITH_HTML
)
)
# The html build was triggered
append_conf.assert_called_once()
html_build.assert_called_once()
# The search build wasn't triggered
search_build.assert_not_called()
# But still returns as success to keep compatibility
self.assertTrue(
all(outcomes.values())
)