Skip to content

Commit 55c38e5

Browse files
committed
add integration tests; run make fmt
1 parent 0e5c3b0 commit 55c38e5

File tree

7 files changed

+170
-79
lines changed

7 files changed

+170
-79
lines changed

rsconnect/api.py

+10-15
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,12 @@ def system_caches_runtime_list(self):
219219
response = self.get("v1/system/caches/runtime")
220220
self._server.handle_bad_response(response)
221221
return response
222-
222+
223223
def system_caches_runtime_delete(self, target):
224224
response = self.delete("v1/system/caches/runtime", body=target)
225225
self._server.handle_bad_response(response)
226226
return response
227227

228-
229228
def task_get(self, task_id, first_status=None):
230229
params = None
231230
if first_status is not None:
@@ -994,25 +993,22 @@ def make_deployment_name(self, title, force_unique):
994993

995994
def list_runtime_caches(self):
996995
return self.client.system_caches_runtime_list()
997-
996+
998997
def delete_runtime_cache(self, language, version, image_name, dry_run):
999-
target = {
1000-
"language": language,
1001-
"version": version,
1002-
"image_name": image_name,
1003-
"dry_run": dry_run
1004-
}
998+
target = {"language": language, "version": version, "image_name": image_name, "dry_run": dry_run}
1005999
result = self.client.system_caches_runtime_delete(target)
10061000
if result["task_id"] == None:
1007-
print(f"Would delete cache: '{result['language']}', version: '{result['version']}', image_name: '{result['image_name']}'")
1001+
print(
1002+
f"Would delete cache: '{result['language']}', version: '{result['version']}', image_name: '{result['image_name']}'"
1003+
)
10081004
print("Dry run finished")
10091005
return result
10101006
else:
1011-
print(f"Deleting cache: '{result['language']}', version: '{result['version']}', image_name: '{result['image_name']}', task_id: '{result['task_id']}'")
1007+
print(
1008+
f"Deleting cache: '{result['language']}', version: '{result['version']}', image_name: '{result['image_name']}', task_id: '{result['task_id']}'"
1009+
)
10121010
(log_lines, task_status) = self.client.wait_for_task(
1013-
result["task_id"],
1014-
connect_logger.info,
1015-
raise_on_error=False
1011+
result["task_id"], connect_logger.info, raise_on_error=False
10161012
)
10171013

10181014
# Task status cannot be finished because we have no timeout.
@@ -1026,7 +1022,6 @@ def delete_runtime_cache(self, language, version, image_name, dry_run):
10261022
return task_status
10271023

10281024

1029-
10301025
def filter_out_server_info(**kwargs):
10311026
server_fields = {"connect_server", "name", "server", "api_key", "insecure", "cacert"}
10321027
new_kwargs = {k: v for k, v in kwargs.items() if k not in server_fields}

rsconnect/http_support.py

-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ def put(self, path, query_params=None, body=None, headers=None, decode_response=
243243
def delete(self, path, query_params=None, body=None, decode_response=True):
244244
return self.request("DELETE", path, query_params, body, decode_response=decode_response)
245245

246-
247246
def request(
248247
self,
249248
method,

rsconnect/main.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -2421,6 +2421,7 @@ def start_content_build(
24212421
def system():
24222422
pass
24232423

2424+
24242425
@system.group(no_args_is_help=True, help="Interact with Posit Connect's system caches.")
24252426
def caches():
24262427
pass
@@ -2466,6 +2467,7 @@ def system_caches_list(name, server, api_key, insecure, cacert, verbose):
24662467
result = ce.list_runtime_caches()
24672468
json.dump(result, sys.stdout, indent=2)
24682469

2470+
24692471
# noinspection SpellCheckingInspection,DuplicatedCode
24702472
@caches.command(
24712473
name="delete",
@@ -2511,7 +2513,7 @@ def system_caches_list(name, server, api_key, insecure, cacert, verbose):
25112513
@click.option(
25122514
"--image-name",
25132515
"-I",
2514-
help="Either \"Local\" or the image name of the target cache's execution environment.",
2516+
help='Either "Local" or the image name of the target cache\'s execution environment.',
25152517
)
25162518
@click.option(
25172519
"--dry-run",
@@ -2528,7 +2530,6 @@ def system_caches_delete(name, server, api_key, insecure, cacert, verbose, langu
25282530
logger.debug(result)
25292531

25302532

2531-
25322533
if __name__ == "__main__":
25332534
cli()
25342535
click.echo()

tests/test_api.py

+17-54
Original file line numberDiff line numberDiff line change
@@ -82,55 +82,40 @@ def test_connect_authorization_header(self):
8282
self.assertEqual(none_connect_client.get_authorization(), None)
8383

8484

85-
8685
class 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-
241204
class RSConnectClientTestCase(TestCase):
242205
def test_deploy_existing_application_with_failure(self):
243206
with patch.object(RSConnectClient, "__init__", lambda _, server, cookies, timeout: None):

tests/test_certificates.py

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66

77
class ParseCertificateFileTestCase(TestCase):
8-
98
def test_parse_certificate_file_ca_bundle(self):
109
res = read_certificate_file("tests/testdata/certificates/localhost.ca-bundle")
1110
self.assertTrue(res)

0 commit comments

Comments
 (0)