|
7 | 7 | import pytest
|
8 | 8 | import responses
|
9 | 9 | from fastapi.testclient import TestClient
|
| 10 | +from pytest_factoryboy import register |
10 | 11 |
|
11 | 12 | from jbi import Operation
|
12 | 13 | from jbi.app import app
|
13 | 14 | from jbi.configuration import get_actions
|
14 | 15 | from jbi.environment import Settings
|
15 |
| -from jbi.models import ActionContext, BugzillaWebhookComment, BugzillaWebhookRequest |
| 16 | +from jbi.models import ActionContext, BugzillaWebhookRequest |
16 | 17 | from jbi.services import bugzilla, jira
|
17 | 18 | from tests.fixtures.factories import *
|
18 | 19 |
|
@@ -54,6 +55,20 @@ def mocked_statsd():
|
54 | 55 | yield _mocked_statsd
|
55 | 56 |
|
56 | 57 |
|
| 58 | +register(ActionContextFactory) |
| 59 | +register(ActionFactory) |
| 60 | +register(ActionsFactory) |
| 61 | +register(ActionParamsFactory) |
| 62 | +register(BugFactory) |
| 63 | +register(BugzillaWebhookFactory) |
| 64 | +register(CommentFactory) |
| 65 | +register(JiraContextFactory) |
| 66 | +register(WebhookFactory) |
| 67 | +register(WebhookEventChangeFactory) |
| 68 | +register(WebhookEventFactory) |
| 69 | +register(WebhookUserFactory) |
| 70 | + |
| 71 | + |
57 | 72 | @pytest.fixture
|
58 | 73 | def anon_client():
|
59 | 74 | """A test client with no authorization."""
|
@@ -100,42 +115,24 @@ def mocked_responses():
|
100 | 115 | yield rsps
|
101 | 116 |
|
102 | 117 |
|
103 |
| -@pytest.fixture |
104 |
| -def context_create_example(action_context_factory) -> ActionContext: |
105 |
| - return action_context_factory( |
106 |
| - operation=Operation.CREATE, |
107 |
| - ) |
| 118 | +register(ActionContextFactory, "context_create_example", operation=Operation.CREATE) |
108 | 119 |
|
109 | 120 |
|
110 | 121 | @pytest.fixture
|
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]") |
119 |
| - comment = BugzillaWebhookComment.parse_obj({"number": 2, "body": "hello"}) |
120 |
| - bug = bug_factory( |
121 |
| - see_also=["https://mozilla.atlassian.net/browse/JBI-234"], |
122 |
| - comment=comment, |
123 |
| - ) |
124 |
| - event = webhook_event_factory(target="comment", user=user) |
125 |
| - context = action_context_factory( |
| 122 | +def context_comment_example(action_context_factory) -> ActionContext: |
| 123 | + return action_context_factory( |
126 | 124 | operation=Operation.COMMENT,
|
127 |
| - bug=bug, |
128 |
| - event=event, |
129 |
| - jira=jira_context_factory(issue=bug.extract_from_see_also()), |
| 125 | + bug__see_also=["https://mozilla.atlassian.net/browse/JBI-234"], |
| 126 | + bug__with_comment=True, |
| 127 | + bug__comment__number=2, |
| 128 | + bug__comment__body="hello", |
| 129 | + event__target="comment", |
| 130 | + event__user__login="[email protected]", |
| 131 | + jira__issue="JBI-234", |
130 | 132 | )
|
131 |
| - return context |
132 | 133 |
|
133 | 134 |
|
134 |
| -@pytest.fixture |
135 |
| -def webhook_create_example(webhook_factory) -> BugzillaWebhookRequest: |
136 |
| - webhook_payload = webhook_factory() |
137 |
| - |
138 |
| - return webhook_payload |
| 135 | +register(WebhookFactory, "webhook_create_example") |
139 | 136 |
|
140 | 137 |
|
141 | 138 | @pytest.fixture(autouse=True)
|
|
0 commit comments