11import sys
22import os
33
4+ from parameterized import parameterized
5+
46sys .path .append (os .path .abspath ("../" ))
57
68from unittest import TestCase , mock
79from icon_cisco_umbrella_destinations .connection .connection import Connection
810from icon_cisco_umbrella_destinations .actions .dlCreate import DlCreate
911from icon_cisco_umbrella_destinations .actions .dlCreate .schema import Input
10- import json
12+ from insightconnect_plugin_runtime . exceptions import PluginException
1113import logging
12- from unit_test .mock import STUB_CONNECTION , mock_request_200 , STUB_DESTINATION_LIST_ID
14+ from unit_test .mock import (
15+ STUB_CONNECTION ,
16+ mock_request_200 ,
17+ mock_request_403 ,
18+ mock_request_401 ,
19+ mock_request_500 ,
20+ mock_request_400 ,
21+ mock_request_404 ,
22+ STUB_DESTINATION_LIST_ID ,
23+ mocked_request ,
24+ )
1325
1426
1527class TestDlCreate (TestCase ):
@@ -28,21 +40,18 @@ def setUp(self) -> None:
2840 "name" : "DELETEME2" ,
2941 }
3042
43+ self .params = {Input .ACCESS : "allow" , Input .ISGLOBAL : False , Input .LABEL : "DELETEME2" }
44+
3145 @mock .patch ("requests.request" , side_effect = mock_request_200 )
3246 def test_successful (self , mock_post ):
33- response = self .action .run ({
34- Input .ACCESS : 'allow' ,
35- Input .ISGLOBAL : False ,
36- Input .LABEL : 'DELETEME2'
37- })
47+ response = self .action .run ({Input .ACCESS : "allow" , Input .ISGLOBAL : False , Input .LABEL : "DELETEME2" })
3848 expected_response = {
3949 "success" : {
4050 "id" : 15786904 ,
4151 "organizationId" : 2372338 ,
4252 "access" : "allow" ,
4353 "isGlobal" : False ,
4454 "name" : "DELETEME2" ,
45- "thirdpartyCategoryId" : None ,
4655 "createdAt" : "2022-02-10T11:01:20+0000" ,
4756 "modifiedAt" : "2022-02-10T11:01:20+0000" ,
4857 "isMspDefault" : False ,
@@ -52,3 +61,18 @@ def test_successful(self, mock_post):
5261 }
5362 }
5463 self .assertEqual (response , expected_response )
64+
65+ @parameterized .expand (
66+ [
67+ (mock_request_401 , PluginException .Preset .USERNAME_PASSWORD ),
68+ (mock_request_403 , PluginException .Preset .UNAUTHORIZED ),
69+ (mock_request_404 , PluginException .Preset .UNAUTHORIZED ),
70+ (mock_request_500 , PluginException .Preset .SERVER_ERROR ),
71+ ],
72+ )
73+ def test_not_ok (self , mock_request , exception ):
74+ mocked_request (mock_request )
75+
76+ with self .assertRaises (PluginException ) as context :
77+ self .action .run (self .params )
78+ self .assertEqual (context .exception .cause , PluginException .causes [exception ])
0 commit comments