diff --git a/jbi/bugzilla/service.py b/jbi/bugzilla/service.py index 71df001e..8267144a 100644 --- a/jbi/bugzilla/service.py +++ b/jbi/bugzilla/service.py @@ -40,10 +40,15 @@ def refresh_bug_data(self, bug: Bug): """Re-fetch a bug to ensure we have the most up-to-date data""" refreshed_bug_data = self.client.get_bug(bug.id) - # When bugs come in as webhook payloads, they have a "comment" - # attribute, but this field isn't available when we get a bug by ID. - # So, we make sure to add the comment back if it was present on the bug. - updated_bug = refreshed_bug_data.model_copy(update={"comment": bug.comment}) + # When bugs come in as webhook payloads, they have "comment" and "attachment" + # attributes, but these fields aren't available when we get a bug by ID. + # So, we make sure to add them back if they were present on the bug. + updated_bug = refreshed_bug_data.model_copy( + update={ + "comment": bug.comment, + "attachment": bug.attachment, + } + ) return updated_bug def list_webhooks(self): diff --git a/tests/unit/bugzilla/test_service.py b/tests/unit/bugzilla/test_service.py new file mode 100644 index 00000000..e35b7760 --- /dev/null +++ b/tests/unit/bugzilla/test_service.py @@ -0,0 +1,38 @@ +import pytest + +from jbi import bugzilla + + +@pytest.fixture +def bugzilla_client(settings): + return bugzilla.client.BugzillaClient( + base_url=settings.bugzilla_base_url, api_key=settings.bugzilla_api_key + ) + + +@pytest.fixture +def bugzilla_service(bugzilla_client): + return bugzilla.service.BugzillaService(bugzilla_client) + + +def test_refresh_bug_data_keeps_comment_and_attachment( + bugzilla_service, mocked_responses, bug_factory, settings +): + bug = bug_factory(with_attachment=True, with_comment=True) + # https://bugzilla.readthedocs.io/en/latest/api/core/v1/bug.html#get-bug + mocked_responses.add( + "GET", + f"{settings.bugzilla_base_url}/rest/bug/%s" % bug.id, + json={ + "bugs": [ + { + "id": bug.id, + } + ], + }, + ) + + updated = bugzilla_service.refresh_bug_data(bug) + + assert updated.comment == bug.comment + assert updated.attachment == bug.attachment