From e0dda189246e6e0882f1982e61f5ffc3a2095241 Mon Sep 17 00:00:00 2001
From: Akanksha <akanksha_mishra01@yahoo.com>
Date: Nov 02 2018 11:44:40 +0000
Subject: [PATCH 1/2] Render status of dependent tickets differently on open/close


Fixes https://pagure.io/pagure/issue/3941

---

diff --git a/pagure/templates/issue.html b/pagure/templates/issue.html
index 62fadee..474a75d 100644
--- a/pagure/templates/issue.html
+++ b/pagure/templates/issue.html
@@ -390,10 +390,17 @@ namespace=repo.namespace, repo=repo.name, issueid=issueid)
           {% endif%}
 
           {%macro blocks_item(ticket, itemtype="block") %}
+          {% if ticket.status|lower == 'open' %}
+            {% set status_color = "success" %}
+          {% elif ticket.status|lower == 'merged' %}
+            {% set status_color = "info" %}
+          {% else %}
+            {% set status_color = "danger" %}
+          {% endif %}
           <div class="d-flex align-items-center">
               <div class="nowrap">
-              <span class="fa fa-fw text-success fa-exclamation-circle pt-1"></span>
-              <span class="text-success font-weight-bold">#{{ticket.id}}</span>
+              <span class="fa fa-fw text-{{status_color}} fa-exclamation-circle pt-1"></span>
+              <span class="text-{{status_color}} font-weight-bold">#{{ticket.id}}</span>
               </div>
               <div class="ellipsis pl-2 font-size-09">
                   <a id="{{itemtype}}-{{ ticket.id }}"

From 679dedcd393a4a1ca7d58c7aa4d8e3b2aa993ec2 Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon <pingou@pingoured.fr>
Date: Nov 02 2018 11:44:40 +0000
Subject: [PATCH 2/2] Add tests checking the behavior of the UI on ticket dependency


Basically the test checks how the UI looks when the blocking ticket
is open or closed.

Merges #3946

Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr>

---

diff --git a/tests/test_pagure_flask_ui_issues.py b/tests/test_pagure_flask_ui_issues.py
index 3add931..ae2fa04 100644
--- a/tests/test_pagure_flask_ui_issues.py
+++ b/tests/test_pagure_flask_ui_issues.py
@@ -2181,6 +2181,115 @@ class PagureFlaskIssuestests(tests.Modeltests):
         self.assertEqual(issue.depending_text, [2])
         self.assertEqual(issue.blocking_text, [])
 
+    @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
+    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    def test_update_issue_block_closed(self):
+        """ Test how blocked issue shows in the UI when the blocking ticket
+        is open and closed. """
+
+        tests.create_projects(self.session)
+        tests.create_projects_git(
+            os.path.join(self.path, 'repos'), bare=True)
+
+        # Create issues to play with
+        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        msg = pagure.lib.query.new_issue(
+            session=self.session,
+            repo=repo,
+            title='Test issue',
+            content='We should work on this',
+            user='pingou',
+        )
+        self.session.commit()
+        self.assertEqual(msg.title, 'Test issue')
+
+        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        msg = pagure.lib.query.new_issue(
+            session=self.session,
+            repo=repo,
+            title='Test issue #2',
+            content='We should work on this again',
+            user='foo',
+        )
+        self.session.commit()
+        self.assertEqual(msg.title, 'Test issue #2')
+
+        user = tests.FakeUser(username='pingou')
+        with tests.user_set(self.app.application, user):
+            output = self.app.get('/test/issue/1')
+            self.assertEqual(output.status_code, 200)
+            output_text = output.get_data(as_text=True)
+            self.assertIn(
+                '<title>Issue #1: Test issue - test - Pagure</title>',
+                output_text)
+            self.assertIn(
+                '<a class="btn btn-outline-secondary btn-sm border-0"'
+                 ' href="/test/issue/1/edit" title="Edit this issue">',
+                output_text)
+
+            csrf_token = self.get_csrf(output=output)
+
+            # Add a dependent ticket - Open
+            data = {
+                'csrf_token': csrf_token,
+                'blocking': '2',
+            }
+            output = self.app.post(
+                '/test/issue/1/update', data=data, follow_redirects=True)
+            self.assertEqual(output.status_code, 200)
+            output_text = output.get_data(as_text=True)
+            self.assertIn(
+                '<title>Issue #1: Test issue - test - Pagure</title>',
+                output_text)
+            self.assertIn(
+                '<a class="btn btn-outline-secondary btn-sm border-0"'
+                 ' href="/test/issue/1/edit" title="Edit this issue">',
+                output_text)
+            self.assertIn(
+                '<span class="fa fa-fw text-success fa-exclamation-circle pt-1"></span>',
+                output_text)
+            self.assertIn(
+                '<span class="text-success font-weight-bold">#2</span>',
+                output_text)
+
+            # Close ticket #1
+            data = {
+                'csrf_token': csrf_token,
+                'status': 'Closed',
+                'blocking': '2',
+            }
+            output = self.app.post(
+                '/test/issue/1/update', data=data, follow_redirects=True)
+            self.assertEqual(output.status_code, 200)
+            output_text = output.get_data(as_text=True)
+            self.assertIn(
+                '<title>Issue #1: Test issue - test - Pagure</title>',
+                output_text)
+
+            # Now looking at how the dependent ticket looks like:
+            output = self.app.get('/test/issue/2')
+            self.assertEqual(output.status_code, 200)
+            output_text = output.get_data(as_text=True)
+            self.assertIn(
+                '<title>Issue #2: Test issue #2 - test - Pagure</title>',
+                output_text)
+            self.assertIn(
+                '<a class="btn btn-outline-secondary btn-sm border-0"'
+                 ' href="/test/issue/2/edit" title="Edit this issue">',
+                output_text)
+            self.assertIn(
+                '<span class="fa fa-fw text-danger fa-exclamation-circle pt-1"></span>',
+                output_text)
+            self.assertIn(
+                '<span class="text-danger font-weight-bold">#1</span>',
+                output_text)
+
+        self.session.commit()
+        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
+        self.assertEqual(issue.depending_text, [])
+        self.assertEqual(issue.blocking_text, [2])
+
     @patch('pagure.lib.git.update_git')
     @patch('pagure.lib.notify.send_email')
     def test_update_issue_block(self, p_send_email, p_ugt):

