tested
This commit is contained in:
@@ -44,7 +44,6 @@ class OwnApi(TestCase):
|
|||||||
self.password = faker.word()
|
self.password = faker.word()
|
||||||
self.u.set_password(self.password)
|
self.u.set_password(self.password)
|
||||||
self.u.save()
|
self.u.save()
|
||||||
|
|
||||||
self.factory = APIRequestFactory()
|
self.factory = APIRequestFactory()
|
||||||
|
|
||||||
|
|
||||||
@@ -210,6 +209,43 @@ class OwnApi(TestCase):
|
|||||||
response = strokedata_tcx(request)
|
response = strokedata_tcx(request)
|
||||||
self.assertEqual(response.status_code,200)
|
self.assertEqual(response.status_code,200)
|
||||||
|
|
||||||
|
def test_strokedataform_rowingdata(self):
|
||||||
|
|
||||||
|
url = reverse('strokedata_rowingdata')
|
||||||
|
|
||||||
|
filename = 'rowers/tests/testdata/testdata.csv'
|
||||||
|
f = open(filename, 'rb')
|
||||||
|
|
||||||
|
# Use Basic Auth header (alternative if using a custom view)
|
||||||
|
credentials = f"{self.u.username}:{self.password}"
|
||||||
|
base64_credentials = base64.b64encode(credentials.encode()).decode()
|
||||||
|
|
||||||
|
# Use Basic Auth header
|
||||||
|
headers = {
|
||||||
|
"HTTP_AUTHORIZATION": f"Basic {base64_credentials}"
|
||||||
|
}
|
||||||
|
|
||||||
|
form_data = {
|
||||||
|
"workouttype": "rower",
|
||||||
|
"boattype": "1x",
|
||||||
|
"notes": "A test file upload",
|
||||||
|
}
|
||||||
|
|
||||||
|
# Send POST request
|
||||||
|
response = self.client.post(
|
||||||
|
url,
|
||||||
|
{"file": f, **form_data},
|
||||||
|
format="multipart", # Ensure multipart/form-data is used
|
||||||
|
**headers, # Optional if login doesn't suffice
|
||||||
|
)
|
||||||
|
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
# Assertions
|
||||||
|
self.assertEqual(response.status_code, 201)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_strokedataform_empty(self):
|
def test_strokedataform_empty(self):
|
||||||
login = self.c.login(username=self.u.username, password=self.password)
|
login = self.c.login(username=self.u.username, password=self.password)
|
||||||
self.assertTrue(login)
|
self.assertTrue(login)
|
||||||
|
|||||||
BIN
rowers/tests/testdata/testdata.tcx.gz
vendored
BIN
rowers/tests/testdata/testdata.tcx.gz
vendored
Binary file not shown.
@@ -434,40 +434,43 @@ def strokedata_rowingdata(request):
|
|||||||
if r.rowerplan == 'freecoach':
|
if r.rowerplan == 'freecoach':
|
||||||
return HttpResponseNotAllowed("This endpoint is for users, not for free coach accounts")
|
return HttpResponseNotAllowed("This endpoint is for users, not for free coach accounts")
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method != 'POST':
|
||||||
form = DocumentsForm(request.POST, request.FILES)
|
return HttpResponseNotAllowed("Method not supported") # pragma: no cover
|
||||||
if not form.is_valid():
|
|
||||||
return HttpResponseBadRequest(json.dumps(form.errors))
|
|
||||||
|
|
||||||
f = form.cleaned_data['file']
|
form = DocumentsForm(request.POST, request.FILES)
|
||||||
if f is None:
|
if not form.is_valid():
|
||||||
return HttpResponseBadRequest("Missing file")
|
return HttpResponseBadRequest(json.dumps(form.errors))
|
||||||
|
|
||||||
filename, completefilename = handle_uploaded_file(f)
|
f = form.cleaned_data['file']
|
||||||
|
if f is None:
|
||||||
|
return HttpResponseBadRequest("Missing file")
|
||||||
|
|
||||||
uploadoptions = {
|
filename, completefilename = handle_uploaded_file(f)
|
||||||
'secret': settings.UPLOAD_SERVICE_SECRET,
|
|
||||||
'user': r.user.id,
|
uploadoptions = {
|
||||||
'file': completefilename,
|
'secret': settings.UPLOAD_SERVICE_SECRET,
|
||||||
'workouttype': form.cleaned_data['workouttype'],
|
'user': r.user.id,
|
||||||
'boattype': form.cleaned_data['boattype'],
|
'file': completefilename,
|
||||||
'title': form.cleaned_data['title'],
|
'workouttype': form.cleaned_data['workouttype'],
|
||||||
'rpe': form.cleaned_data['rpe'],
|
'boattype': form.cleaned_data['boattype'],
|
||||||
'notes': form.cleaned_data['notes']
|
'title': form.cleaned_data['title'],
|
||||||
|
'rpe': form.cleaned_data['rpe'],
|
||||||
|
'notes': form.cleaned_data['notes']
|
||||||
|
}
|
||||||
|
|
||||||
|
url = settings.UPLOAD_SERVICE_URL
|
||||||
|
|
||||||
|
_ = myqueue(queuehigh,
|
||||||
|
handle_request_post,
|
||||||
|
url,
|
||||||
|
uploadoptions)
|
||||||
|
response = JsonResponse(
|
||||||
|
{
|
||||||
|
"status": "success",
|
||||||
}
|
}
|
||||||
|
)
|
||||||
url = settings.UPLOAD_SERVICE_URL
|
response.status_code = 201
|
||||||
|
return response
|
||||||
_ = myqueue(queuehigh,
|
|
||||||
handle_request_post,
|
|
||||||
url,
|
|
||||||
uploadoptions)
|
|
||||||
|
|
||||||
return JsonResponse(
|
|
||||||
{
|
|
||||||
"status": "success",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
|
|||||||
Reference in New Issue
Block a user