From b15d96317ff5b17d9a5ff669521f9776c059e4e8 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 23 2017 10:43:43 +0000 Subject: [PATCH 1/2] Make the label of the flag render based on the flag's status Instead of the previous approach that was using the percentages Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/templates/commit.html b/pagure/templates/commit.html index 00a9c93..5b249de 100644 --- a/pagure/templates/commit.html +++ b/pagure/templates/commit.html @@ -135,12 +135,15 @@ {% for flag in flags %}
  • - {{ flag.username }} -
    {{ flag.percent }}%
    + + {{ flag.username }} + +
    + + {{- flag.status -}} + {%- if flag.percent %} ({{ flag.percent }}%) {%- endif -%} + +
    {{ flag.comment }} diff --git a/pagure/templates/pull_request.html b/pagure/templates/pull_request.html index 7c9b325..1c59530 100644 --- a/pagure/templates/pull_request.html +++ b/pagure/templates/pull_request.html @@ -683,12 +683,15 @@ {% for flag in pull_request.flags %}
  • - {{ flag.username }} -
    {{ flag.percent }}%
    + + {{ flag.username }} + +
    + + {{ flag.status }} + {%- if flag.percent %} ({{ flag.percent }}%) {%- endif %} + +
    {{ flag.comment }} diff --git a/pagure/ui/filters.py b/pagure/ui/filters.py index 66b342a..64a7687 100644 --- a/pagure/ui/filters.py +++ b/pagure/ui/filters.py @@ -652,3 +652,17 @@ def table_get_link_order(column, order_key, order): else: # Default to descending return 'desc' + + +@APP.template_filter('flag2label') +def flag_to_label(flag): + """ For a given flag return the bootstrap label to use + """ + status = { + 'success': 'label-success', + 'failure': 'label-danger', + 'error': 'label-danger', + 'pending': 'label-info', + 'canceled': 'label-warning', + } + return status[flag.status.lower()] From c43375de7e109ee3d724739ec87f2dfd0d9b514c Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 23 2017 10:43:43 +0000 Subject: [PATCH 2/2] Add tests for the UI of commit flags Signed-off-by: Pierre-Yves Chibon --- diff --git a/tests/test_pagure_flask_ui_repo_flag_commit.py b/tests/test_pagure_flask_ui_repo_flag_commit.py new file mode 100644 index 0000000..47d4ef6 --- /dev/null +++ b/tests/test_pagure_flask_ui_repo_flag_commit.py @@ -0,0 +1,270 @@ +# -*- coding: utf-8 -*- + +""" + (c) 2017 - Copyright Red Hat Inc + + Authors: + Pierre-Yves Chibon + +""" + +import unittest +import sys +import os + +import pygit2 + +sys.path.insert(0, os.path.join(os.path.dirname( + os.path.abspath(__file__)), '..')) + +import pagure +import pagure.lib +import tests + + +class ViewCommitFlagtests(tests.SimplePagureTest): + """ Tests for the UI related to commit flags """ + + def setUp(self): + """ Set up the environnment, ran before every tests. """ + super(ViewCommitFlagtests, self).setUp() + + pagure.APP.config['TESTING'] = True + pagure.SESSION = self.session + pagure.ui.SESSION = self.session + pagure.ui.app.SESSION = self.session + pagure.ui.filters.SESSION = self.session + pagure.ui.repo.SESSION = self.session + + tests.create_projects(self.session) + tests.create_tokens(self.session) + + # Add a README to the git repo - First commit + tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git')) + repo = pygit2.Repository(os.path.join(self.path, 'repos', 'test.git')) + self.commit = repo.revparse_single('HEAD') + + def test_view_commit_no_flag(self): + """ Test the view_commit endpoint. """ + + # View first commit + output = self.app.get('/test/c/%s' % self.commit.oid.hex) + self.assertEqual(output.status_code, 200) + self.assertIn( + 'Commit - test - %s - Pagure' % self.commit.oid.hex, + output.data) + self.assertIn( + '