@@ -82,55 +82,40 @@ def test_connect_authorization_header(self):
82
82
self .assertEqual (none_connect_client .get_authorization (), None )
83
83
84
84
85
-
86
85
class TestSystemRuntimeCachesAPI (TestCase ):
87
86
# RSConnectExecutor.list_runtime_caches() returns the resulting JSON from the server.
88
87
@httpretty .activate (verbose = True , allow_net_connect = False )
89
88
def test_client_system_caches_runtime_list (self ):
90
89
ce = RSConnectExecutor (None , "http://test-server/" , "api_key" )
91
90
mocked_response = {
92
91
"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" },
103
94
]
104
95
}
105
96
httpretty .register_uri (
106
97
httpretty .GET ,
107
98
"http://test-server/__api__/v1/system/caches/runtime" ,
108
99
body = json .dumps (mocked_response ),
109
100
status = 200 ,
110
- forcing_headers = {' Content-Type' : ' application/json' }
101
+ forcing_headers = {" Content-Type" : " application/json" },
111
102
)
112
103
result = ce .list_runtime_caches ()
113
104
self .assertDictEqual (result , mocked_response )
114
105
115
-
116
106
# # RSConnectExecutor.delete_runtime_cache() dry run returns expected request
117
107
# # RSConnectExecutor.delete_runtime_cache() dry run prints expected messages
118
108
@httpretty .activate (verbose = True , allow_net_connect = False )
119
109
def test_executor_delete_runtime_cache_dry_run (self ):
120
110
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 }
127
112
128
113
httpretty .register_uri (
129
114
httpretty .DELETE ,
130
115
"http://test-server/__api__/v1/system/caches/runtime" ,
131
116
body = json .dumps (mocked_output ),
132
117
status = 200 ,
133
- forcing_headers = {' Content-Type' : ' application/json' }
118
+ forcing_headers = {" Content-Type" : " application/json" },
134
119
)
135
120
136
121
captured_output = io .StringIO ()
@@ -140,14 +125,8 @@ def test_executor_delete_runtime_cache_dry_run(self):
140
125
141
126
# Print expectations
142
127
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" )
151
130
152
131
# Result expectations
153
132
self .assertDictEqual (mocked_output , result )
@@ -161,37 +140,32 @@ def test_executor_delete_runtime_cache_wet_run(self):
161
140
"language" : "Python" ,
162
141
"version" : "1.2.3" ,
163
142
"image_name" : "teapot" ,
164
- "task_id" : "this_is_a_task_id"
143
+ "task_id" : "this_is_a_task_id" ,
165
144
}
166
145
httpretty .register_uri (
167
146
httpretty .DELETE ,
168
147
"http://test-server/__api__/v1/system/caches/runtime" ,
169
148
body = json .dumps (mocked_delete_output ),
170
149
status = 200 ,
171
- forcing_headers = {' Content-Type' : ' application/json' }
150
+ forcing_headers = {" Content-Type" : " application/json" },
172
151
)
173
152
174
153
mocked_task_status = {
175
154
"id" : "this_is_a_task_id" ,
176
155
"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 },
184
158
"finished" : True ,
185
159
"code" : 0 ,
186
160
"error" : "" ,
187
- "last_status" : 1
161
+ "last_status" : 1 ,
188
162
}
189
163
httpretty .register_uri (
190
164
httpretty .GET ,
191
165
"http://test-server/__api__/tasks/this_is_a_task_id" ,
192
166
body = json .dumps (mocked_task_status ),
193
167
status = 200 ,
194
- forcing_headers = {' Content-Type' : ' application/json' }
168
+ forcing_headers = {" Content-Type" : " application/json" },
195
169
)
196
170
197
171
captured_output = io .StringIO ()
@@ -203,12 +177,9 @@ def test_executor_delete_runtime_cache_wet_run(self):
203
177
output_lines = captured_output .getvalue ().splitlines ()
204
178
self .assertEqual (
205
179
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'" ,
211
181
)
182
+ self .assertEqual (output_lines [1 ], "Cache deletion finished" )
212
183
213
184
# Result expectations
214
185
self .assertDictEqual (mocked_task_status , result )
@@ -217,27 +188,19 @@ def test_executor_delete_runtime_cache_wet_run(self):
217
188
@httpretty .activate (verbose = True , allow_net_connect = False )
218
189
def test_executor_delete_runtime_cache_error (self ):
219
190
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 }
225
192
httpretty .register_uri (
226
193
httpretty .DELETE ,
227
194
"http://test-server/__api__/v1/system/caches/runtime" ,
228
195
body = json .dumps (mocked_delete_output ),
229
196
status = 404 ,
230
- forcing_headers = {' Content-Type' : ' application/json' }
197
+ forcing_headers = {" Content-Type" : " application/json" },
231
198
)
232
199
233
200
with self .assertRaisesRegex (RSConnectException , "Cache path does not exist" ):
234
201
result = ce .delete_runtime_cache (language = "Python" , version = "1.2.3" , image_name = "teapot" , dry_run = False )
235
202
236
203
237
-
238
-
239
-
240
-
241
204
class RSConnectClientTestCase (TestCase ):
242
205
def test_deploy_existing_application_with_failure (self ):
243
206
with patch .object (RSConnectClient , "__init__" , lambda _ , server , cookies , timeout : None ):
0 commit comments