16
16
from tests .fixtures .factories import bug_factory
17
17
18
18
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
+
19
43
def test_request_is_ignored_because_private (
20
44
webhook_create_private_example : BugzillaWebhookRequest ,
21
45
actions_example : Actions ,
@@ -59,8 +83,10 @@ def test_added_comment_without_linked_issue_is_ignored(
59
83
webhook_comment_example : BugzillaWebhookRequest ,
60
84
actions_example : Actions ,
61
85
settings : Settings ,
86
+ mocked_bugzilla ,
62
87
):
63
88
webhook_comment_example .bug .see_also = []
89
+ mocked_bugzilla .get_bug .return_value = webhook_comment_example .bug
64
90
65
91
with pytest .raises (IgnoreInvalidRequestError ) as exc_info :
66
92
execute_action (
@@ -75,9 +101,11 @@ def test_request_is_ignored_because_no_action(
75
101
webhook_create_example : BugzillaWebhookRequest ,
76
102
actions_example : Actions ,
77
103
settings : Settings ,
104
+ mocked_bugzilla ,
78
105
):
79
106
assert webhook_create_example .bug
80
107
webhook_create_example .bug .whiteboard = "bar"
108
+ mocked_bugzilla .get_bug .return_value = webhook_create_example .bug
81
109
82
110
with pytest .raises (IgnoreInvalidRequestError ) as exc_info :
83
111
execute_action (
@@ -93,7 +121,10 @@ def test_execution_logging_for_successful_requests(
93
121
webhook_create_example : BugzillaWebhookRequest ,
94
122
actions_example : Actions ,
95
123
settings : Settings ,
124
+ mocked_bugzilla ,
96
125
):
126
+ mocked_bugzilla .get_bug .return_value = webhook_create_example .bug
127
+
97
128
with caplog .at_level (logging .DEBUG ):
98
129
execute_action (
99
130
request = webhook_create_example ,
@@ -117,9 +148,12 @@ def test_execution_logging_for_ignored_requests(
117
148
webhook_create_example : BugzillaWebhookRequest ,
118
149
actions_example : Actions ,
119
150
settings : Settings ,
151
+ mocked_bugzilla ,
120
152
):
121
153
assert webhook_create_example .bug
122
154
webhook_create_example .bug .whiteboard = "foo"
155
+ mocked_bugzilla .get_bug .return_value = webhook_create_example .bug
156
+
123
157
with caplog .at_level (logging .DEBUG ):
124
158
with pytest .raises (IgnoreInvalidRequestError ):
125
159
execute_action (
@@ -143,7 +177,10 @@ def test_action_is_logged_as_success_if_returns_true(
143
177
webhook_create_example : BugzillaWebhookRequest ,
144
178
actions_example : Actions ,
145
179
settings : Settings ,
180
+ mocked_bugzilla ,
146
181
):
182
+ mocked_bugzilla .get_bug .return_value = webhook_create_example .bug
183
+
147
184
with mock .patch ("jbi.models.Action.caller" ) as mocked :
148
185
mocked .return_value = True , {}
149
186
@@ -175,7 +212,10 @@ def test_action_is_logged_as_ignore_if_returns_false(
175
212
webhook_create_example : BugzillaWebhookRequest ,
176
213
actions_example : Actions ,
177
214
settings : Settings ,
215
+ mocked_bugzilla ,
178
216
):
217
+ mocked_bugzilla .get_bug .return_value = webhook_create_example .bug
218
+
179
219
with mock .patch ("jbi.models.Action.caller" ) as mocked :
180
220
mocked .return_value = False , {}
181
221
@@ -204,9 +244,11 @@ def test_counter_is_incremented_on_ignored_requests(
204
244
webhook_create_example : BugzillaWebhookRequest ,
205
245
actions_example : Actions ,
206
246
settings : Settings ,
247
+ mocked_bugzilla ,
207
248
):
208
249
assert webhook_create_example .bug
209
250
webhook_create_example .bug .whiteboard = "foo"
251
+ mocked_bugzilla .get_bug .return_value = webhook_create_example .bug
210
252
211
253
with mock .patch ("jbi.runner.statsd" ) as mocked :
212
254
with pytest .raises (IgnoreInvalidRequestError ):
@@ -222,38 +264,14 @@ def test_counter_is_incremented_on_processed_requests(
222
264
webhook_create_example : BugzillaWebhookRequest ,
223
265
actions_example : Actions ,
224
266
settings : Settings ,
267
+ mocked_bugzilla ,
225
268
):
269
+ mocked_bugzilla .get_bug .return_value = webhook_create_example .bug
270
+
226
271
with mock .patch ("jbi.runner.statsd" ) as mocked :
227
272
execute_action (
228
273
request = webhook_create_example ,
229
274
actions = actions_example ,
230
275
settings = settings ,
231
276
)
232
277
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