|
12 | 12 | from jbi.app import app
|
13 | 13 | from jbi.configuration import get_actions
|
14 | 14 | from jbi.environment import Settings
|
15 |
| -from jbi.models import ( |
16 |
| - Action, |
17 |
| - ActionContext, |
18 |
| - Actions, |
19 |
| - BugzillaWebhookComment, |
20 |
| - BugzillaWebhookRequest, |
21 |
| -) |
| 15 | +from jbi.models import ActionContext, BugzillaWebhookComment, BugzillaWebhookRequest |
22 | 16 | from jbi.services import bugzilla, jira
|
23 |
| -from tests.fixtures import factories |
| 17 | +from tests.fixtures.factories import * |
24 | 18 |
|
25 | 19 |
|
26 | 20 | class FilteredLogCaptureFixture(pytest.LogCaptureFixture):
|
@@ -107,160 +101,43 @@ def mocked_responses():
|
107 | 101 |
|
108 | 102 |
|
109 | 103 | @pytest.fixture
|
110 |
| -def context_create_example() -> ActionContext: |
111 |
| - return factories.action_context_factory( |
| 104 | +def context_create_example(action_context_factory) -> ActionContext: |
| 105 | + return action_context_factory( |
112 | 106 | operation=Operation.CREATE,
|
113 | 107 | )
|
114 | 108 |
|
115 | 109 |
|
116 | 110 | @pytest.fixture
|
117 |
| -def context_update_example() -> ActionContext: |
118 |
| - bug = factories.bug_factory( |
119 |
| - see_also=["https://mozilla.atlassian.net/browse/JBI-234"] |
120 |
| - ) |
121 |
| - context = factories.action_context_factory( |
122 |
| - operation=Operation.UPDATE, |
123 |
| - bug=bug, |
124 |
| - jira=factories.jira_context_factory(issue=bug.extract_from_see_also()), |
125 |
| - ) |
126 |
| - return context |
127 |
| - |
128 |
| - |
129 |
| -@pytest.fixture |
130 |
| -def context_update_status_assignee() -> ActionContext: |
131 |
| - bug = factories.bug_factory( |
132 |
| - see_also=["https://mozilla.atlassian.net/browse/JBI-234"] |
133 |
| - ) |
134 |
| - changes = [ |
135 |
| - { |
136 |
| - "field": "status", |
137 |
| - "removed": "OPEN", |
138 |
| - "added": "FIXED", |
139 |
| - }, |
140 |
| - { |
141 |
| - "field": "assignee", |
142 |
| - |
143 |
| - |
144 |
| - }, |
145 |
| - ] |
146 |
| - event = factories.webhook_event_factory(routing_key="bug.modify", changes=changes) |
147 |
| - context = factories.action_context_factory( |
148 |
| - operation=Operation.UPDATE, |
149 |
| - bug=bug, |
150 |
| - event=event, |
151 |
| - jira=factories.jira_context_factory(issue=bug.extract_from_see_also()), |
152 |
| - ) |
153 |
| - return context |
154 |
| - |
155 |
| - |
156 |
| -@pytest.fixture |
157 |
| -def context_comment_example() -> ActionContext: |
158 |
| - user = factories. webhook_user_factory( login="[email protected]") |
| 111 | +def context_comment_example( |
| 112 | + webhook_user_factory, |
| 113 | + bug_factory, |
| 114 | + webhook_event_factory, |
| 115 | + action_context_factory, |
| 116 | + jira_context_factory, |
| 117 | +) -> ActionContext: |
| 118 | + user = webhook_user_factory( login="[email protected]") |
159 | 119 | comment = BugzillaWebhookComment.parse_obj({"number": 2, "body": "hello"})
|
160 |
| - bug = factories.bug_factory( |
| 120 | + bug = bug_factory( |
161 | 121 | see_also=["https://mozilla.atlassian.net/browse/JBI-234"],
|
162 | 122 | comment=comment,
|
163 | 123 | )
|
164 |
| - event = factories.webhook_event_factory(target="comment", user=user) |
165 |
| - context = factories.action_context_factory( |
| 124 | + event = webhook_event_factory(target="comment", user=user) |
| 125 | + context = action_context_factory( |
166 | 126 | operation=Operation.COMMENT,
|
167 | 127 | bug=bug,
|
168 | 128 | event=event,
|
169 |
| - jira=factories.jira_context_factory(issue=bug.extract_from_see_also()), |
170 |
| - ) |
171 |
| - return context |
172 |
| - |
173 |
| - |
174 |
| -@pytest.fixture |
175 |
| -def context_update_resolution_example() -> ActionContext: |
176 |
| - bug = factories.bug_factory( |
177 |
| - see_also=["https://mozilla.atlassian.net/browse/JBI-234"] |
178 |
| - ) |
179 |
| - event = factories.webhook_event_factory( |
180 |
| - action="modify", |
181 |
| - changes=[ |
182 |
| - factories.webhook_event_change_factory( |
183 |
| - field="resolution", removed="OPEN", added="FIXED" |
184 |
| - ), |
185 |
| - ], |
186 |
| - ) |
187 |
| - context = factories.action_context_factory( |
188 |
| - operation=Operation.UPDATE, |
189 |
| - bug=bug, |
190 |
| - event=event, |
191 |
| - jira=factories.jira_context_factory(issue=bug.extract_from_see_also()), |
| 129 | + jira=jira_context_factory(issue=bug.extract_from_see_also()), |
192 | 130 | )
|
193 | 131 | return context
|
194 | 132 |
|
195 | 133 |
|
196 | 134 | @pytest.fixture
|
197 |
| -def webhook_create_example() -> BugzillaWebhookRequest: |
198 |
| - webhook_payload = factories.webhook_factory() |
| 135 | +def webhook_create_example(webhook_factory) -> BugzillaWebhookRequest: |
| 136 | + webhook_payload = webhook_factory() |
199 | 137 |
|
200 | 138 | return webhook_payload
|
201 | 139 |
|
202 | 140 |
|
203 |
| -@pytest.fixture |
204 |
| -def webhook_comment_example() -> BugzillaWebhookRequest: |
205 |
| - user = factories. webhook_user_factory( login="[email protected]") |
206 |
| - comment = BugzillaWebhookComment.parse_obj({"number": 2, "body": "hello"}) |
207 |
| - bug = factories.bug_factory( |
208 |
| - see_also=["https://mozilla.atlassian.net/browse/JBI-234"], |
209 |
| - comment=comment, |
210 |
| - ) |
211 |
| - event = factories.webhook_event_factory(target="comment", user=user) |
212 |
| - webhook_payload = factories.webhook_factory(bug=bug, event=event) |
213 |
| - |
214 |
| - return webhook_payload |
215 |
| - |
216 |
| - |
217 |
| -@pytest.fixture |
218 |
| -def webhook_private_comment_example() -> BugzillaWebhookRequest: |
219 |
| - user = factories. webhook_user_factory( login="[email protected]") |
220 |
| - event = factories.webhook_event_factory(target="comment", user=user) |
221 |
| - bug = factories.bug_factory( |
222 |
| - comment={"id": 344, "number": 2, "is_private": True}, |
223 |
| - see_also=["https://mozilla.atlassian.net/browse/JBI-234"], |
224 |
| - ) |
225 |
| - webhook_payload = factories.webhook_factory(bug=bug, event=event) |
226 |
| - return webhook_payload |
227 |
| - |
228 |
| - |
229 |
| -@pytest.fixture |
230 |
| -def webhook_change_status_assignee(): |
231 |
| - changes = [ |
232 |
| - factories.webhook_event_change_factory( |
233 |
| - field="status", removed="OPEN", added="FIXED" |
234 |
| - ), |
235 |
| - factories.webhook_event_change_factory( |
236 |
| - field="assignee", removed="[email protected]", added="[email protected]" |
237 |
| - ), |
238 |
| - ] |
239 |
| - event = factories.webhook_event_factory(routing_key="bug.modify", changes=changes) |
240 |
| - webhook_payload = factories.webhook_factory(event=event) |
241 |
| - return webhook_payload |
242 |
| - |
243 |
| - |
244 |
| -@pytest.fixture |
245 |
| -def action_params_factory(): |
246 |
| - return factories.action_params_factory |
247 |
| - |
248 |
| - |
249 |
| -@pytest.fixture |
250 |
| -def action_factory(): |
251 |
| - return factories.action_factory |
252 |
| - |
253 |
| - |
254 |
| -@pytest.fixture |
255 |
| -def action_example() -> Action: |
256 |
| - return factories.action_factory() |
257 |
| - |
258 |
| - |
259 |
| -@pytest.fixture |
260 |
| -def actions_example(action_example) -> Actions: |
261 |
| - return Actions.parse_obj([action_example]) |
262 |
| - |
263 |
| - |
264 | 141 | @pytest.fixture(autouse=True)
|
265 | 142 | def sleepless(monkeypatch):
|
266 | 143 | # https://stackoverflow.com/a/54829577
|
|
0 commit comments