Skip to content

Commit

Permalink
tests for folder http endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
jlewitt1 committed Aug 6, 2024
1 parent 22cb540 commit 55163ec
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions tests/test_servers/test_http_server.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os
import tempfile
from pathlib import Path

Expand Down Expand Up @@ -214,6 +215,101 @@ def test_log_streaming_call(self, http_client, remote_log_streaming_func):
== 3
)

@pytest.mark.level("local")
def test_folder_put_and_get(self, http_client, cluster):
response = http_client.post(
"/folder/method/put",
json={
"path": "~/.rh",
"contents": {"new_file.txt": "Hello, world!"},
},
headers=rns_client.request_headers(cluster.rns_address),
)
assert response.status_code == 200

response = http_client.post(
"/folder/method/get",
json={"path": "~/.rh/new_file.txt"},
headers=rns_client.request_headers(cluster.rns_address),
)
assert response.status_code == 200

resp_json = response.json()
serialization = resp_json["serialization"]

assert serialization == "pickle"
assert resp_json["output_type"] == "result_serialized"
assert deserialize_data(resp_json["data"], serialization) == "Hello, world!"

@pytest.mark.level("local")
def test_folder_mv(self, http_client, cluster):
response = http_client.post(
"/folder/method/mv",
json={"path": "~/.rh/new_file.txt", "dest_path": "~/new_file.txt"},
headers=rns_client.request_headers(cluster.rns_address),
)
assert response.status_code == 200

response = http_client.post(
"/folder/method/get",
json={"path": "~/new_file.txt"},
headers=rns_client.request_headers(cluster.rns_address),
)
assert response.status_code == 200

@pytest.mark.level("local")
def test_folder_mkdir(self, http_client, cluster):
response = http_client.post(
"/folder/method/mkdir",
json={"path": "~/.rh/new-folder"},
headers=rns_client.request_headers(cluster.rns_address),
)
assert response.status_code == 200

@pytest.mark.level("local")
def test_folder_rm_and_ls(self, http_client, cluster):
# Delete the file
response = http_client.post(
"/folder/method/rm",
json={
"path": "~/.rh/new-folder",
"contents": ["new_file.txt"],
},
headers=rns_client.request_headers(cluster.rns_address),
)
assert response.status_code == 200

# empty folder should still be there since recursive not explicitly set to `True`
response = http_client.post(
"/folder/method/ls",
json={"path": "~/.rh"},
headers=rns_client.request_headers(cluster.rns_address),
)
assert response.status_code == 200

file_names: list = response.json().get("data")
base_names = [os.path.basename(f) for f in file_names]
assert "new-folder" in base_names

# Delete the now empty folder
response = http_client.post(
"/folder/method/rm",
json={"path": "~/.rh/new-folder"},
headers=rns_client.request_headers(cluster.rns_address),
)
assert response.status_code == 200

response = http_client.post(
"/folder/method/ls",
json={"path": "~/.rh"},
headers=rns_client.request_headers(cluster.rns_address),
)
assert response.status_code == 200

file_names: list = response.json().get("data")
base_names = [os.path.basename(f) for f in file_names]
assert "new-folder" not in base_names

@pytest.mark.level("local")
@pytest.mark.asyncio
async def test_async_call(self, async_http_client, remote_func):
Expand Down

0 comments on commit 55163ec

Please sign in to comment.