Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

Commit

Permalink
Melhora redabilidade com Path
Browse files Browse the repository at this point in the history
  • Loading branch information
anapaulagomes committed Oct 14, 2021
1 parent 5deda23 commit 638ffa5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions web/datasets/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def upload_file(self, location_or_url, relative_file_path, prefix=""):

@staticmethod
def create_temp_file(url, relative_file_path="", prefix=""):
temporary_directory = Path(f"{settings.DATA_DIR}/{relative_file_path}")
temporary_directory = Path(settings.DATA_DIR) / relative_file_path
temporary_directory.mkdir(parents=True, exist_ok=True)

response = requests.get(url)
Expand All @@ -66,7 +66,7 @@ def download_file(self, s3_file_path):
start_index = s3_file_path.rfind("/") + 1
file_name = s3_file_path[start_index:]

local_path = f"{settings.DATA_DIR}/{file_name}"
local_path = Path(settings.DATA_DIR) / file_name
with open(local_path, "wb") as file_:
self.client.download_fileobj(self.bucket, s3_file_path, file_)

Expand Down
8 changes: 4 additions & 4 deletions web/datasets/tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ def test_upload_file(self):

expected_file_path = f"maria-quiteria-local/files/{relative_path}/robots.txt"
expected_s3_url = f"https://teste.s3.brasil.amazonaws.com/{bucket_file_path}"
real_path = Path(f"{settings.DATA_DIR}/{expected_file_path}")
real_path = Path(settings.DATA_DIR) / expected_file_path

assert s3_url == expected_s3_url
assert bucket_file_path == expected_file_path
assert real_path.exists() is True
assert real_path.exists()
real_path.unlink()

def test_create_temp_file(self):
Expand Down Expand Up @@ -68,11 +68,11 @@ def test_download_file(self):

expected_file_path = f"maria-quiteria-local/files/{relative_path}/robots.txt"
expected_s3_url = f"https://teste.s3.brasil.amazonaws.com/{expected_file_path}"
real_path = Path(f"{settings.DATA_DIR}/{expected_file_path}")
real_path = Path(settings.DATA_DIR) / expected_file_path

assert s3_url == expected_s3_url
assert relative_file_path == expected_file_path
assert real_path.exists() is True
assert real_path.exists()

absolute_file_path = client.download_file(relative_file_path)

Expand Down

0 comments on commit 638ffa5

Please sign in to comment.