File tree Expand file tree Collapse file tree 4 files changed +14
-25
lines changed Expand file tree Collapse file tree 4 files changed +14
-25
lines changed Original file line number Diff line number Diff line change @@ -326,7 +326,7 @@ class Config:
326
326
webhook_id : int
327
327
webhook_name : str
328
328
event : BugzillaWebhookEvent
329
- bug : Optional [ BugzillaBug ]
329
+ bug : BugzillaBug
330
330
331
331
def map_as_jira_comment (self ):
332
332
"""Extract comment from Webhook Event"""
@@ -388,8 +388,6 @@ def getbug_as_bugzilla_object(self) -> BugzillaBug:
388
388
@functools .cached_property
389
389
def bugzilla_object (self ) -> BugzillaBug :
390
390
"""Returns the bugzilla bug object, querying the API as needed for private bugs"""
391
- if not self .bug :
392
- raise ValueError ("missing bug reference" )
393
391
if not self .bug .is_private :
394
392
return self .bug
395
393
return self .getbug_as_bugzilla_object ()
Original file line number Diff line number Diff line change @@ -27,19 +27,15 @@ def execute_action(
27
27
The value returned by the action call is returned.
28
28
"""
29
29
log_context = RunnerLogContext (
30
- bug = {
31
- "id" : request .bug .id if request .bug else None ,
32
- },
33
- request = request ,
30
+ bug = request .bug .dict (),
31
+ request = request .dict (),
34
32
operation = Operation .HANDLE ,
35
33
)
36
34
try :
37
35
logger .debug (
38
36
"Handling incoming request" ,
39
37
extra = log_context .dict (),
40
38
)
41
- if not request .bug :
42
- raise IgnoreInvalidRequestError ("no bug data received" )
43
39
44
40
try :
45
41
bug_obj : BugzillaBug = request .bugzilla_object
Original file line number Diff line number Diff line change @@ -111,6 +111,17 @@ def test_webhook_is_200_if_action_raises_IgnoreInvalidRequestError(
111
111
)
112
112
113
113
114
+ def test_webhook_is_422_if_bug_information_missing (webhook_create_example ):
115
+ webhook_create_example .bug = None
116
+
117
+ with TestClient (app ) as anon_client :
118
+ response = anon_client .post (
119
+ "/bugzilla_webhook" , data = webhook_create_example .json ()
120
+ )
121
+ assert response .status_code == 422
122
+ assert response .json ()["detail" ][0 ]["msg" ] == "none is not an allowed value"
123
+
124
+
114
125
def test_read_version (anon_client ):
115
126
"""__version__ returns the contents of version.json."""
116
127
here = os .path .dirname (__file__ )
Original file line number Diff line number Diff line change @@ -56,22 +56,6 @@ def test_private_request_is_allowed(
56
56
assert payload .bug .id == 654321
57
57
58
58
59
- def test_request_is_ignored_because_no_bug (
60
- webhook_create_example : BugzillaWebhookRequest ,
61
- actions_example : Actions ,
62
- settings : Settings ,
63
- ):
64
- webhook_create_example .bug = None
65
-
66
- with pytest .raises (IgnoreInvalidRequestError ) as exc_info :
67
- execute_action (
68
- request = webhook_create_example ,
69
- actions = actions_example ,
70
- settings = settings ,
71
- )
72
- assert str (exc_info .value ) == "no bug data received"
73
-
74
-
75
59
def test_request_is_ignored_because_no_action (
76
60
webhook_create_example : BugzillaWebhookRequest ,
77
61
actions_example : Actions ,
You can’t perform that action at this time.
0 commit comments