Skip to content

Commit 57a7076

Browse files
authored
Fix #292: Always fetch latest bug object from Bugzilla (#293)
1 parent 95c87f9 commit 57a7076

File tree

3 files changed

+48
-29
lines changed

3 files changed

+48
-29
lines changed

jbi/runner.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ def execute_action(
4646
extra=runner_context.dict(),
4747
)
4848
try:
49-
if bug.is_private:
50-
bug = bugzilla.get_client().get_bug(bug.id)
49+
bug = bugzilla.get_client().get_bug(bug.id)
5150
except Exception as err:
5251
logger.exception("Failed to get bug: %s", err, extra=runner_context.dict())
5352
raise IgnoreInvalidRequestError(

tests/unit/test_router.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,11 @@ def test_webhook_is_200_if_action_succeeds(
9898

9999
def test_webhook_is_200_if_action_raises_IgnoreInvalidRequestError(
100100
webhook_create_example: BugzillaWebhookRequest,
101+
mocked_bugzilla,
101102
):
102103
assert webhook_create_example.bug
103104
webhook_create_example.bug.whiteboard = "unmatched"
105+
mocked_bugzilla.get_bug.return_value = webhook_create_example.bug
104106

105107
with TestClient(app) as anon_client:
106108
response = anon_client.post(

tests/unit/test_runner.py

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,30 @@
1616
from tests.fixtures.factories import bug_factory
1717

1818

19+
def test_bugzilla_object_is_always_fetched(
20+
mocked_bugzilla,
21+
webhook_create_example,
22+
actions_example: Actions,
23+
settings: Settings,
24+
):
25+
# See https://github.com/mozilla/jira-bugzilla-integration/issues/292
26+
fetched_bug = bug_factory(
27+
id=webhook_create_example.bug.id,
28+
see_also=["https://mozilla.atlassian.net/browse/JBI-234"],
29+
)
30+
mocked_bugzilla.get_bug.return_value = fetched_bug
31+
32+
# when the runner executes a private bug
33+
execute_action(
34+
request=webhook_create_example,
35+
actions=actions_example,
36+
settings=settings,
37+
)
38+
39+
# then
40+
mocked_bugzilla.get_bug.assert_called_once_with(webhook_create_example.bug.id)
41+
42+
1943
def test_request_is_ignored_because_private(
2044
webhook_create_private_example: BugzillaWebhookRequest,
2145
actions_example: Actions,
@@ -59,8 +83,10 @@ def test_added_comment_without_linked_issue_is_ignored(
5983
webhook_comment_example: BugzillaWebhookRequest,
6084
actions_example: Actions,
6185
settings: Settings,
86+
mocked_bugzilla,
6287
):
6388
webhook_comment_example.bug.see_also = []
89+
mocked_bugzilla.get_bug.return_value = webhook_comment_example.bug
6490

6591
with pytest.raises(IgnoreInvalidRequestError) as exc_info:
6692
execute_action(
@@ -75,9 +101,11 @@ def test_request_is_ignored_because_no_action(
75101
webhook_create_example: BugzillaWebhookRequest,
76102
actions_example: Actions,
77103
settings: Settings,
104+
mocked_bugzilla,
78105
):
79106
assert webhook_create_example.bug
80107
webhook_create_example.bug.whiteboard = "bar"
108+
mocked_bugzilla.get_bug.return_value = webhook_create_example.bug
81109

82110
with pytest.raises(IgnoreInvalidRequestError) as exc_info:
83111
execute_action(
@@ -93,7 +121,10 @@ def test_execution_logging_for_successful_requests(
93121
webhook_create_example: BugzillaWebhookRequest,
94122
actions_example: Actions,
95123
settings: Settings,
124+
mocked_bugzilla,
96125
):
126+
mocked_bugzilla.get_bug.return_value = webhook_create_example.bug
127+
97128
with caplog.at_level(logging.DEBUG):
98129
execute_action(
99130
request=webhook_create_example,
@@ -117,9 +148,12 @@ def test_execution_logging_for_ignored_requests(
117148
webhook_create_example: BugzillaWebhookRequest,
118149
actions_example: Actions,
119150
settings: Settings,
151+
mocked_bugzilla,
120152
):
121153
assert webhook_create_example.bug
122154
webhook_create_example.bug.whiteboard = "foo"
155+
mocked_bugzilla.get_bug.return_value = webhook_create_example.bug
156+
123157
with caplog.at_level(logging.DEBUG):
124158
with pytest.raises(IgnoreInvalidRequestError):
125159
execute_action(
@@ -143,7 +177,10 @@ def test_action_is_logged_as_success_if_returns_true(
143177
webhook_create_example: BugzillaWebhookRequest,
144178
actions_example: Actions,
145179
settings: Settings,
180+
mocked_bugzilla,
146181
):
182+
mocked_bugzilla.get_bug.return_value = webhook_create_example.bug
183+
147184
with mock.patch("jbi.models.Action.caller") as mocked:
148185
mocked.return_value = True, {}
149186

@@ -175,7 +212,10 @@ def test_action_is_logged_as_ignore_if_returns_false(
175212
webhook_create_example: BugzillaWebhookRequest,
176213
actions_example: Actions,
177214
settings: Settings,
215+
mocked_bugzilla,
178216
):
217+
mocked_bugzilla.get_bug.return_value = webhook_create_example.bug
218+
179219
with mock.patch("jbi.models.Action.caller") as mocked:
180220
mocked.return_value = False, {}
181221

@@ -204,9 +244,11 @@ def test_counter_is_incremented_on_ignored_requests(
204244
webhook_create_example: BugzillaWebhookRequest,
205245
actions_example: Actions,
206246
settings: Settings,
247+
mocked_bugzilla,
207248
):
208249
assert webhook_create_example.bug
209250
webhook_create_example.bug.whiteboard = "foo"
251+
mocked_bugzilla.get_bug.return_value = webhook_create_example.bug
210252

211253
with mock.patch("jbi.runner.statsd") as mocked:
212254
with pytest.raises(IgnoreInvalidRequestError):
@@ -222,38 +264,14 @@ def test_counter_is_incremented_on_processed_requests(
222264
webhook_create_example: BugzillaWebhookRequest,
223265
actions_example: Actions,
224266
settings: Settings,
267+
mocked_bugzilla,
225268
):
269+
mocked_bugzilla.get_bug.return_value = webhook_create_example.bug
270+
226271
with mock.patch("jbi.runner.statsd") as mocked:
227272
execute_action(
228273
request=webhook_create_example,
229274
actions=actions_example,
230275
settings=settings,
231276
)
232277
mocked.incr.assert_called_with("jbi.bugzilla.processed.count")
233-
234-
235-
def test_bugzilla_object_is_fetched_when_private(
236-
mocked_bugzilla,
237-
webhook_modify_private_example,
238-
actions_example: Actions,
239-
settings: Settings,
240-
):
241-
fetched_private_bug = bug_factory(
242-
id=webhook_modify_private_example.bug.id,
243-
is_private=webhook_modify_private_example.bug.is_private,
244-
see_also=["https://mozilla.atlassian.net/browse/JBI-234"],
245-
)
246-
mocked_bugzilla.get_bug.return_value = fetched_private_bug
247-
actions_example["devtest"].allow_private = True
248-
249-
# when the runner executes a private bug
250-
execute_action(
251-
request=webhook_modify_private_example,
252-
actions=actions_example,
253-
settings=settings,
254-
)
255-
256-
# then
257-
mocked_bugzilla.get_bug.assert_called_once_with(
258-
webhook_modify_private_example.bug.id
259-
)

0 commit comments

Comments
 (0)