Skip to content

Commit

Permalink
Minor formatting fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Aurélien Bompard <[email protected]>
  • Loading branch information
abompard committed Jun 10, 2024
1 parent a66d8be commit b6f5c0c
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 99 deletions.
18 changes: 9 additions & 9 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be
introduced by others.

Finally, software patents pose a constant threat to the existence of
any free program. We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
Expand Down Expand Up @@ -111,7 +111,7 @@ modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.

GNU LESSER GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

Expand Down Expand Up @@ -158,7 +158,7 @@ Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.

2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
Expand Down Expand Up @@ -216,7 +216,7 @@ instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.

Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
Expand Down Expand Up @@ -267,7 +267,7 @@ Library will still fall under Section 6.)
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.

6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
Expand Down Expand Up @@ -329,7 +329,7 @@ restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.

7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
Expand Down Expand Up @@ -370,7 +370,7 @@ subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties with
this License.

11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
Expand Down Expand Up @@ -422,7 +422,7 @@ conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.

14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
Expand Down Expand Up @@ -456,7 +456,7 @@ SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.

END OF TERMS AND CONDITIONS

How to Apply These Terms to Your New Libraries

If you develop a new library, and you want it to be of the greatest
Expand Down
9 changes: 3 additions & 6 deletions bugzilla2fedmsg/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
import os
import time
import logging

import click
import fedora_messaging
Expand All @@ -15,18 +14,16 @@


@click.command()
@click.option(
"-c", "--config", envvar="FEDORA_MESSAGING_CONF", help="Configuration file"
)
@click.option("-c", "--config", envvar="FEDORA_MESSAGING_CONF", help="Configuration file")
def cli(config):
"""Relay Bugzilla changes into Fedora Messaging."""
if config:
if not os.path.isfile(config):
raise click.exceptions.BadParameter("{} is not a file".format(config))
raise click.exceptions.BadParameter(f"{config} is not a file")
try:
fedora_messaging.config.conf.load_config(config_path=config)
except fedora_messaging.exceptions.ConfigurationException as e:
raise click.exceptions.BadParameter(str(e))
raise click.exceptions.BadParameter(str(e)) from e
fedora_messaging.config.conf.setup_logging()

# Now start the consumer.
Expand Down
10 changes: 3 additions & 7 deletions bugzilla2fedmsg/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ def __init__(self, conf, relay):
self._conf = conf

# Bugzilla
self.products = self._conf.get("bugzilla", {}).get(
"products", ["Fedora", "Fedora EPEL"]
)
self.products = self._conf.get("bugzilla", {}).get("products", ["Fedora", "Fedora EPEL"])

# STOMP
stomp_config = self._conf.get("stomp", {})
Expand All @@ -40,9 +38,7 @@ def __init__(self, conf, relay):
# Disable cert validation for demo only
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE
ssl_context.load_cert_chain(
stomp_config["ssl_crt"], stomp_config["ssl_key"]
)
ssl_context.load_cert_chain(stomp_config["ssl_crt"], stomp_config["ssl_key"])
else:
ssl_context = None

Expand Down Expand Up @@ -96,7 +92,7 @@ def consume(self):
continue
body = json.loads(frame.body.decode())
msg_id = frame.headers.get(StompSpec.MESSAGE_ID_HEADER)
LOGGER.debug("Received message on STOMP with ID {}".format(msg_id))
LOGGER.debug(f"Received message on STOMP with ID {msg_id}")
try:
self.relay.on_stomp_message(body, frame.headers)
except Exception:
Expand Down
14 changes: 6 additions & 8 deletions bugzilla2fedmsg/relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def _bz4_compat_transform(bug, event, objdict, obj):
if bug.get("operating_system"):
bug["op_sys"] = bug["operating_system"]
if not bug.get("weburl"):
bug["weburl"] = "https://bugzilla.redhat.com/show_bug.cgi?id=%s" % bug["id"]
bug["weburl"] = f"https://bugzilla.redhat.com/show_bug.cgi?id={bug['id']}"
event["who"] = event["user"]["login"]
event["changes"] = event.get("changes", [])
for change in event["changes"]:
Expand Down Expand Up @@ -78,7 +78,7 @@ def on_stomp_message(self, body, headers):
# it.
product_name = bug["product"]["name"]
if product_name not in self._allowed_products:
LOGGER.debug("DROP: %r not in %r" % (product_name, self._allowed_products))
LOGGER.debug("DROP: %r not in %r", product_name, self._allowed_products)
return

body["timestamp"] = datetime.datetime.fromtimestamp(
Expand All @@ -103,20 +103,18 @@ def on_stomp_message(self, body, headers):
)
body.update(objdict)

LOGGER.debug("Republishing #%s" % bug["id"])
LOGGER.debug("Republishing #%s", bug["id"])
messageclass = MessageV1
if self._bz4_compat_mode:
messageclass = MessageV1BZ4
try:
message = messageclass(
topic="bugzilla.{}".format(topic),
topic=f"bugzilla.{topic}",
body=body,
severity=INFO,
)
publish(message)
except PublishReturned as e:
LOGGER.warning(
"Fedora Messaging broker rejected message {}: {}".format(message.id, e)
)
LOGGER.warning(f"Fedora Messaging broker rejected message {message.id}: {e}")
except ConnectionException as e:
LOGGER.warning("Error sending message {}: {}".format(message.id, e))
LOGGER.warning(f"Error sending message {message.id}: {e}")
1 change: 0 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
""" Test fixtures for bugzilla2fedmsg.relay.
Authors: Adam Williamson <[email protected]>
Expand Down
4 changes: 2 additions & 2 deletions tests/test_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_connect_twice(consumer, connected_frame, message_frame):
try:
consumer.consume()
except StompConnectionError as e:
assert False, "Must not fail when already connected: {}".format(e)
pytest.fail(f"Must not fail when already connected: {e}")


def test_subscribe_twice(consumer, connected_frame, message_frame):
Expand All @@ -114,4 +114,4 @@ def test_subscribe_twice(consumer, connected_frame, message_frame):
try:
consumer.consume()
except StompProtocolError as e:
assert False, "Must not fail when already subscribed: {}".format(e)
pytest.fail(f"Must not fail when already subscribed: {e}")
53 changes: 14 additions & 39 deletions tests/test_relay.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
""" Tests for bugzilla2fedmsg.relay.
Authors: Adam Williamson <[email protected]>
Expand All @@ -12,17 +11,15 @@
import bugzilla2fedmsg.relay


class TestRelay(object):
class TestRelay:
relay = bugzilla2fedmsg.relay.MessageRelay(
{"bugzilla": {"products": ["Fedora", "Fedora EPEL"]}}
)

@mock.patch("bugzilla2fedmsg.relay.publish", autospec=True)
def test_bug_create(self, fakepublish, bug_create_message):
"""Check correct result for bug.create message."""
self.relay.on_stomp_message(
bug_create_message["body"], bug_create_message["headers"]
)
self.relay.on_stomp_message(bug_create_message["body"], bug_create_message["headers"])
assert fakepublish.call_count == 1
message = fakepublish.call_args[0][0]
assert message.topic == "bugzilla.bug.new"
Expand All @@ -35,9 +32,7 @@ def test_bug_create(self, fakepublish, bug_create_message):
@mock.patch("bugzilla2fedmsg.relay.publish", autospec=True)
def test_bug_modify(self, fakepublish, bug_modify_message):
"""Check correct result for bug.modify message."""
self.relay.on_stomp_message(
bug_modify_message["body"], bug_modify_message["headers"]
)
self.relay.on_stomp_message(bug_modify_message["body"], bug_modify_message["headers"])
assert fakepublish.call_count == 1
message = fakepublish.call_args[0][0]
assert message.topic == "bugzilla.bug.update"
Expand Down Expand Up @@ -128,9 +123,7 @@ def test_other_product_drop(self, fakepublish, other_product_message):
config, the products we care about are the defaults: 'Fedora'
and 'Fedora EPEL'.
"""
self.relay.on_stomp_message(
other_product_message["body"], other_product_message["headers"]
)
self.relay.on_stomp_message(other_product_message["body"], other_product_message["headers"])
assert fakepublish.call_count == 0

@mock.patch("bugzilla2fedmsg.relay.publish", autospec=True)
Expand All @@ -142,9 +135,7 @@ def test_bz4_compat(self, fakepublish, bug_create_message, comment_create_messag
bz4relay = bugzilla2fedmsg.relay.MessageRelay(
{"bugzilla": {"products": ["Fedora", "Fedora EPEL"], "bz4compat": True}}
)
bz4relay.on_stomp_message(
bug_create_message["body"], bug_create_message["headers"]
)
bz4relay.on_stomp_message(bug_create_message["body"], bug_create_message["headers"])
assert fakepublish.call_count == 1
message = fakepublish.call_args[0][0]
assert message.body["bug"]["assigned_to"] == "[email protected]"
Expand All @@ -155,8 +146,7 @@ def test_bz4_compat(self, fakepublish, bug_create_message, comment_create_messag
assert message.body["bug"]["op_sys"] == "Unspecified"
assert message.body["event"]["who"] == "[email protected]"
assert (
message.body["bug"]["weburl"]
== "https://bugzilla.redhat.com/show_bug.cgi?id=1701391"
message.body["bug"]["weburl"] == "https://bugzilla.redhat.com/show_bug.cgi?id=1701391"
)
# we need a comment message to test this
fakepublish.reset_mock()
Expand All @@ -168,9 +158,7 @@ def test_bz4_compat(self, fakepublish, bug_create_message, comment_create_messag
assert message.body["comment"]["author"] == "[email protected]"

@mock.patch("bugzilla2fedmsg.relay.publish", autospec=True)
def test_bz4_compat_disabled(
self, fakepublish, bug_create_message, comment_create_message
):
def test_bz4_compat_disabled(self, fakepublish, bug_create_message, comment_create_message):
"""Test that we *don't* make Bugzilla 4 compat modifications
if the option is switched off. Tests only the destructive ones
as they're the ones we really want to avoid, and if these
Expand All @@ -179,49 +167,36 @@ def test_bz4_compat_disabled(
nobz4relay = bugzilla2fedmsg.relay.MessageRelay(
{"bugzilla": {"products": ["Fedora", "Fedora EPEL"], "bz4compat": False}}
)
nobz4relay.on_stomp_message(
bug_create_message["body"], bug_create_message["headers"]
)
nobz4relay.on_stomp_message(bug_create_message["body"], bug_create_message["headers"])
assert fakepublish.call_count == 1
message = fakepublish.call_args[0][0]
assert all(
item in message.body["bug"]["assigned_to"]
for item in ("login", "id", "real_name")
item in message.body["bug"]["assigned_to"] for item in ("login", "id", "real_name")
)
assert all(item in message.body["bug"]["component"] for item in ("id", "name"))
assert all(item in message.body["bug"]["product"] for item in ("id", "name"))

@mock.patch("bugzilla2fedmsg.relay.publish", autospec=True)
def test_publish_exception_publishreturned(
self, fakepublish, bug_create_message, caplog
):
def test_publish_exception_publishreturned(self, fakepublish, bug_create_message, caplog):
"""Check that we handle PublishReturned exception from publish
correctly.
"""
fakepublish.side_effect = fedora_messaging.exceptions.PublishReturned("oops!")
# this should not raise any exception
self.relay.on_stomp_message(
bug_create_message["body"], bug_create_message["headers"]
)
self.relay.on_stomp_message(bug_create_message["body"], bug_create_message["headers"])
assert fakepublish.call_count == 1
# check the logging worked
assert "Fedora Messaging broker rejected message" in caplog.text

@mock.patch("bugzilla2fedmsg.relay.publish", autospec=True)
def test_publish_exception_connectionexception(
self, fakepublish, bug_create_message, caplog
):
def test_publish_exception_connectionexception(self, fakepublish, bug_create_message, caplog):
"""Check that we handle ConnectionException from publish
correctly.
"""
# First test PublishReturned
fakepublish.side_effect = fedora_messaging.exceptions.ConnectionException(
"oops!"
)
fakepublish.side_effect = fedora_messaging.exceptions.ConnectionException("oops!")
# this should not raise any exception
self.relay.on_stomp_message(
bug_create_message["body"], bug_create_message["headers"]
)
self.relay.on_stomp_message(bug_create_message["body"], bug_create_message["headers"])
assert fakepublish.call_count == 1
# check the logging worked
assert "Error sending message" in caplog.text
Loading

0 comments on commit b6f5c0c

Please sign in to comment.