Skip to content

Commit

Permalink
test: update echoes tests to use file selection utility
Browse files Browse the repository at this point in the history
  • Loading branch information
jkglasbrenner committed Jan 14, 2025
1 parent 8105b58 commit 886e89d
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions tests/unit/restapi/v1/test_echoes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from dioptra.client.base import DioptraResponseProtocol
from dioptra.client.client import DioptraClient
from dioptra.client.utils import select_files_in_directory, select_one_or_more_files

# -- Tests -----------------------------------------------------------------------------

Expand All @@ -27,26 +28,37 @@ def test_upload_files(
dioptra_client: DioptraClient[DioptraResponseProtocol],
tmp_path: Path,
) -> None:
(tmp_path / "subdir").mkdir()
fake_file1_path = tmp_path / "fake_file1.txt"
fake_file2_path = tmp_path / "fake_file2.txt"
fake_file3_path = tmp_path / "subdir" / "fake_file3.txt"

with fake_file1_path.open("wt") as f1, fake_file2_path.open("wt") as f2:
with (
fake_file1_path.open("wt") as f1,
fake_file2_path.open("wt") as f2,
fake_file3_path.open("wt") as f3,
):
f1.write("This is a test file.")
f2.write("This is also a test file.")
f3.write("This is yet another test file.")

fake_file1_size = os.stat(fake_file1_path).st_size
fake_file2_size = os.stat(fake_file2_path).st_size
fake_file3_size = os.stat(fake_file3_path).st_size

response = dioptra_client.echoes.create(
test_files=[str(fake_file1_path), str(fake_file2_path)],
test_files=select_files_in_directory(tmp_path, recursive=True),
test_string="A test",
)
response_dict = response.json()

assert response_dict["testFilesInfo"][0]["filename"] == str(fake_file1_path)
assert response_dict["testFilesInfo"][1]["filename"] == str(fake_file2_path)
assert response_dict["testString"] == "A test"
assert response_dict["testFilesInfo"][0]["filename"] == "fake_file1.txt"
assert response_dict["testFilesInfo"][1]["filename"] == "fake_file2.txt"
assert response_dict["testFilesInfo"][2]["filename"] == "subdir/fake_file3.txt"
assert response_dict["testFilesInfo"][0]["size"] == fake_file1_size
assert response_dict["testFilesInfo"][1]["size"] == fake_file2_size
assert response_dict["testFilesInfo"][2]["size"] == fake_file3_size


def test_upload_single_file(
Expand All @@ -61,10 +73,11 @@ def test_upload_single_file(
fake_file_size = os.stat(fake_file_path).st_size

response = dioptra_client.echoes.create_single(
test_file=str(fake_file_path),
test_file=select_one_or_more_files([fake_file_path])[0],
test_string="A single file test",
)
response_dict = response.json()

assert response_dict["testFileInfo"]["filename"] == str(fake_file_path)
assert response_dict["testString"] == "A single file test"
assert response_dict["testFileInfo"]["filename"] == str(fake_file_path.name)
assert response_dict["testFileInfo"]["size"] == fake_file_size

0 comments on commit 886e89d

Please sign in to comment.