This commit is contained in:
Sahej Panag
2024-04-21 21:53:40 -04:00
parent 155e60700f
commit 2b5d0ffe23
2 changed files with 16 additions and 14 deletions

View File

@@ -76,7 +76,7 @@ def request_file():
return error, response.status_code
@app.route('/request-tests', methods=['GET'])
def request_tests():
def request_test_():
data = request.json
file_id = data['id']
filename = data['filename']

View File

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