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
diff --git a/README.md b/README.md
index 1961190..ba79920 100644
--- a/README.md
+++ b/README.md
@@ -92,7 +92,7 @@ Unit tests are written with the standard unittest module, and can be launched
92like this:92like this:
9393
94```94```
95(venv) $ python -m unittest discover -s tests95(venv) $ python -m unittest discover -s tests -v
96```96```
9797
98[Flask]: (https://palletsprojects.com/p/flask/)98[Flask]: (https://palletsprojects.com/p/flask/)
diff --git a/tests/test_webapp.py b/tests/test_webapp.py
99new file mode 10064499new file mode 100644
index 0000000..d63af1c
--- /dev/null
+++ b/tests/test_webapp.py
@@ -0,0 +1,35 @@
1import unittest
2
3import webapp
4
5
6class TestWebapp(unittest.TestCase):
7 def test_bug_link(self):
8 """
9 Test bug links can be generated as expected
10 """
11 test_data = [
12 ("https://bugs.launchpad.net/project/+bug/1955391",
13 '<a href="https://bugs.launchpad.net/project/+bug/1955391/">#1955391</a>'),
14 ]
15 for web_link, html_link in test_data:
16 with self.subTest():
17 self.assertEqual(webapp.bug_link(web_link), html_link)
18
19 def test_bug_title(self):
20 """
21 Test bug title can be generated as expected
22 """
23 test_data = [
24 ('Bug #123456 in The Given project: "Actual title of the bug"',
25 "Actual title of the bug"),
26 ('Bug #123456 in The Given project: "Actual \"title\" of the bug"',
27 'Actual "title" of the bug'),
28 ]
29 for full_title, expected_title in test_data:
30 with self.subTest():
31 self.assertEqual(webapp.bug_title(full_title), expected_title)
32
33
34if __name__ == "__main__":
35 unittest.main()
diff --git a/webapp/__init__.py b/webapp/__init__.py
index befaea5..329fec0 100644
--- a/webapp/__init__.py
+++ b/webapp/__init__.py
@@ -70,24 +70,27 @@ def pluralize(number, singular="", plural="s"):
7070
7171
72@app.template_filter("bug_link")72@app.template_filter("bug_link")
73def bug_link(bug_task):73def bug_link(web_link):
74 # a bug_task.title looks like74 """
75 # Bug #123456 in The Given project: "Actual title of the bug"75 Extract bug ID from a Launchpad Web link and return an HTML link
76 rexp = r"Bug #(?P<id>\d*) .*\"(?P<title>.*)\""76 """
77 info = re.search(rexp, bug_task.title).groupdict()77 # `web_link` comes from `bug_task.web_link` and looks like
7878 # https://bugs.launchpad.net/project/+bug/123456
79 bug_link = f"<a href=\"{bug_task.web_link}/\">#{info['id']}</a>"79 bug_id = web_link.split("/")[-1]
80
81 bug_link = f"<a href=\"{web_link}/\">#{bug_id}</a>"
80 return bug_link82 return bug_link
8183
8284
83@app.template_filter("bug_title")85@app.template_filter("bug_title")
84def bug_title(bug_task):86def bug_title(title):
85 # a bug_task.title looks like87 """
88 Extract the bug title from a Launchpad bug task
89 """
90 # `title` comes from `bug_task.title` and looks like
86 # Bug #123456 in The Given project: "Actual title of the bug"91 # Bug #123456 in The Given project: "Actual title of the bug"
87 rexp = r"Bug #(?P<id>\d*) .*\"(?P<title>.*)\""92 idx = title.find("\"")
88 info = re.search(rexp, bug_task.title).groupdict()93 bug_title = title[idx+1:-1]
89
90 bug_title = info["title"]
91 return bug_title94 return bug_title
9295
9396
diff --git a/webapp/templates/summary.html b/webapp/templates/summary.html
index c409720..d51ef18 100644
--- a/webapp/templates/summary.html
+++ b/webapp/templates/summary.html
@@ -16,7 +16,7 @@
16 {% for importance, bugs in report_bug_list|groupby("importance") if importance in ["Critical", "High"] %}16 {% for importance, bugs in report_bug_list|groupby("importance") if importance in ["Critical", "High"] %}
17 <dt>{{ importance }}</dt>17 <dt>{{ importance }}</dt>
18 {% for bug in bugs %}18 {% for bug in bugs %}
19 <dd>{{ bug|bug_link|safe }} {{ bug|bug_title }}</dd>19 <dd>{{ bug.web_link|bug_link|safe }} {{ bug.title|bug_title }}</dd>
20 {% endfor %}20 {% endfor %}
21 {% else %}21 {% else %}
22 <dt>Critical/High</dt>22 <dt>Critical/High</dt>
@@ -24,7 +24,7 @@
24 {% endfor %}24 {% endfor %}
25 <dt>Other</dt>25 <dt>Other</dt>
26 {% for bug in report_bug_list if bug.importance not in ["Critical", "High"] %}26 {% for bug in report_bug_list if bug.importance not in ["Critical", "High"] %}
27 <dd>{{ bug|bug_link|safe }} {{ bug|bug_title }}</dd>27 <dd>{{ bug.web_link|bug_link|safe }} {{ bug.title|bug_title }}</dd>
28 {% else %}28 {% else %}
29 <dd><em>None</em></dd>29 <dd><em>None</em></dd>
30 {% endfor %}30 {% endfor %}

Subscribers

People subscribed via source and target branches

to all changes: