2024-04-22 00:42:08 -04:00
|
|
|
import requests
|
|
|
|
|
import json
|
|
|
|
|
import os
|
|
|
|
|
|
2024-04-22 12:51:22 -04:00
|
|
|
|
2024-04-22 00:42:08 -04:00
|
|
|
def request_tests():
|
|
|
|
|
url = "http://localhost:8080/request-tests"
|
|
|
|
|
downloaded_files = []
|
|
|
|
|
print("past url")
|
|
|
|
|
for i in range(100):
|
|
|
|
|
filename = f"TestFileTransfer.pdf"
|
2024-04-22 12:51:22 -04:00
|
|
|
|
|
|
|
|
payload = json.dumps(
|
|
|
|
|
{
|
|
|
|
|
"id": 5,
|
|
|
|
|
"filename": filename,
|
|
|
|
|
"ip": "143.215.87.54",
|
|
|
|
|
"new_filename": f"TestFileTransfer_{i}.pdf",
|
|
|
|
|
}
|
|
|
|
|
)
|
2024-04-22 00:42:08 -04:00
|
|
|
|
|
|
|
|
headers = {
|
2024-04-22 12:51:22 -04:00
|
|
|
"Content-Type": "application/json",
|
2024-04-22 00:42:08 -04:00
|
|
|
}
|
2024-04-22 12:51:22 -04:00
|
|
|
|
2024-04-22 00:42:08 -04:00
|
|
|
response = requests.get(url, headers=headers, data=payload)
|
|
|
|
|
print("response received")
|
|
|
|
|
print(payload)
|
|
|
|
|
print(response)
|
2024-04-22 12:51:22 -04:00
|
|
|
|
2024-04-22 00:42:08 -04:00
|
|
|
if response.status_code == 200:
|
|
|
|
|
print(f"Request {i+1} successful")
|
|
|
|
|
downloaded_files.append(f"bcdef_{i}.txt")
|
|
|
|
|
else:
|
|
|
|
|
print(f"Request {i+1} failed with status code {response.status_code}")
|
2024-04-22 12:51:22 -04:00
|
|
|
|
2024-04-22 00:42:08 -04:00
|
|
|
if downloaded_files:
|
2024-04-22 12:51:22 -04:00
|
|
|
file_paths = ", ".join(["./uploads/" + file for file in downloaded_files])
|
2024-04-22 00:42:08 -04:00
|
|
|
return f"1000 files have been downloaded to {file_paths}", 200
|
|
|
|
|
else:
|
|
|
|
|
return "No files downloaded", 200
|
|
|
|
|
|
2024-04-22 12:51:22 -04:00
|
|
|
|
|
|
|
|
request_tests()
|