5
5
import requests
6
6
import responses
7
7
8
+ import tests .fixtures .factories as factories
8
9
from jbi import Operation
9
10
from jbi .bugzilla .client import BugNotAccessibleError
10
11
from jbi .environment import get_settings
15
16
Executor ,
16
17
execute_action ,
17
18
execute_or_queue ,
18
- lookup_action ,
19
+ lookup_actions ,
19
20
)
20
21
21
22
@@ -187,7 +188,7 @@ def test_action_is_logged_as_success_if_returns_true(
187
188
("Action 'devtest' executed successfully for Bug 654321" , Operation .SUCCESS ),
188
189
]
189
190
assert capturelogs .records [- 1 ].bug ["id" ] == 654321
190
- assert capturelogs .records [- 1 ].action ["whiteboard_tag" ] == "devtest"
191
+ assert capturelogs .records [- 1 ].actions [ 0 ] ["whiteboard_tag" ] == "devtest"
191
192
192
193
193
194
def test_action_is_logged_as_ignore_if_returns_false (
@@ -619,11 +620,42 @@ def test_counter_is_incremented_for_attachment(
619
620
)
620
621
def test_lookup_action_found (whiteboard , actions , bug_factory ):
621
622
bug = bug_factory (id = 1234 , whiteboard = whiteboard )
622
- action = lookup_action (bug , actions )
623
+ action = lookup_actions (bug , actions )[ 0 ]
623
624
assert action .whiteboard_tag == "devtest"
624
625
assert "test config" in action .description
625
626
626
627
628
+ @pytest .mark .parametrize (
629
+ "whiteboard,expected_tags" ,
630
+ [
631
+ ("[example][DevTest]" , ["devtest" ]),
632
+ ("[DevTest][example]" , ["devtest" ]),
633
+ ("[example][DevTest][other]" , ["devtest" , "other" ]),
634
+ ],
635
+ )
636
+ def test_multiple_lookup_actions_found (whiteboard , expected_tags , bug_factory ):
637
+ actions = factories .ActionsFactory (
638
+ root = [
639
+ factories .ActionFactory (
640
+ whiteboard_tag = "devtest" ,
641
+ bugzilla_user_id = "tbd" ,
642
+ description = "test config" ,
643
+ ),
644
+ factories .ActionFactory (
645
+ whiteboard_tag = "other" ,
646
+ bugzilla_user_id = "tbd" ,
647
+ description = "test config" ,
648
+ ),
649
+ ]
650
+ )
651
+ bug = bug_factory (id = 1234 , whiteboard = whiteboard )
652
+ acts = lookup_actions (bug , actions )
653
+ assert len (acts ) == len (expected_tags )
654
+ looked_up_tags = [a .whiteboard_tag for a in acts ]
655
+ assert sorted (looked_up_tags ) == sorted (expected_tags )
656
+ assert all (["test config" == a .description for a in acts ])
657
+
658
+
627
659
@pytest .mark .parametrize (
628
660
"whiteboard" ,
629
661
[
@@ -649,5 +681,87 @@ def test_lookup_action_found(whiteboard, actions, bug_factory):
649
681
def test_lookup_action_not_found (whiteboard , actions , bug_factory ):
650
682
bug = bug_factory (id = 1234 , whiteboard = whiteboard )
651
683
with pytest .raises (ActionNotFoundError ) as exc_info :
652
- lookup_action (bug , actions )
684
+ lookup_actions (bug , actions )[ 0 ]
653
685
assert str (exc_info .value ) == "devtest"
686
+
687
+
688
+ def test_request_triggers_multiple_actions (
689
+ webhook_request_factory ,
690
+ mocked_bugzilla ,
691
+ ):
692
+ actions = factories .ActionsFactory (
693
+ root = [
694
+ factories .ActionFactory (
695
+ whiteboard_tag = "devtest" ,
696
+ bugzilla_user_id = "tbd" ,
697
+ description = "test config" ,
698
+ ),
699
+ factories .ActionFactory (
700
+ whiteboard_tag = "other" ,
701
+ bugzilla_user_id = "tbd" ,
702
+ description = "test config" ,
703
+ ),
704
+ ]
705
+ )
706
+
707
+ webhook = webhook_request_factory (bug__whiteboard = "[devtest][other]" )
708
+ mocked_bugzilla .get_bug .return_value = webhook .bug
709
+
710
+ details = execute_action (request = webhook , actions = actions )
711
+
712
+ # Details has the following shape:
713
+ # {'devtest': {'responses': [..]}, 'other': {'responses': [...]}}
714
+ assert len (actions ) == len (details )
715
+ assert "devtest" in details
716
+ assert "other" in details
717
+
718
+
719
+ def test_request_triggers_multiple_update_actions (
720
+ webhook_request_factory ,
721
+ mocked_bugzilla ,
722
+ mocked_jira ,
723
+ ):
724
+ actions = factories .ActionsFactory (
725
+ root = [
726
+ factories .ActionFactory (
727
+ whiteboard_tag = "devtest" ,
728
+ bugzilla_user_id = "tbd" ,
729
+ description = "test config" ,
730
+ parameters__jira_project_key = "JBI" ,
731
+ ),
732
+ factories .ActionFactory (
733
+ whiteboard_tag = "other" ,
734
+ bugzilla_user_id = "tbd" ,
735
+ description = "test config" ,
736
+ parameters__jira_project_key = "DE" ,
737
+ ),
738
+ ]
739
+ )
740
+
741
+ webhook = webhook_request_factory (
742
+ bug__whiteboard = "[devtest][other]" ,
743
+ bug__see_also = [
744
+ "https://mozilla.atlassian.net/browse/JBI-234" ,
745
+ "https://mozilla.atlassian.net/browse/DE-567" ,
746
+ ],
747
+ )
748
+ mocked_bugzilla .get_bug .return_value = webhook .bug
749
+
750
+ def side_effect_for_get_issue (issue_key ):
751
+ if issue_key .startswith ("JBI-" ):
752
+ return {"fields" : {"project" : {"key" : "JBI" }}}
753
+ elif issue_key .startswith ("DE-" ):
754
+ return {"fields" : {"project" : {"key" : "DE" }}}
755
+
756
+ return None
757
+
758
+ mocked_jira .get_issue .side_effect = side_effect_for_get_issue
759
+
760
+ details = execute_action (request = webhook , actions = actions )
761
+
762
+ # Details has the following shape:
763
+ # {'devtest': {'responses': [..]}, 'other': {'responses': [...]}}
764
+ assert len (actions ) == len (details )
765
+ assert "devtest" in details
766
+ assert "other" in details
767
+ print (details )
0 commit comments