@@ -102,6 +102,27 @@ def test_create_invalid_alert_receive_channel(alert_receive_channel_internal_api
102
102
assert response .status_code == status .HTTP_400_BAD_REQUEST
103
103
104
104
105
+ @pytest .mark .django_db
106
+ def test_create_invalid_alert_receive_channel_type (alert_receive_channel_internal_api_setup , make_user_auth_headers ):
107
+ user , token , _ = alert_receive_channel_internal_api_setup
108
+
109
+ client = APIClient ()
110
+ url = reverse ("api-internal:alert_receive_channel-list" )
111
+
112
+ response_1 = client .post (
113
+ url ,
114
+ data = {"integration" : "random123" , "verbal_name" : "Random 123" },
115
+ format = "json" ,
116
+ ** make_user_auth_headers (user , token ),
117
+ )
118
+ response_2 = client .post (
119
+ url , data = {"verbal_name" : "Random 123" }, format = "json" , ** make_user_auth_headers (user , token )
120
+ )
121
+
122
+ assert response_1 .status_code == status .HTTP_400_BAD_REQUEST
123
+ assert response_2 .status_code == status .HTTP_400_BAD_REQUEST
124
+
125
+
105
126
@pytest .mark .django_db
106
127
def test_update_alert_receive_channel (alert_receive_channel_internal_api_setup , make_user_auth_headers ):
107
128
user , token , alert_receive_channel = alert_receive_channel_internal_api_setup
@@ -693,6 +714,74 @@ def test_get_alert_receive_channels_direct_paging_present_for_filters(
693
714
assert response .json ()["results" ][0 ]["value" ] == alert_receive_channel .public_primary_key
694
715
695
716
717
+ @pytest .mark .django_db
718
+ def test_create_alert_receive_channels_direct_paging (
719
+ make_organization_and_user_with_plugin_token , make_team , make_alert_receive_channel , make_user_auth_headers
720
+ ):
721
+ organization , user , token = make_organization_and_user_with_plugin_token ()
722
+ team = make_team (organization )
723
+
724
+ client = APIClient ()
725
+ url = reverse ("api-internal:alert_receive_channel-list" )
726
+
727
+ response_1 = client .post (
728
+ url , data = {"integration" : "direct_paging" }, format = "json" , ** make_user_auth_headers (user , token )
729
+ )
730
+ response_2 = client .post (
731
+ url , data = {"integration" : "direct_paging" }, format = "json" , ** make_user_auth_headers (user , token )
732
+ )
733
+
734
+ response_3 = client .post (
735
+ url ,
736
+ data = {"integration" : "direct_paging" , "team" : team .public_primary_key },
737
+ format = "json" ,
738
+ ** make_user_auth_headers (user , token ),
739
+ )
740
+ response_4 = client .post (
741
+ url ,
742
+ data = {"integration" : "direct_paging" , "team" : team .public_primary_key },
743
+ format = "json" ,
744
+ ** make_user_auth_headers (user , token ),
745
+ )
746
+
747
+ # Check direct paging integration for "No team" is created
748
+ assert response_1 .status_code == status .HTTP_201_CREATED
749
+ # Check direct paging integration is not created, as it already exists for "No team"
750
+ assert response_2 .status_code == status .HTTP_400_BAD_REQUEST
751
+
752
+ # Check direct paging integration for team is created
753
+ assert response_3 .status_code == status .HTTP_201_CREATED
754
+ # Check direct paging integration is not created, as it already exists for team
755
+ assert response_4 .status_code == status .HTTP_400_BAD_REQUEST
756
+ assert response_4 .json ()["detail" ] == AlertReceiveChannel .DuplicateDirectPagingError .DETAIL
757
+
758
+
759
+ @pytest .mark .django_db
760
+ def test_update_alert_receive_channels_direct_paging (
761
+ make_organization_and_user_with_plugin_token , make_team , make_alert_receive_channel , make_user_auth_headers
762
+ ):
763
+ organization , user , token = make_organization_and_user_with_plugin_token ()
764
+ team = make_team (organization )
765
+ integration = make_alert_receive_channel (
766
+ organization , integration = AlertReceiveChannel .INTEGRATION_DIRECT_PAGING , team = None
767
+ )
768
+ make_alert_receive_channel (organization , integration = AlertReceiveChannel .INTEGRATION_DIRECT_PAGING , team = team )
769
+
770
+ client = APIClient ()
771
+ url = reverse ("api-internal:alert_receive_channel-detail" , kwargs = {"pk" : integration .public_primary_key })
772
+
773
+ # Move direct paging integration from "No team" to team
774
+ response = client .put (
775
+ url ,
776
+ data = {"integration" : "direct_paging" , "team" : team .public_primary_key },
777
+ format = "json" ,
778
+ ** make_user_auth_headers (user , token ),
779
+ )
780
+
781
+ assert response .status_code == status .HTTP_400_BAD_REQUEST
782
+ assert response .json ()["detail" ] == AlertReceiveChannel .DuplicateDirectPagingError .DETAIL
783
+
784
+
696
785
@pytest .mark .django_db
697
786
def test_start_maintenance_integration (
698
787
make_user_auth_headers ,
0 commit comments