Skip to content
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

Trigger build on default branch when saving a project #5393

Merged
merged 9 commits into from
Mar 14, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions readthedocs/core/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ def prepare_build(

if not version:
version = project.versions.get(slug=LATEST)
if not version.active:
dojutsu-user marked this conversation as resolved.
Show resolved Hide resolved
default_version_slug = project.default_branch
version = project.versions.get(slug=default_version_slug)

kwargs = {
'version_pk': version.pk,
Expand Down
29 changes: 29 additions & 0 deletions readthedocs/rtd_tests/tests/test_core_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from readthedocs.projects.tasks import remove_dirs
from readthedocs.core.utils import slugify, trigger_build
from readthedocs.projects.models import Project
from readthedocs.builds.constants import LATEST


class CoreUtilTests(TestCase):
Expand All @@ -33,6 +34,34 @@ def test_trigger_skipped_project(self, update_docs_task):
self.assertEqual(result, (None, None))
self.assertFalse(update_docs_task.signature.called)
self.assertFalse(update_docs_task.signature().apply_async.called)

@mock.patch('readthedocs.projects.tasks.update_docs_task')
def test_trigger_build_when_latest_is_not_activated(self, update_docs_task):
self.assertFalse(Version.objects.filter(slug='test-slug').exists())

project_1 = get(Project)
version_1 = get(Version, project=project_1, slug='test-slug')
active_version = project_1.versions.filter(slug=LATEST).update(active=False)

project_1.default_branch = 'test-slug'
project_1.save()

trigger_build(project=project_1)
kwargs = {
'version_pk': version_1.pk,
'record': True,
'force': False,
'build_pk': mock.ANY,
}

update_docs_task.signature.assert_has_calls([
mock.call(
args=(project_1.pk,),
kwargs=kwargs,
options=mock.ANY,
immutable=True,
),
])

@mock.patch('readthedocs.projects.tasks.update_docs_task')
def test_trigger_custom_queue(self, update_docs):
Expand Down