From 6da92ed41bdece39c5121ca9ab66d17906385671 Mon Sep 17 00:00:00 2001 From: abahrani Date: Tue, 22 Oct 2024 22:52:28 -0700 Subject: [PATCH 1/9] rename method getcomments to get_comments for better readablity --- bugzilla/bug.py | 2 +- examples/getbug.py | 4 ++-- examples/update.py | 4 ++-- tests/test_api_bug.py | 2 +- tests/test_rw_functional.py | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bugzilla/bug.py b/bugzilla/bug.py index 0a7c2d16..1efba18b 100644 --- a/bugzilla/bug.py +++ b/bugzilla/bug.py @@ -292,7 +292,7 @@ def addcomment(self, comment, private=False): return self.bugzilla.update_bugs(self.bug_id, vals) - def getcomments(self): + def get_comments(self): """ Returns an array of comment dictionaries for this bug """ diff --git a/examples/getbug.py b/examples/getbug.py index faf4c30f..f164c0a1 100644 --- a/examples/getbug.py +++ b/examples/getbug.py @@ -33,8 +33,8 @@ # comments must be fetched separately on stock bugzilla. this just returns # a raw dict with all the info. -comments = bug.getcomments() +comments = bug.get_comments() print("\nLast comment data:\n%s" % pprint.pformat(comments[-1])) -# getcomments is just a wrapper around bzapi.get_comments(), which can be +# get_comments is just a wrapper around bzapi.get_comments(), which can be # used for bulk comments fetching diff --git a/examples/update.py b/examples/update.py index cd76992e..86b1967c 100644 --- a/examples/update.py +++ b/examples/update.py @@ -38,7 +38,7 @@ # Now let's add a comment -comments = bug.getcomments() +comments = bug.get_comments() print("Bug originally has %d comments" % len(comments)) update = bzapi.build_update(comment="new example comment %s" % time.time()) @@ -46,7 +46,7 @@ # refresh() actually isn't required here because comments are fetched # on demand -comments = bug.getcomments() +comments = bug.get_comments() print("Bug now has %d comments. Last comment=%s" % (len(comments), comments[-1]["text"])) diff --git a/tests/test_api_bug.py b/tests/test_api_bug.py index 61572fc5..a82ddb14 100644 --- a/tests/test_api_bug.py +++ b/tests/test_api_bug.py @@ -200,7 +200,7 @@ def _get_fake_bug(apiname): # Stub API testing bug = fakebz.getbug(1165434) bug.get_history_raw() - bug.getcomments() + bug.get_comments() # Some hackery to hit a few attachment code paths bug.id = 663674 diff --git a/tests/test_rw_functional.py b/tests/test_rw_functional.py index 3d49688e..9333e9f9 100644 --- a/tests/test_rw_functional.py +++ b/tests/test_rw_functional.py @@ -318,8 +318,8 @@ def test05ModifyStatus(run_cli, backends): assert bug.longdescs[-1]["text"] == comment assert bug.longdescs[-1]["is_private"] == 0 - # Confirm comments is same as getcomments - assert bug.comments == bug.getcomments() + # Confirm comments is same as get_comments + assert bug.comments == bug.get_comments() # Reset state run_cli(cmd + "--status %s" % origstatus, bz) From fbb103c8fe7d79d94da7d3d99dd18bf81fe1587b Mon Sep 17 00:00:00 2001 From: abahrani Date: Tue, 22 Oct 2024 23:10:05 -0700 Subject: [PATCH 2/9] add the previous method for backward compatibility --- bugzilla/bug.py | 12 +++++++++++- tests/test_rw_functional.py | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/bugzilla/bug.py b/bugzilla/bug.py index 1efba18b..c73d00e1 100644 --- a/bugzilla/bug.py +++ b/bugzilla/bug.py @@ -4,6 +4,7 @@ # This work is licensed under the GNU GPLv2 or later. # See the COPYING file in the top-level directory. +import warnings import copy from logging import getLogger from urllib.parse import urlparse, urlunparse @@ -299,7 +300,16 @@ def get_comments(self): comment_list = self.bugzilla.get_comments([self.bug_id]) return comment_list['bugs'][str(self.bug_id)]['comments'] - + def getcomments(self): + """ + Returns an array of comment dictionaries for this bug just + """ + warnings.warn( + "getcomments() is deprecated and will be removed in a future version. Use get_comments() instead.", + DeprecationWarning, + stacklevel=2 + ) + return self.getcomment() ##################### # Get/Set bug flags # ##################### diff --git a/tests/test_rw_functional.py b/tests/test_rw_functional.py index 9333e9f9..a6dede65 100644 --- a/tests/test_rw_functional.py +++ b/tests/test_rw_functional.py @@ -320,6 +320,8 @@ def test05ModifyStatus(run_cli, backends): # Confirm comments is same as get_comments assert bug.comments == bug.get_comments() + # This method will be removed in a future version + assert bug.comments == bug.getcomments() # Reset state run_cli(cmd + "--status %s" % origstatus, bz) From bdb2ced730118d2ebe28a858fe3e9594aa7f502e Mon Sep 17 00:00:00 2001 From: abahrani Date: Tue, 22 Oct 2024 23:17:29 -0700 Subject: [PATCH 3/9] add old examples for full code coverage --- examples/deprecated/getbug.py | 40 ++++++++++++++++++++++++ examples/deprecated/update.py | 59 +++++++++++++++++++++++++++++++++++ tests/test_rw_functional.py | 1 + 3 files changed, 100 insertions(+) create mode 100644 examples/deprecated/getbug.py create mode 100644 examples/deprecated/update.py diff --git a/examples/deprecated/getbug.py b/examples/deprecated/getbug.py new file mode 100644 index 00000000..faf4c30f --- /dev/null +++ b/examples/deprecated/getbug.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python +# +# This work is licensed under the GNU GPLv2 or later. +# See the COPYING file in the top-level directory. + +# getbug.py: Simple demonstration of connecting to bugzilla, fetching +# a bug, and printing some details. + +import pprint + +import bugzilla + +# public test instance of bugzilla.redhat.com. It's okay to make changes +URL = "bugzilla.stage.redhat.com" + +bzapi = bugzilla.Bugzilla(URL) + +# getbug() is just a simple wrapper around getbugs(), which takes a list +# IDs, if you need to fetch multiple +# +# Example bug: https://bugzilla.stage.redhat.com/show_bug.cgi?id=427301 +bug = bzapi.getbug(427301) +print("Fetched bug #%s:" % bug.id) +print(" Product = %s" % bug.product) +print(" Component = %s" % bug.component) +print(" Status = %s" % bug.status) +print(" Resolution= %s" % bug.resolution) +print(" Summary = %s" % bug.summary) + +# Just check dir(bug) for other attributes, or check upstream bugzilla +# Bug.get docs for field names: +# https://bugzilla.readthedocs.io/en/latest/api/core/v1/bug.html#get-bug + +# comments must be fetched separately on stock bugzilla. this just returns +# a raw dict with all the info. +comments = bug.getcomments() +print("\nLast comment data:\n%s" % pprint.pformat(comments[-1])) + +# getcomments is just a wrapper around bzapi.get_comments(), which can be +# used for bulk comments fetching diff --git a/examples/deprecated/update.py b/examples/deprecated/update.py new file mode 100644 index 00000000..cd76992e --- /dev/null +++ b/examples/deprecated/update.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python +# +# This work is licensed under the GNU GPLv2 or later. +# See the COPYING file in the top-level directory. + +# update.py: Make changes to an existing bug + +import time + +import bugzilla + +# public test instance of bugzilla.redhat.com. It's okay to make changes +URL = "bugzilla.stage.redhat.com" +bzapi = bugzilla.Bugzilla(URL) +if not bzapi.logged_in: + print("This example requires cached login credentials for %s" % URL) + bzapi.interactive_login() + + +# Similar to build_query, build_update is a helper function that handles +# some bugzilla version incompatibility issues. All it does is return a +# properly formatted dict(), and provide friendly parameter names. +# The param names map to those accepted by Bugzilla Bug.update: +# https://bugzilla.readthedocs.io/en/latest/api/core/v1/bug.html#update-bug +# +# Example bug: https://bugzilla.stage.redhat.com/show_bug.cgi?id=427301 +# Don't worry, changing things here is fine, and won't send any email to +# users or anything. It's what bugzilla.stage.redhat.com is for! +bug = bzapi.getbug(427301) +print("Bug id=%s original summary=%s" % (bug.id, bug.summary)) + +update = bzapi.build_update(summary="new example summary %s" % time.time()) +bzapi.update_bugs([bug.id], update) + +# Call bug.refresh() to update its cached state +bug.refresh() +print("Bug id=%s new summary=%s" % (bug.id, bug.summary)) + + +# Now let's add a comment +comments = bug.getcomments() +print("Bug originally has %d comments" % len(comments)) + +update = bzapi.build_update(comment="new example comment %s" % time.time()) +bzapi.update_bugs([bug.id], update) + +# refresh() actually isn't required here because comments are fetched +# on demand +comments = bug.getcomments() +print("Bug now has %d comments. Last comment=%s" % (len(comments), + comments[-1]["text"])) + + +# The 'bug' object actually has some old convenience APIs for specific +# actions like commenting, and closing. However these aren't recommended: +# they encourage splitting up bug edits when really batching should be done +# as much as possible, not only to make your code quicker and save strain +# on the bugzilla instance, but also to avoid spamming bugzilla users with +# redundant email from two modifications that could have been batched. diff --git a/tests/test_rw_functional.py b/tests/test_rw_functional.py index a6dede65..8ed6da58 100644 --- a/tests/test_rw_functional.py +++ b/tests/test_rw_functional.py @@ -322,6 +322,7 @@ def test05ModifyStatus(run_cli, backends): assert bug.comments == bug.get_comments() # This method will be removed in a future version assert bug.comments == bug.getcomments() + assert bug.get_comments == bug.getcomments() # Reset state run_cli(cmd + "--status %s" % origstatus, bz) From 15a76168fb81199c445ae039073339b027260fc4 Mon Sep 17 00:00:00 2001 From: abahrani Date: Tue, 22 Oct 2024 23:25:44 -0700 Subject: [PATCH 4/9] add getcomments to test_api_bug.py --- examples/deprecated/getbug.py | 2 +- tests/test_api_bug.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/deprecated/getbug.py b/examples/deprecated/getbug.py index faf4c30f..ac2425d0 100644 --- a/examples/deprecated/getbug.py +++ b/examples/deprecated/getbug.py @@ -36,5 +36,5 @@ comments = bug.getcomments() print("\nLast comment data:\n%s" % pprint.pformat(comments[-1])) -# getcomments is just a wrapper around bzapi.get_comments(), which can be +# getcomments is just a wrapper around bzapi.getcomments(), which can be # used for bulk comments fetching diff --git a/tests/test_api_bug.py b/tests/test_api_bug.py index a82ddb14..9d5c2564 100644 --- a/tests/test_api_bug.py +++ b/tests/test_api_bug.py @@ -201,6 +201,7 @@ def _get_fake_bug(apiname): bug = fakebz.getbug(1165434) bug.get_history_raw() bug.get_comments() + bug.getcomments() # Some hackery to hit a few attachment code paths bug.id = 663674 From eeebcdd06a7edd79224f6e63d93180b31c2b1b3a Mon Sep 17 00:00:00 2001 From: abahrani Date: Tue, 22 Oct 2024 23:27:51 -0700 Subject: [PATCH 5/9] hot-fix typo in method of getcomments --- bugzilla/bug.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bugzilla/bug.py b/bugzilla/bug.py index c73d00e1..3a3174f4 100644 --- a/bugzilla/bug.py +++ b/bugzilla/bug.py @@ -309,7 +309,7 @@ def getcomments(self): DeprecationWarning, stacklevel=2 ) - return self.getcomment() + return self.get_comments() ##################### # Get/Set bug flags # ##################### From 85b1b710998c9d128c4f2e9dc55078bdfd8d4182 Mon Sep 17 00:00:00 2001 From: abahrani Date: Mon, 28 Oct 2024 11:04:54 -0700 Subject: [PATCH 6/9] remove unnecessary examples --- examples/deprecated/getbug.py | 40 ------------------------ examples/deprecated/update.py | 59 ----------------------------------- 2 files changed, 99 deletions(-) delete mode 100644 examples/deprecated/getbug.py delete mode 100644 examples/deprecated/update.py diff --git a/examples/deprecated/getbug.py b/examples/deprecated/getbug.py deleted file mode 100644 index ac2425d0..00000000 --- a/examples/deprecated/getbug.py +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env python -# -# This work is licensed under the GNU GPLv2 or later. -# See the COPYING file in the top-level directory. - -# getbug.py: Simple demonstration of connecting to bugzilla, fetching -# a bug, and printing some details. - -import pprint - -import bugzilla - -# public test instance of bugzilla.redhat.com. It's okay to make changes -URL = "bugzilla.stage.redhat.com" - -bzapi = bugzilla.Bugzilla(URL) - -# getbug() is just a simple wrapper around getbugs(), which takes a list -# IDs, if you need to fetch multiple -# -# Example bug: https://bugzilla.stage.redhat.com/show_bug.cgi?id=427301 -bug = bzapi.getbug(427301) -print("Fetched bug #%s:" % bug.id) -print(" Product = %s" % bug.product) -print(" Component = %s" % bug.component) -print(" Status = %s" % bug.status) -print(" Resolution= %s" % bug.resolution) -print(" Summary = %s" % bug.summary) - -# Just check dir(bug) for other attributes, or check upstream bugzilla -# Bug.get docs for field names: -# https://bugzilla.readthedocs.io/en/latest/api/core/v1/bug.html#get-bug - -# comments must be fetched separately on stock bugzilla. this just returns -# a raw dict with all the info. -comments = bug.getcomments() -print("\nLast comment data:\n%s" % pprint.pformat(comments[-1])) - -# getcomments is just a wrapper around bzapi.getcomments(), which can be -# used for bulk comments fetching diff --git a/examples/deprecated/update.py b/examples/deprecated/update.py deleted file mode 100644 index cd76992e..00000000 --- a/examples/deprecated/update.py +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env python -# -# This work is licensed under the GNU GPLv2 or later. -# See the COPYING file in the top-level directory. - -# update.py: Make changes to an existing bug - -import time - -import bugzilla - -# public test instance of bugzilla.redhat.com. It's okay to make changes -URL = "bugzilla.stage.redhat.com" -bzapi = bugzilla.Bugzilla(URL) -if not bzapi.logged_in: - print("This example requires cached login credentials for %s" % URL) - bzapi.interactive_login() - - -# Similar to build_query, build_update is a helper function that handles -# some bugzilla version incompatibility issues. All it does is return a -# properly formatted dict(), and provide friendly parameter names. -# The param names map to those accepted by Bugzilla Bug.update: -# https://bugzilla.readthedocs.io/en/latest/api/core/v1/bug.html#update-bug -# -# Example bug: https://bugzilla.stage.redhat.com/show_bug.cgi?id=427301 -# Don't worry, changing things here is fine, and won't send any email to -# users or anything. It's what bugzilla.stage.redhat.com is for! -bug = bzapi.getbug(427301) -print("Bug id=%s original summary=%s" % (bug.id, bug.summary)) - -update = bzapi.build_update(summary="new example summary %s" % time.time()) -bzapi.update_bugs([bug.id], update) - -# Call bug.refresh() to update its cached state -bug.refresh() -print("Bug id=%s new summary=%s" % (bug.id, bug.summary)) - - -# Now let's add a comment -comments = bug.getcomments() -print("Bug originally has %d comments" % len(comments)) - -update = bzapi.build_update(comment="new example comment %s" % time.time()) -bzapi.update_bugs([bug.id], update) - -# refresh() actually isn't required here because comments are fetched -# on demand -comments = bug.getcomments() -print("Bug now has %d comments. Last comment=%s" % (len(comments), - comments[-1]["text"])) - - -# The 'bug' object actually has some old convenience APIs for specific -# actions like commenting, and closing. However these aren't recommended: -# they encourage splitting up bug edits when really batching should be done -# as much as possible, not only to make your code quicker and save strain -# on the bugzilla instance, but also to avoid spamming bugzilla users with -# redundant email from two modifications that could have been batched. From fedab680cb7c0d03189dd4f11549b0b8835a2267 Mon Sep 17 00:00:00 2001 From: abahrani Date: Mon, 28 Oct 2024 11:07:01 -0700 Subject: [PATCH 7/9] remove deprication warning --- bugzilla/bug.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/bugzilla/bug.py b/bugzilla/bug.py index 3a3174f4..b0cb3a2e 100644 --- a/bugzilla/bug.py +++ b/bugzilla/bug.py @@ -4,7 +4,6 @@ # This work is licensed under the GNU GPLv2 or later. # See the COPYING file in the top-level directory. -import warnings import copy from logging import getLogger from urllib.parse import urlparse, urlunparse @@ -302,13 +301,10 @@ def get_comments(self): def getcomments(self): """ + Some code bases still use this method. So, for the sake of backward compatibility this method + stays in the class' interface. Returns an array of comment dictionaries for this bug just """ - warnings.warn( - "getcomments() is deprecated and will be removed in a future version. Use get_comments() instead.", - DeprecationWarning, - stacklevel=2 - ) return self.get_comments() ##################### # Get/Set bug flags # From 42c8087b5cda0820a2de059f9553b8a2a9acd3f9 Mon Sep 17 00:00:00 2001 From: Ali Bahrani Date: Tue, 29 Oct 2024 09:17:47 -0700 Subject: [PATCH 8/9] Update bugzilla/bug.py (cleaner function description for the older method of getcomments) Co-authored-by: Andreas Hasenkopf --- bugzilla/bug.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/bugzilla/bug.py b/bugzilla/bug.py index b0cb3a2e..6f3ec43b 100644 --- a/bugzilla/bug.py +++ b/bugzilla/bug.py @@ -299,13 +299,7 @@ def get_comments(self): comment_list = self.bugzilla.get_comments([self.bug_id]) return comment_list['bugs'][str(self.bug_id)]['comments'] - def getcomments(self): - """ - Some code bases still use this method. So, for the sake of backward compatibility this method - stays in the class' interface. - Returns an array of comment dictionaries for this bug just - """ - return self.get_comments() + getcomments = get_comments ##################### # Get/Set bug flags # ##################### From 1062e857d9b9bb1d34587b8d03b7766d66818831 Mon Sep 17 00:00:00 2001 From: abahrani Date: Tue, 29 Oct 2024 09:24:15 -0700 Subject: [PATCH 9/9] fix typo: forgotten parathesis for method call --- tests/test_rw_functional.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_rw_functional.py b/tests/test_rw_functional.py index 8ed6da58..b59d84cd 100644 --- a/tests/test_rw_functional.py +++ b/tests/test_rw_functional.py @@ -322,7 +322,7 @@ def test05ModifyStatus(run_cli, backends): assert bug.comments == bug.get_comments() # This method will be removed in a future version assert bug.comments == bug.getcomments() - assert bug.get_comments == bug.getcomments() + assert bug.get_comments() == bug.getcomments() # Reset state run_cli(cmd + "--status %s" % origstatus, bz)