Skip to content

Commit

Permalink
Merge branch 'kevoreilly:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaudioWayne authored Mar 22, 2024
2 parents f5a7cd8 + 7682dd8 commit 9425632
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ def do_mkdir():
try:
mode = int(request.form.get("mode", 0o777))

os.makedirs(request.form["dirpath"], mode=mode)
os.makedirs(request.form["dirpath"], mode=mode, exist_ok=True)
except Exception as ex:
print(f"error creating dir {ex}")
return json_exception("Error creating directory")
Expand Down
10 changes: 7 additions & 3 deletions agent/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,14 +369,18 @@ def test_mkdir_valid(self):
assert os.path.exists(new_dir)
assert os.path.isdir(new_dir)

def test_mkdir_invalid(self):
def test_mkdir_missing(self):
"""Ensure we get an error returned when the mkdir request fails."""
form = {}
js = self.post_form("mkdir", form, 400)
assert js["message"] == "No dirpath has been provided"

root = pathlib.Path(tempfile.gettempdir()).root
form = {"dirpath": root, "mode": 0o777}
@pytest.mark.skip("Not many paths are actually invalid")
def test_mkdir_invalid(self):
"""Ensure we get an error returned when the mkdir request fails."""
# TODO come up with an invalid directory path for windows / linux
invalid = ""
form = {"dirpath": invalid, "mode": 0o777}
js = self.post_form("mkdir", form, 500)
assert js["message"] == "Error creating directory"

Expand Down

0 comments on commit 9425632

Please sign in to comment.