Skip to content

Commit

Permalink
fix(tests): update status code assertions and remove redundant test c…
Browse files Browse the repository at this point in the history
…ases
  • Loading branch information
kshitijrajsharma committed Jan 7, 2025
1 parent 6eae3d7 commit c71f92c
Showing 1 changed file with 1 addition and 41 deletions.
42 changes: 1 addition & 41 deletions backend/tests/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def test_create_training(self):
res = self.client.post(
f"{API_BASE}/label/osm/fetch/{self.aoi.id}/", "", headers=headersList
)
self.assertEqual(res.status_code, status.HTTP_201_CREATED)
self.assertEqual(res.status_code, 201)

# download labels from osm for 2

Expand Down Expand Up @@ -309,43 +309,3 @@ def test_get_workspace(self):

res = self.client.get(f"{API_BASE}/workspace/dataset_1/", headers=headersList)
self.assertEqual(res.status_code, 404)

def test_download_workspace(self):
try:
lookup_dir = "test_dir"

# download non-existent dir should fail
res = self.client.get(
f"{API_BASE}/workspace/download/{lookup_dir}", headers=headersList
)
self.assertEqual(res.status_code, status.HTTP_404_NOT_FOUND)

# test download workspace
base_dir = os.path.join(settings.TRAINING_WORKSPACE, lookup_dir)
os.makedirs(base_dir)

with open(os.path.join(base_dir, "file.txt"), "wb") as f:
f.write(b"Test file")

res = self.client.get(
f"{API_BASE}/workspace/download/{lookup_dir}",
headers=headersList,
)
self.assertEqual(res.status_code, status.HTTP_200_OK)

# test download file greater than the 200 mb limit

with open(os.path.join(base_dir, "large_file.txt"), "wb") as f:
f.seek(201 * 1024**2)
f.write(b"\0")

# download file size greater than limit should fail
res = self.client.get(
f"{API_BASE}/workspace/download/{lookup_dir}",
headers=headersList,
)
self.assertEqual(res.status_code, status.HTTP_403_FORBIDDEN)

finally:
# clean up
shutil.rmtree(base_dir)

0 comments on commit c71f92c

Please sign in to comment.