Skip to content

"Default branch: latest" does not exist Fix. #5547

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

Merged
merged 5 commits into from
Apr 27, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
13 changes: 6 additions & 7 deletions readthedocs/projects/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,13 @@ def __init__(self, *args, **kwargs):
self.helper.add_input(Submit('save', _('Save')))

default_choice = (None, '-' * 9)
# commit_name is used as the id because it handles
# the special cases of LATEST and STABLE.
all_versions_choices = [
(v.commit_name, v.verbose_name)
for v in self.instance.versions.all()
]
versions_choices = self.instance.versions.filter(
machine=False).values_list('verbose_name', flat=True)

self.fields['default_branch'].widget = forms.Select(
choices=[default_choice] + all_versions_choices,
choices=[default_choice] + list(
zip(versions_choices, versions_choices)
),
)

active_versions = self.get_all_active_versions()
Expand Down
33 changes: 29 additions & 4 deletions readthedocs/rtd_tests/tests/test_project_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django_dynamic_fixture import get
from textclassifier.validators import ClassifierValidator

from readthedocs.builds.constants import LATEST
from readthedocs.builds.constants import LATEST, STABLE
from readthedocs.builds.models import Version
from readthedocs.projects.constants import (
PRIVATE,
Expand Down Expand Up @@ -261,20 +261,45 @@ def test_list_only_active_versions_on_default_version(self):
{'latest', 'public-1', 'public-2', 'private', 'protected'},
)

def test_list_all_versions_on_default_branch(self):
def test_list_only_non_auto_generated_versions_on_default_branch(self):
user_created_stable_version = get(
Version,
project=self.project,
slug='stable',
active=True,
privacy_level=PUBLIC,
identifier='ab96cbff71a8f40a4240aaf9d12e6c10',
verbose_name='stable',
)
form = ProjectAdvancedForm(instance=self.project)
# This version is created automatically by the project on save
self.assertTrue(self.project.versions.filter(slug=LATEST).exists())
latest = self.project.versions.filter(slug=LATEST)
# User created `stable` version
stable = self.project.versions.filter(slug=STABLE)
self.assertTrue(latest.exists())
# show only the versions that are not auto generated as choices
self.assertEqual(
{
identifier
for identifier, _ in form.fields['default_branch'].widget.choices
},
{
None, 'master', 'public-1', 'public-2',
None, 'stable', 'public-1', 'public-2',
'public-3', 'public/4', 'protected', 'private',
},
)
# Auto generated version `latest` should not be among the choices
self.assertNotIn(
latest.first().verbose_name,
[identifier for identifier, _ in form.fields[
'default_branch'].widget.choices],
)
# `commit_name` can not be used as the value of the choice for `stable`
self.assertNotIn(
stable.first().commit_name,
[identifier for identifier, _ in form.fields[
'default_branch'].widget.choices],
)

def test_default_version_field_if_no_active_version(self):
project_1 = get(Project)
Expand Down