@@ -61,6 +61,7 @@ def __init__(
6161 port = None ,
6262 timeout = 30 ,
6363 verify = True ,
64+ response_status_code = 200 ,
6465 ):
6566 super ().__init__ (
6667 host ,
@@ -81,6 +82,7 @@ def __init__(
8182 port = port ,
8283 timeout = timeout ,
8384 verify = verify ,
85+ response_status_code = response_status_code ,
8486 )
8587 elif api_format == "xml" :
8688 self .api = MockXMLClient (
@@ -91,10 +93,33 @@ def __init__(
9193 port = port ,
9294 timeout = timeout ,
9395 verify = verify ,
96+ response_status_code = response_status_code ,
9497 )
9598
9699
97100class MockRPCClient (RPCClient ):
101+ def __init__ (
102+ self ,
103+ host ,
104+ username ,
105+ password ,
106+ transport = "https" ,
107+ port = None ,
108+ timeout = 30 ,
109+ verify = True ,
110+ response_status_code = 200 ,
111+ ):
112+ self .response_status_code = response_status_code
113+ super ().__init__ (
114+ host = host ,
115+ username = username ,
116+ password = password ,
117+ transport = transport ,
118+ port = port ,
119+ timeout = timeout ,
120+ verify = verify ,
121+ )
122+
98123 def _send_request (self , commands , method = "cli" ):
99124 payload = self ._build_payload (commands , method )
100125
@@ -112,12 +137,34 @@ def _send_request(self, commands, method="cli"):
112137
113138 response_obj = FakeResponse ()
114139 response_obj .text = mock_response
115- response_obj .status_code = 200
140+ response_obj .status_code = self . response_status_code
116141
117- return response_obj . text
142+ return response_obj
118143
119144
120145class MockXMLClient (XMLClient ):
146+ def __init__ (
147+ self ,
148+ host ,
149+ username ,
150+ password ,
151+ transport = "https" ,
152+ port = None ,
153+ timeout = 30 ,
154+ verify = True ,
155+ response_status_code = 200 ,
156+ ):
157+ self .response_status_code = response_status_code
158+ super ().__init__ (
159+ host = host ,
160+ username = username ,
161+ password = password ,
162+ transport = transport ,
163+ port = port ,
164+ timeout = timeout ,
165+ verify = verify ,
166+ )
167+
121168 def _send_request (self , commands , method = "cli_show" ):
122169 payload = self ._build_payload (commands , method )
123170
@@ -135,6 +182,6 @@ def _send_request(self, commands, method="cli_show"):
135182
136183 response_obj = FakeResponse ()
137184 response_obj .text = mock_response
138- response_obj .status_code = 200
185+ response_obj .status_code = self . response_status_code
139186
140- return response_obj . text
187+ return response_obj
0 commit comments