simple upload tests
This commit is contained in:
@@ -33,7 +33,9 @@ from django.urls import reverse
|
||||
from django.utils import timezone as tz
|
||||
|
||||
from rowers.forms import DocumentsForm, TeamUploadOptionsForm
|
||||
from rowers.models import TeamInviteForm, Workout, User, Rower, Team
|
||||
from rowers.models import (
|
||||
TeamInviteForm, Workout, User, Rower, Team,
|
||||
VirtualRace, IndoorVirtualRaceResult, VirtualRaceResult)
|
||||
from rowers.opaque import encoder
|
||||
from rowers import uploads
|
||||
|
||||
@@ -68,23 +70,27 @@ def generate_job_id():
|
||||
return str(uuid4())
|
||||
|
||||
def valid_uploadoptions(uploadoptions):
|
||||
secret = uploadoptions.get('secret', '')
|
||||
if secret != settings.UPLOAD_SERVICE_SECRET:
|
||||
return False
|
||||
|
||||
fstr = uploadoptions.get('file', None)
|
||||
if fstr is None:
|
||||
return False
|
||||
return False, "Missing file in upload options."
|
||||
|
||||
# check if file can be found
|
||||
if not os.path.isfile(fstr):
|
||||
return False
|
||||
if isinstance(fstr, str):
|
||||
if not os.path.isfile(fstr):
|
||||
return False, f"File not found: {fstr}"
|
||||
|
||||
|
||||
form = DocumentsForm(uploadoptions)
|
||||
optionsform = TeamUploadOptionsForm(uploadoptions)
|
||||
rowerform = TeamInviteForm(uploadoptions)
|
||||
rowerform.fields.pop('email') # we don't need email here
|
||||
return form.is_valid() and optionsform.is_valid() and rowerform.is_valid()
|
||||
return (
|
||||
form.is_valid() and optionsform.is_valid() and rowerform.is_valid(),
|
||||
"{form_errors}, {optionsform_errors}, {rowerform_errors}".format(
|
||||
form_errors=form.errors,
|
||||
optionsform_errors=optionsform.errors,
|
||||
rowerform_errors=rowerform.errors,
|
||||
))
|
||||
|
||||
def is_zipfile(file_path):
|
||||
fileformat = get_file_type(file_path)
|
||||
@@ -126,11 +132,12 @@ def is_invalid_file(file_path):
|
||||
|
||||
|
||||
def upload_handler(uploadoptions, filename):
|
||||
if not valid_uploadoptions(uploadoptions):
|
||||
valid, message = valid_uploadoptions(uploadoptions)
|
||||
if not valid:
|
||||
return {
|
||||
"status": "error",
|
||||
"job_id": None,
|
||||
"message": "Invalid upload options or file not found."
|
||||
"message": message
|
||||
}
|
||||
is_valid, message = is_invalid_file(filename)
|
||||
if not is_valid:
|
||||
|
||||
Reference in New Issue
Block a user