Merge ~pieq/oem-qa-autosummary:fix-1929019-double-quote into oem-qa-autosummary:master

Proposed by Pierre Equoy
Status: Merged
Approved by: Pierre Equoy
Approved revision: bb9880a5ee1ba40d5b7bdfd13fb2b136b1972ddb
Merged at revision: 7d463e3e3784c08873530da059b7e609f1b6ecdb
Proposed branch: ~pieq/oem-qa-autosummary:fix-1929019-double-quote
Merge into: oem-qa-autosummary:master
Diff against target: 121 lines (+54/-16)
4 files modified
README.md (+1/-1)
tests/test_webapp.py (+35/-0)
webapp/__init__.py (+16/-13)
webapp/templates/summary.html (+2/-2)
Reviewer Review Type Date Requested Status
Nara Huang (community) Approve
Review via email: mp+414281@code.launchpad.net

Description of the change

Cleaned up some helper functions, one of which was creating a bug when generating summaries that contained bugs with double quotes in their titles.

In the process, I rewrote two help functions and added unit tests for them.

Test done:

A. Current version
------------------
1. Run the current version of autosummary
2. Find a project that can be used to generate an autosummary (I used Havana gm3-uc20 milestone)
3. Find a bug in that project that would be displayed in the generated summary
4. Update the title of that bug to include some double quotes ("blabla")
5. Generate the summary

→ The title of the chosen bug is truncated or even completely empty

B. Version in this MR
---------------------
1. Run it locally
2. Find a project that can be used to generate an autosummary (I used Havana gm3-uc20 milestone)
3. Find a bug in that project that would be displayed in the generated summary
4. Update the title of that bug to include some double quotes ("blabla")
5. Generate the summary

→ The title appears as expected

C. Run unit tests with version in this MR
-----------------------------------------

(venv)$ python -m unittest discover -s tests -v
ERROR:root:the mail.content file is not found on the WebDAV server
ERROR:root:sha256sum file for a given image is not found on the WebDAV server
test_get_available_projects (test_summary.TestSummary) ... ok
test_get_date_from_image_name (test_summary.TestSummary)
Test datetimes can be retrieved from image names ... ok
test_bug_link (test_webapp.TestWebapp)
Test bug links can be generated as expected ... ok
test_bug_title (test_webapp.TestWebapp)
Test bug title can be generated as expected ... ok

----------------------------------------------------------------------
Ran 4 tests in 0.004s

OK

To post a comment you must log in.
Revision history for this message
Nara Huang (narahuang) wrote :

LGTM +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/README.md b/README.md
2index 1961190..ba79920 100644
3--- a/README.md
4+++ b/README.md
5@@ -92,7 +92,7 @@ Unit tests are written with the standard unittest module, and can be launched
6 like this:
7
8 ```
9-(venv) $ python -m unittest discover -s tests
10+(venv) $ python -m unittest discover -s tests -v
11 ```
12
13 [Flask]: (https://palletsprojects.com/p/flask/)
14diff --git a/tests/test_webapp.py b/tests/test_webapp.py
15new file mode 100644
16index 0000000..d63af1c
17--- /dev/null
18+++ b/tests/test_webapp.py
19@@ -0,0 +1,35 @@
20+import unittest
21+
22+import webapp
23+
24+
25+class TestWebapp(unittest.TestCase):
26+ def test_bug_link(self):
27+ """
28+ Test bug links can be generated as expected
29+ """
30+ test_data = [
31+ ("https://bugs.launchpad.net/project/+bug/1955391",
32+ '<a href="https://bugs.launchpad.net/project/+bug/1955391/">#1955391</a>'),
33+ ]
34+ for web_link, html_link in test_data:
35+ with self.subTest():
36+ self.assertEqual(webapp.bug_link(web_link), html_link)
37+
38+ def test_bug_title(self):
39+ """
40+ Test bug title can be generated as expected
41+ """
42+ test_data = [
43+ ('Bug #123456 in The Given project: "Actual title of the bug"',
44+ "Actual title of the bug"),
45+ ('Bug #123456 in The Given project: "Actual \"title\" of the bug"',
46+ 'Actual "title" of the bug'),
47+ ]
48+ for full_title, expected_title in test_data:
49+ with self.subTest():
50+ self.assertEqual(webapp.bug_title(full_title), expected_title)
51+
52+
53+if __name__ == "__main__":
54+ unittest.main()
55diff --git a/webapp/__init__.py b/webapp/__init__.py
56index befaea5..329fec0 100644
57--- a/webapp/__init__.py
58+++ b/webapp/__init__.py
59@@ -70,24 +70,27 @@ def pluralize(number, singular="", plural="s"):
60
61
62 @app.template_filter("bug_link")
63-def bug_link(bug_task):
64- # a bug_task.title looks like
65- # Bug #123456 in The Given project: "Actual title of the bug"
66- rexp = r"Bug #(?P<id>\d*) .*\"(?P<title>.*)\""
67- info = re.search(rexp, bug_task.title).groupdict()
68-
69- bug_link = f"<a href=\"{bug_task.web_link}/\">#{info['id']}</a>"
70+def bug_link(web_link):
71+ """
72+ Extract bug ID from a Launchpad Web link and return an HTML link
73+ """
74+ # `web_link` comes from `bug_task.web_link` and looks like
75+ # https://bugs.launchpad.net/project/+bug/123456
76+ bug_id = web_link.split("/")[-1]
77+
78+ bug_link = f"<a href=\"{web_link}/\">#{bug_id}</a>"
79 return bug_link
80
81
82 @app.template_filter("bug_title")
83-def bug_title(bug_task):
84- # a bug_task.title looks like
85+def bug_title(title):
86+ """
87+ Extract the bug title from a Launchpad bug task
88+ """
89+ # `title` comes from `bug_task.title` and looks like
90 # Bug #123456 in The Given project: "Actual title of the bug"
91- rexp = r"Bug #(?P<id>\d*) .*\"(?P<title>.*)\""
92- info = re.search(rexp, bug_task.title).groupdict()
93-
94- bug_title = info["title"]
95+ idx = title.find("\"")
96+ bug_title = title[idx+1:-1]
97 return bug_title
98
99
100diff --git a/webapp/templates/summary.html b/webapp/templates/summary.html
101index c409720..d51ef18 100644
102--- a/webapp/templates/summary.html
103+++ b/webapp/templates/summary.html
104@@ -16,7 +16,7 @@
105 {% for importance, bugs in report_bug_list|groupby("importance") if importance in ["Critical", "High"] %}
106 <dt>{{ importance }}</dt>
107 {% for bug in bugs %}
108- <dd>{{ bug|bug_link|safe }} {{ bug|bug_title }}</dd>
109+ <dd>{{ bug.web_link|bug_link|safe }} {{ bug.title|bug_title }}</dd>
110 {% endfor %}
111 {% else %}
112 <dt>Critical/High</dt>
113@@ -24,7 +24,7 @@
114 {% endfor %}
115 <dt>Other</dt>
116 {% for bug in report_bug_list if bug.importance not in ["Critical", "High"] %}
117- <dd>{{ bug|bug_link|safe }} {{ bug|bug_title }}</dd>
118+ <dd>{{ bug.web_link|bug_link|safe }} {{ bug.title|bug_title }}</dd>
119 {% else %}
120 <dd><em>None</em></dd>
121 {% endfor %}

Subscribers

People subscribed via source and target branches

to all changes: