@@ -82,55 +82,40 @@ def test_connect_authorization_header(self):
8282 self .assertEqual (none_connect_client .get_authorization (), None )
8383
8484
85-
8685class TestSystemRuntimeCachesAPI (TestCase ):
8786 # RSConnectExecutor.list_runtime_caches() returns the resulting JSON from the server.
8887 @httpretty .activate (verbose = True , allow_net_connect = False )
8988 def test_client_system_caches_runtime_list (self ):
9089 ce = RSConnectExecutor (None , "http://test-server/" , "api_key" )
9190 mocked_response = {
9291 "caches" : [
93- {
94- "language" : "R" ,
95- "version" : "3.6.3" ,
96- "image_name" : "Local"
97- },
98- {
99- "language" : "Python" ,
100- "version" : "5.6.7" ,
101- "image_name" : "teapot.bak"
102- }
92+ {"language" : "R" , "version" : "3.6.3" , "image_name" : "Local" },
93+ {"language" : "Python" , "version" : "5.6.7" , "image_name" : "teapot.bak" },
10394 ]
10495 }
10596 httpretty .register_uri (
10697 httpretty .GET ,
10798 "http://test-server/__api__/v1/system/caches/runtime" ,
10899 body = json .dumps (mocked_response ),
109100 status = 200 ,
110- forcing_headers = {' Content-Type' : ' application/json' }
101+ forcing_headers = {" Content-Type" : " application/json" },
111102 )
112103 result = ce .list_runtime_caches ()
113104 self .assertDictEqual (result , mocked_response )
114105
115-
116106 # # RSConnectExecutor.delete_runtime_cache() dry run returns expected request
117107 # # RSConnectExecutor.delete_runtime_cache() dry run prints expected messages
118108 @httpretty .activate (verbose = True , allow_net_connect = False )
119109 def test_executor_delete_runtime_cache_dry_run (self ):
120110 ce = RSConnectExecutor (None , "http://test-server/" , "api_key" )
121- mocked_output = {
122- "language" : "Python" ,
123- "version" : "1.2.3" ,
124- "image_name" : "teapot" ,
125- "task_id" : None
126- }
111+ mocked_output = {"language" : "Python" , "version" : "1.2.3" , "image_name" : "teapot" , "task_id" : None }
127112
128113 httpretty .register_uri (
129114 httpretty .DELETE ,
130115 "http://test-server/__api__/v1/system/caches/runtime" ,
131116 body = json .dumps (mocked_output ),
132117 status = 200 ,
133- forcing_headers = {' Content-Type' : ' application/json' }
118+ forcing_headers = {" Content-Type" : " application/json" },
134119 )
135120
136121 captured_output = io .StringIO ()
@@ -140,14 +125,8 @@ def test_executor_delete_runtime_cache_dry_run(self):
140125
141126 # Print expectations
142127 output_lines = captured_output .getvalue ().splitlines ()
143- self .assertEqual (
144- output_lines [0 ],
145- "Would delete cache: 'Python', version: '1.2.3', image_name: 'teapot'"
146- )
147- self .assertEqual (
148- output_lines [1 ],
149- "Dry run finished"
150- )
128+ self .assertEqual (output_lines [0 ], "Would delete cache: 'Python', version: '1.2.3', image_name: 'teapot'" )
129+ self .assertEqual (output_lines [1 ], "Dry run finished" )
151130
152131 # Result expectations
153132 self .assertDictEqual (mocked_output , result )
@@ -161,37 +140,32 @@ def test_executor_delete_runtime_cache_wet_run(self):
161140 "language" : "Python" ,
162141 "version" : "1.2.3" ,
163142 "image_name" : "teapot" ,
164- "task_id" : "this_is_a_task_id"
143+ "task_id" : "this_is_a_task_id" ,
165144 }
166145 httpretty .register_uri (
167146 httpretty .DELETE ,
168147 "http://test-server/__api__/v1/system/caches/runtime" ,
169148 body = json .dumps (mocked_delete_output ),
170149 status = 200 ,
171- forcing_headers = {' Content-Type' : ' application/json' }
150+ forcing_headers = {" Content-Type" : " application/json" },
172151 )
173152
174153 mocked_task_status = {
175154 "id" : "this_is_a_task_id" ,
176155 "user_id" : 1 ,
177- "status" : [
178- "Removing runtime cache"
179- ],
180- "result" : {
181- "type" : "" ,
182- "data" : None
183- },
156+ "status" : ["Removing runtime cache" ],
157+ "result" : {"type" : "" , "data" : None },
184158 "finished" : True ,
185159 "code" : 0 ,
186160 "error" : "" ,
187- "last_status" : 1
161+ "last_status" : 1 ,
188162 }
189163 httpretty .register_uri (
190164 httpretty .GET ,
191165 "http://test-server/__api__/tasks/this_is_a_task_id" ,
192166 body = json .dumps (mocked_task_status ),
193167 status = 200 ,
194- forcing_headers = {' Content-Type' : ' application/json' }
168+ forcing_headers = {" Content-Type" : " application/json" },
195169 )
196170
197171 captured_output = io .StringIO ()
@@ -203,12 +177,9 @@ def test_executor_delete_runtime_cache_wet_run(self):
203177 output_lines = captured_output .getvalue ().splitlines ()
204178 self .assertEqual (
205179 output_lines [0 ],
206- "Deleting cache: 'Python', version: '1.2.3', image_name: 'teapot', task_id: 'this_is_a_task_id'"
207- )
208- self .assertEqual (
209- output_lines [1 ],
210- "Cache deletion finished"
180+ "Deleting cache: 'Python', version: '1.2.3', image_name: 'teapot', task_id: 'this_is_a_task_id'" ,
211181 )
182+ self .assertEqual (output_lines [1 ], "Cache deletion finished" )
212183
213184 # Result expectations
214185 self .assertDictEqual (mocked_task_status , result )
@@ -217,27 +188,19 @@ def test_executor_delete_runtime_cache_wet_run(self):
217188 @httpretty .activate (verbose = True , allow_net_connect = False )
218189 def test_executor_delete_runtime_cache_error (self ):
219190 ce = RSConnectExecutor (None , "http://test-server/" , "api_key" )
220- mocked_delete_output = {
221- "code" : 4 ,
222- "error" : "Cache path does not exist" ,
223- "payload" : None
224- }
191+ mocked_delete_output = {"code" : 4 , "error" : "Cache path does not exist" , "payload" : None }
225192 httpretty .register_uri (
226193 httpretty .DELETE ,
227194 "http://test-server/__api__/v1/system/caches/runtime" ,
228195 body = json .dumps (mocked_delete_output ),
229196 status = 404 ,
230- forcing_headers = {' Content-Type' : ' application/json' }
197+ forcing_headers = {" Content-Type" : " application/json" },
231198 )
232199
233200 with self .assertRaisesRegex (RSConnectException , "Cache path does not exist" ):
234201 result = ce .delete_runtime_cache (language = "Python" , version = "1.2.3" , image_name = "teapot" , dry_run = False )
235202
236203
237-
238-
239-
240-
241204class RSConnectClientTestCase (TestCase ):
242205 def test_deploy_existing_application_with_failure (self ):
243206 with patch .object (RSConnectClient , "__init__" , lambda _ , server , cookies , timeout : None ):
0 commit comments