11import pydantic
22import pytest
33
4+ from jbi .errors import ActionNotFoundError
45from 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] " ]) 1416def 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
1921def 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+ ]
0 commit comments