Skip to content

Commit a8f7d51

Browse files
authored
Small changes as follow-up of #591 (#601)
* Move bugzilla model tests to test_models * Delete module docstring and pylint ignore in `test_runner.py` - if pylint can't enumerate test fixtures, that itself is a clue that something is wrong - The organization of the test directory mirrors that application code directory, so it's evident what this module tests * Update acceptance date of ADR
1 parent 883bba6 commit a8f7d51

File tree

4 files changed

+85
-93
lines changed

4 files changed

+85
-93
lines changed

docs/adrs/002-action-customizaiton.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Restrict Workflow Customization and Validate Default Action Parameters
22

33
- Status: Accepted
4-
- Date: 2023-06-23
4+
- Date: 2023-06-27
55

66
Tracking issue: [#544](https://github.com/mozilla/jira-bugzilla-integration/issues/544)
77

tests/unit/test_bugzilla.py

Lines changed: 0 additions & 86 deletions
This file was deleted.

tests/unit/test_models.py

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import pydantic
22
import pytest
33

4+
from jbi.errors import ActionNotFoundError
45
from jbi.models import ActionParams, Actions, ActionSteps
6+
from tests.fixtures.factories import bug_factory
57

68

79
@pytest.mark.parametrize("value", [123456, [123456], [12345, 67890], "tbd"])
@@ -13,7 +15,7 @@ def test_valid_bugzilla_user_ids(action_factory, value):
1315
@pytest.mark.parametrize("value", [None, "[email protected]"])
1416
def test_invalid_bugzilla_user_ids(action_factory, value):
1517
with pytest.raises(pydantic.ValidationError):
16-
action = action_factory(bugzilla_user_id=value)
18+
action_factory(bugzilla_user_id=value)
1719

1820

1921
def test_no_actions_fails():
@@ -43,3 +45,84 @@ def test_override_step_configuration_for_single_action_type():
4345
assert params.steps.new != default_steps.new
4446
assert params.steps.existing == default_steps.existing
4547
assert params.steps.comment == default_steps.comment
48+
49+
50+
@pytest.mark.parametrize(
51+
"see_also,expected",
52+
[
53+
(None, None),
54+
([], None),
55+
(["foo"], None),
56+
(["fail:/format"], None),
57+
(["foo", "http://jira.net/123"], "123"),
58+
(["http://org/123"], None),
59+
(["http://jira.com"], None),
60+
(["http://mozilla.jira.com/"], None),
61+
(["http://mozilla.jira.com/123"], "123"),
62+
(["http://mozilla.jira.com/123/"], "123"),
63+
(["http://mozilla.jira.com/ticket/123"], "123"),
64+
(["http://atlassian.com/ticket/123"], "123"),
65+
(["http://mozilla.jira.com/123", "http://mozilla.jira.com/456"], "123"),
66+
],
67+
)
68+
def test_extract_see_also(see_also, expected):
69+
bug = bug_factory(see_also=see_also)
70+
assert bug.extract_from_see_also() == expected
71+
72+
73+
@pytest.mark.parametrize(
74+
"whiteboard",
75+
[
76+
"[DevTest-]",
77+
"[-DevTest-]",
78+
"[-DevTest]",
79+
"[DevTest-test]",
80+
"[test-DevTest]",
81+
"[foo-DevTest-bar]",
82+
"[foo-bar-DevTest-foo-bar]",
83+
"[example][DevTest]",
84+
"[DevTest][example]",
85+
"[example][DevTest][example]",
86+
],
87+
)
88+
def test_lookup_action_found(whiteboard, actions_example):
89+
bug = bug_factory(id=1234, whiteboard=whiteboard)
90+
action = bug.lookup_action(actions_example)
91+
assert action.whiteboard_tag == "devtest"
92+
assert "test config" in action.description
93+
94+
95+
@pytest.mark.parametrize(
96+
"whiteboard",
97+
[
98+
"DevTest",
99+
"foo DevTest",
100+
"DevTest bar",
101+
"foo DevTest bar",
102+
"[fooDevTest]",
103+
"[foo DevTest]",
104+
"[DevTestbar]",
105+
"[DevTest bar]",
106+
"[fooDevTestbar]",
107+
"[fooDevTest-bar]",
108+
"[foo-DevTestbar]",
109+
"[foo] devtest [bar]",
110+
],
111+
)
112+
def test_lookup_action_not_found(whiteboard, actions_example):
113+
bug = bug_factory(id=1234, whiteboard=whiteboard)
114+
with pytest.raises(ActionNotFoundError) as exc_info:
115+
bug.lookup_action(actions_example)
116+
assert str(exc_info.value) == "devtest"
117+
118+
119+
def test_payload_empty_changes_list(webhook_change_status_assignee):
120+
webhook_change_status_assignee.event.changes = None
121+
assert webhook_change_status_assignee.event.changed_fields() == []
122+
123+
124+
def test_payload_changes_list(webhook_change_status_assignee):
125+
assert webhook_change_status_assignee.event.changed_fields() == [
126+
"status",
127+
"assignee",
128+
]

tests/unit/test_runner.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
"""
2-
Module for testing jbi/runner.py
3-
"""
41
import logging
5-
6-
# pylint: disable=cannot-enumerate-pytest-fixtures
72
from unittest import mock
83

94
import pytest

0 commit comments

Comments
 (0)