Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stsewd committed Nov 1, 2018
1 parent 0f5d979 commit 19ae374
Showing 1 changed file with 50 additions and 2 deletions.
52 changes: 50 additions & 2 deletions readthedocs/rtd_tests/tests/test_project_forms.py
Expand Up @@ -16,7 +16,13 @@

from readthedocs.builds.constants import LATEST
from readthedocs.builds.models import Version
from readthedocs.projects.constants import PRIVATE, PROTECTED, PUBLIC
from readthedocs.projects.constants import (
PRIVATE,
PROTECTED,
PUBLIC,
REPO_TYPE_GIT,
REPO_TYPE_HG,
)
from readthedocs.projects.exceptions import ProjectSpamError
from readthedocs.projects.forms import (
ProjectAdvancedForm,
Expand All @@ -29,6 +35,7 @@


class TestProjectForms(TestCase):

@mock.patch.object(ClassifierValidator, '__call__')
def test_form_spam(self, mocked_validator):
"""Form description field fails spam validation."""
Expand Down Expand Up @@ -83,7 +90,7 @@ def test_import_repo_url(self):
('ssh+git://github.com/humitos/foo', True),
('strangeuser@bitbucket.org:strangeuser/readthedocs.git', True),
('user@one-ssh.domain.com:22/_ssh/docs', True),
] + common_urls
] + common_urls

with override_settings(ALLOW_PRIVATE_REPOS=False):
for url, valid in public_urls:
Expand Down Expand Up @@ -115,6 +122,47 @@ def test_empty_slug(self):
self.assertFalse(form.is_valid())
self.assertIn('name', form.errors)

def test_changing_vcs_should_change_latest(self):
"""When changing the project's VCS, latest should be changed too."""
project = get(Project, repo_type=REPO_TYPE_HG, default_branch=None)
latest = project.versions.get(slug=LATEST)
self.assertEqual(latest.identifier, 'default')

form = ProjectBasicsForm(
{
'repo': 'http://github.com/test/test',
'name': 'name',
'repo_type': REPO_TYPE_GIT,
},
instance=project,
)
self.assertTrue(form.is_valid())
form.save()
latest.refresh_from_db()
self.assertEqual(latest.identifier, 'master')

def test_changing_vcs_should_not_change_latest_is_not_none(self):
"""
When changing the project's VCS,
we shoudl respect the custom default branch.
"""
project = get(Project, repo_type=REPO_TYPE_HG, default_branch='custom')
latest = project.versions.get(slug=LATEST)
self.assertEqual(latest.identifier, 'custom')

form = ProjectBasicsForm(
{
'repo': 'http://github.com/test/test',
'name': 'name',
'repo_type': REPO_TYPE_GIT,
},
instance=project,
)
self.assertTrue(form.is_valid())
form.save()
latest.refresh_from_db()
self.assertEqual(latest.identifier, 'custom')


class TestProjectAdvancedForm(TestCase):

Expand Down

0 comments on commit 19ae374

Please sign in to comment.