Skip to content
Merged
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
61 changes: 61 additions & 0 deletions readthedocs/rtd_tests/tests/test_doc_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
from django.test.utils import override_settings

from readthedocs.config.tests.test_config import get_build_config
from readthedocs.doc_builder.backends.mkdocs import BaseMkdocs
from readthedocs.doc_builder.backends.sphinx import BaseSphinx
from readthedocs.doc_builder.python_environments import Virtualenv
from readthedocs.projects.exceptions import ProjectConfigurationError
from readthedocs.projects.exceptions import UserFileNotFound
from readthedocs.projects.models import Project


Expand Down Expand Up @@ -112,3 +114,62 @@ def test_multiple_conf_py(
with pytest.raises(ProjectConfigurationError):
with override_settings(DOCROOT=tmp_docs_dir):
base_sphinx.show_conf()


@override_settings(PRODUCTION_DOMAIN="readthedocs.org")
class MkDocsBuilderTest(TestCase):
fixtures = ["test_data", "eric"]

def setUp(self):
self.project = Project.objects.get(slug="pip")
self.version = self.project.versions.first()

self.build_env = mock.MagicMock()
self.build_env.project = self.project
self.build_env.version = self.version
self.build_env.build = {
"id": 123,
}
self.build_env.api_client = mock.MagicMock()

@patch("readthedocs.doc_builder.backends.mkdocs.BaseMkdocs.run")
@patch("readthedocs.projects.models.Project.checkout_path")
@patch("readthedocs.doc_builder.python_environments.load_yaml_config")
def test_project_without_mkdocs_yml(
self,
load_yaml_config,
checkout_path,
_,
):
"""
Test for a project with a missing ``mkdocs.yml`` file.

When ``mkdocs.configuration`` points to a file that doesn't exist,
a ``UserFileNotFound`` error should be raised.
"""
tmp_dir = tempfile.mkdtemp()
checkout_path.return_value = tmp_dir
python_env = Virtualenv(
version=self.version,
build_env=self.build_env,
config=get_build_config(
{"mkdocs": {"configuration": "mkdocs.yml"}},
validate=True,
source_file=f"{tmp_dir}/readthedocs.yml",
),
)
base_mkdocs = BaseMkdocs(
build_env=self.build_env,
python_env=python_env,
)
with self.assertRaises(UserFileNotFound) as e:
base_mkdocs.show_conf()

self.assertEqual(
e.exception.message_id,
UserFileNotFound.FILE_NOT_FOUND,
)
self.assertEqual(
e.exception.format_values.get("filename"),
"mkdocs.yml",
)