Add test case for privacy_level Form choices
@@ -2,13 +2,14 @@ import mock
from django.contrib.auth.models import User
from django.test import TestCase
from django.test.utils import override_settings
+from django.utils.translation import ugettext_lazy as _
from django_dynamic_fixture import get
from textclassifier.validators import ClassifierValidator
-
from readthedocs.builds.constants import LATEST, STABLE
from readthedocs.builds.models import Version
from readthedocs.projects.constants import (
PRIVATE,
+ PRIVACY_CHOICES,
PROTECTED,
PUBLIC,
REPO_TYPE_GIT,
@@ -272,6 +273,28 @@ class TestProjectAdvancedForm(TestCase):
self.assertTrue(form.fields['default_version'].widget.attrs['readonly'])
self.assertEqual(form.fields['default_version'].initial, 'latest')
+ def test_hide_protected_privacy_level_new_objects(self):
+ """
+ Test PROTECTED is only allowed in old objects.
+
+ New projects are not allowed to set the privacy level as protected.
+ """
+ # New default object
+ project = get(Project)
+ form = ProjectAdvancedForm(instance=project)
+
+ privacy_choices = list(PRIVACY_CHOICES)
+ privacy_choices.remove((PROTECTED, _('Protected')))
+ self.assertEqual(form.fields['privacy_level'].choices, privacy_choices)
+
+ # "Old" object with privacy_level previously set as protected
+ project = get(
+ Project,
+ privacy_level=PROTECTED,
+ )
+ form = ProjectAdvancedForm(instance=project)
+ self.assertEqual(form.fields['privacy_level'].choices, list(PRIVACY_CHOICES))
+
class TestProjectAdvancedFormDefaultBranch(TestCase):
