TT#78800 release_dashboard: use human sorting for tags/branches

Change-Id: Ic9362c40e34f18bb465e0ab29c118e1dfe37bd0c
changes/53/39053/1
Victor Seva 5 years ago
parent daf050f140
commit 680eef8445

@ -12,7 +12,10 @@
#
# You should have received a copy of the GNU General Public License along
# with this prograproj. If not, see <http://www.gnu.org/licenses/>.
from unittest.mock import patch
from django.contrib.auth.models import User
from django.test import override_settings
from django.test import TestCase
from django.urls import reverse
@ -28,6 +31,39 @@ class TestHotfix(TestCase):
res = self.client.get(reverse("release_dashboard:hotfix"))
self.assertEqual(res.status_code, 200)
@override_settings(RELEASE_DASHBOARD_PROJECTS=["fake"])
@patch("release_dashboard.views.get_tags")
@patch("release_dashboard.views.get_branches")
def test_natural_sort(self, gb, gt):
user = User.objects.create_user(username="test")
self.client.force_login(user)
gt.return_value = []
gb.return_value = [
"branch/mr5.1",
"branch/mr8.1.1",
"branch/mr8.1.2",
"branch/mr8.1.10",
"branch/mr7.5.1",
"branch/mr6.10.1",
]
res = self.client.get(reverse("release_dashboard:hotfix"))
self.assertEqual(res.status_code, 200)
expected = [
{
"name": "fake",
"tags": [],
"branches": [
"branch/mr8.1.10",
"branch/mr8.1.2",
"branch/mr8.1.1",
"branch/mr7.5.1",
"branch/mr6.10.1",
"branch/mr5.1",
],
},
]
self.assertEqual(res.context["projects"], expected)
class TestDocker(TestCase):
def test_no_login(self):

@ -15,6 +15,7 @@
import re
from django.views.generic.base import TemplateView
from natsort import humansorted
from ..conf import settings
from release_dashboard.utils import get_branches
@ -43,9 +44,11 @@ def _projects_versions(
"name": project,
}
if tags:
info["tags"] = get_tags(project, regex)
info["tags"] = humansorted(get_tags(project, regex), reverse=True)
if branches:
info["branches"] = get_branches(project, regex)
info["branches"] = humansorted(
get_branches(project, regex), reverse=True
)
if master:
info["branches"].append("master")
res.append(info)
@ -61,8 +64,8 @@ def _common_versions(context, tags=True, branches=True):
if branches:
common_versions["branches"] |= set(project["branches"])
context["common_versions"] = {
"tags": sorted(common_versions["tags"], reverse=True),
"branches": sorted(common_versions["branches"], reverse=True),
"tags": humansorted(common_versions["tags"], reverse=True),
"branches": humansorted(common_versions["branches"], reverse=True),
}

@ -15,6 +15,7 @@ djangorestframework>=3.6,<3.7
drfapikey
flower
markdown
natsort
python-debian
PyYAML
six>=1.9

@ -5,7 +5,7 @@ FROM docker.mgm.sipwise.com/sipwise-buster:latest
# is updated with the current date. It will force refresh of all
# of the base images and things like `apt-get update` won't be using
# old cached versions when the Dockerfile is built.
ENV REFRESHED_AT 2020-03-21
ENV REFRESHED_AT 2020-04-02
# test execution; we need the backport of python3-junitxml from our own
# repository since it's not part of Debian/buster

Loading…
Cancel
Save