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 3 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: 27 additions & 6 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 @@ -230,6 +230,15 @@ def setUp(self):
identifier='public/4',
verbose_name='public/4',
)
get(
Version,
project=self.project,
slug='stable',
active=True,
privacy_level=PUBLIC,
identifier='ab96cbff71a8f40a4240aaf9d12e6c10',
verbose_name='stable',
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating a version named stable is a specific test, we shouldn't merge it with the rest.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stsewd Okay 👍 . Updated the PR

get(
Version,
project=self.project,
Expand Down Expand Up @@ -258,23 +267,35 @@ def test_list_only_active_versions_on_default_version(self):
slug
for slug, _ in form.fields['default_version'].widget.choices
},
{'latest', 'public-1', 'public-2', 'private', 'protected'},
{'latest', 'public-1', 'public-2', 'stable', 'private', 'protected'},
)

def test_list_all_versions_on_default_branch(self):
def test_list_only_non_auto_generated_versions_on_default_branch(self):
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)
stable = self.project.versions.filter(slug=STABLE)
self.assertTrue(latest.exists())
self.assertEqual(
{
identifier
for identifier, _ in form.fields['default_branch'].widget.choices
},
{
None, 'master', 'public-1', 'public-2',
'public-3', 'public/4', 'protected', 'private',
None, 'public-1', 'public-2',
'public-3', 'public/4', 'stable', 'protected', 'private',
},
)
self.assertNotIn(
latest.first().verbose_name,
[identifier for identifier, _ in form.fields[
'default_branch'].widget.choices],
)
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