forked from readthedocs/readthedocs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace Version.get_vcs_slug() and Version.remote_slug with Version.c…
…ommit_name The two places were solving the same problem but with different results. That is undesired and resulted in invalid behaviour. The commit_name property unifies those now and has tests to make sure it works the way intended. The problem with this on-first-sight-easy problem is that we currently do store different things in "identifier", "slug", "verbose_name" fields depending if its a branch or tag, if it's a special version (like stable, latest) etc. The cleanest solution would be to refactor the Version model to expose those information more easily and store branch_name, tag_name, explicitly.
- Loading branch information
1 parent
a83a092
commit e20ae26
Showing
3 changed files
with
93 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from django.test import TestCase | ||
from django_dynamic_fixture import get | ||
from django_dynamic_fixture import new | ||
|
||
from readthedocs.builds.constants import BRANCH | ||
from readthedocs.builds.constants import LATEST | ||
from readthedocs.builds.constants import STABLE | ||
from readthedocs.builds.constants import TAG | ||
from readthedocs.builds.models import Version | ||
from readthedocs.projects.constants import REPO_TYPE_GIT | ||
from readthedocs.projects.constants import REPO_TYPE_HG | ||
from readthedocs.projects.models import Project | ||
|
||
|
||
class VersionCommitNameTests(TestCase): | ||
def test_branch_name(self): | ||
version = new(Version, identifier='release-2.5.x', | ||
slug='release-2.5.x', verbose_name='release-2.5.x', | ||
type=BRANCH) | ||
self.assertEqual(version.commit_name, 'release-2.5.x') | ||
|
||
def test_tag_name(self): | ||
version = new(Version, identifier='10f1b29a2bd2', slug='release-2.5.0', | ||
verbose_name='release-2.5.0', type=TAG) | ||
self.assertEqual(version.commit_name, 'release-2.5.0') | ||
|
||
def test_branch_with_name_stable(self): | ||
version = new(Version, identifier='origin/stable', slug=STABLE, | ||
verbose_name='stable', type=BRANCH) | ||
self.assertEqual(version.commit_name, 'stable') | ||
|
||
def test_stable_version_tag(self): | ||
version = new(Version, | ||
identifier='3d92b728b7d7b842259ac2020c2fa389f13aff0d', | ||
slug=STABLE, verbose_name=STABLE, type=TAG) | ||
self.assertEqual(version.commit_name, | ||
'3d92b728b7d7b842259ac2020c2fa389f13aff0d') | ||
|
||
def test_hg_latest_branch(self): | ||
hg_project = get(Project, repo_type=REPO_TYPE_HG) | ||
version = new(Version, identifier='default', slug=LATEST, | ||
verbose_name=LATEST, type=BRANCH, project=hg_project) | ||
self.assertEqual(version.commit_name, 'default') | ||
|
||
def test_git_latest_branch(self): | ||
git_project = get(Project, repo_type=REPO_TYPE_GIT) | ||
version = new(Version, project=git_project, | ||
identifier='origin/master', slug=LATEST, | ||
verbose_name=LATEST, type=BRANCH) | ||
self.assertEqual(version.commit_name, 'master') |