Private
Public Access
1
0

should pass tests now

This commit is contained in:
Sander Roosendaal
2020-12-02 18:47:17 +01:00
parent 78c6bfb345
commit edb080f9b2
9 changed files with 116 additions and 51 deletions

View File

@@ -1572,7 +1572,6 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower',
if title is not None and len(title)>140: if title is not None and len(title)>140:
title = title[0:140] title = title[0:140]
w = Workout(user=r, name=title, date=workoutdate, w = Workout(user=r, name=title, date=workoutdate,
workouttype=workouttype, workouttype=workouttype,
boattype=boattype, boattype=boattype,
@@ -1813,6 +1812,7 @@ def new_workout_from_file(r, f2,
workoutsource=None, workoutsource=None,
title='Workout', title='Workout',
boattype='1x', boattype='1x',
rpe=-1,
makeprivate=False, makeprivate=False,
notes='', notes='',
uploadoptions={'boattype':'1x','workouttype':'rower'}): uploadoptions={'boattype':'1x','workouttype':'rower'}):
@@ -1947,6 +1947,7 @@ def new_workout_from_file(r, f2,
dosummary=dosummary, dosummary=dosummary,
workoutsource=workoutsource, workoutsource=workoutsource,
summary=summary, summary=summary,
rpe=rpe,
inboard=inboard, oarlength=oarlength, inboard=inboard, oarlength=oarlength,
title=title, title=title,
forceunit='N', forceunit='N',

View File

@@ -245,17 +245,23 @@ class StandardsForm(forms.Form):
# The form used for uploading files # The form used for uploading files
class DocumentsForm(forms.Form): class DocumentsForm(forms.Form):
rpechoices = Workout.rpechoices
rpechoices = tuple([(-1,'---')]+list(rpechoices))
title = forms.CharField(required=False) title = forms.CharField(required=False)
file = forms.FileField(required=False, file = forms.FileField(required=False,
validators=[validate_file_extension]) validators=[validate_file_extension])
workouttype = forms.ChoiceField(required=True, workouttype = forms.ChoiceField(required=True,
choices=Workout.workouttypes) choices=Workout.workouttypes,
label='Workout Type')
boattype = forms.ChoiceField(required=True, boattype = forms.ChoiceField(required=True,
choices=mytypes.boattypes, choices=mytypes.boattypes,
label = "Boat Type") label = "Boat Type")
rpe = forms.ChoiceField(required=False,
choices=rpechoices,
label='Rate of Perceived Exertion',initial=-1)
notes = forms.CharField(required=False, notes = forms.CharField(required=False,
widget=forms.Textarea) widget=forms.Textarea)

View File

@@ -195,6 +195,7 @@ class CPChartTest(TestCase):
'duplicate': False, 'duplicate': False,
'avghr': '160', 'avghr': '160',
'avgpwr': 0, 'avgpwr': 0,
'rpe':4,
'avgspm': 40, 'avgspm': 40,
} }

View File

@@ -4,6 +4,7 @@ from __future__ import print_function
from __future__ import unicode_literals from __future__ import unicode_literals
#from __future__ import print_function #from __future__ import print_function
from .statements import * from .statements import *
from django.db import transaction
@override_settings(TESTING=True) @override_settings(TESTING=True)
class EmailUpload(TestCase): class EmailUpload(TestCase):
@@ -62,6 +63,7 @@ workout run
'workouttype':'rower', 'workouttype':'rower',
'boattype': '1x', 'boattype': '1x',
'notes': 'aap noot mies', 'notes': 'aap noot mies',
'rpe':1,
'make_plot': False, 'make_plot': False,
'upload_to_C2': False, 'upload_to_C2': False,
'plottype': 'timeplot', 'plottype': 'timeplot',
@@ -84,27 +86,29 @@ workout run
@patch('rowers.dataprep.create_engine') @patch('rowers.dataprep.create_engine')
@patch('rowers.dataprep.getsmallrowdata_db',side_effect=mocked_getsmallrowdata_db) @patch('rowers.dataprep.getsmallrowdata_db',side_effect=mocked_getsmallrowdata_db)
def test_uploadapi2(self,mocked_sqlalchemy,mocked_getsmallrowdata_db): def test_uploadapi2(self,mocked_sqlalchemy,mocked_getsmallrowdata_db):
form_data = { with transaction.atomic():
'title': 'test', form_data = {
'workouttype':'rower', 'title': 'test',
'boattype': '1x', 'workouttype':'rower',
'notes': 'aap noot mies', 'boattype': '1x',
'make_plot': False, 'notes': 'aap noot mies',
'upload_to_C2': False, 'make_plot': False,
'plottype': 'timeplot', 'upload_to_C2': False,
'file': 'media/mailbox_attachments/colin3.csv', 'plottype': 'timeplot',
'secret': settings.UPLOAD_SERVICE_SECRET, 'rpe':4,
'useremail': 'sander2@ds.nl', 'file': 'media/mailbox_attachments/colin3.csv',
} 'secret': settings.UPLOAD_SERVICE_SECRET,
'useremail': 'sander2@ds.nl',
}
url = reverse('workout_upload_api') url = reverse('workout_upload_api')
response = self.c.post(url,form_data,HTTP_HOST='127.0.0.1:4533') response = self.c.post(url,form_data,HTTP_HOST='127.0.0.1:4533')
self.assertEqual(response.status_code,200) self.assertEqual(response.status_code,200)
# should also test if workout is created # should also test if workout is created
w = Workout.objects.get(id=1) w = Workout.objects.get(id=1)
self.assertEqual(w.name,'test') self.assertEqual(w.name,'test')
self.assertEqual(w.notes,'aap noot mies') self.assertEqual(w.notes,'aap noot mies')
@patch('rowers.dataprep.create_engine') @patch('rowers.dataprep.create_engine')
@patch('rowers.dataprep.getsmallrowdata_db',side_effect=mocked_getsmallrowdata_db) @patch('rowers.dataprep.getsmallrowdata_db',side_effect=mocked_getsmallrowdata_db)

View File

@@ -32,6 +32,7 @@ class DataTest(TestCase):
'weightcategory':'lwt', 'weightcategory':'lwt',
'adaptiveclass': 'PR1', 'adaptiveclass': 'PR1',
'workouttype':'water', 'workouttype':'water',
'rpe':1,
'boattype':'1x', 'boattype':'1x',
'private':False, 'private':False,
} }

View File

@@ -55,6 +55,7 @@ class ForceUnits(TestCase):
'make_plot':False, 'make_plot':False,
'upload_to_c2':False, 'upload_to_c2':False,
'plottype':'timeplot', 'plottype':'timeplot',
'rpe': 1,
'file': f, 'file': f,
} }
@@ -100,6 +101,7 @@ class ForceUnits(TestCase):
'boattype':'1x', 'boattype':'1x',
'notes':'aap noot mies', 'notes':'aap noot mies',
'make_plot':False, 'make_plot':False,
'rpe': 1,
'upload_to_c2':False, 'upload_to_c2':False,
'plottype':'timeplot', 'plottype':'timeplot',
'file': f, 'file': f,
@@ -131,6 +133,7 @@ class ForceUnits(TestCase):
file_data = {'file': f} file_data = {'file': f}
form_data = { form_data = {
'title':'test', 'title':'test',
'rpe':1,
'workouttype':'rower', 'workouttype':'rower',
'boattype':'1x', 'boattype':'1x',
'notes':'aap noot mies', 'notes':'aap noot mies',

View File

@@ -6,6 +6,7 @@ from __future__ import unicode_literals
#from __future__ import print_function #from __future__ import print_function
from .statements import * from .statements import *
nu = datetime.datetime.now() nu = datetime.datetime.now()
from django.db import transaction
from rowers.views import add_defaultfavorites from rowers.views import add_defaultfavorites
@@ -50,7 +51,9 @@ class ViewTest(TestCase):
'workouttype':'rower', 'workouttype':'rower',
'boattype':'1x', 'boattype':'1x',
'notes':'aap noot mies', 'notes':'aap noot mies',
'rpe':4,
'make_plot':False, 'make_plot':False,
'rpe':6,
'upload_to_c2':False, 'upload_to_c2':False,
'plottype':'timeplot', 'plottype':'timeplot',
'file': f, 'file': f,
@@ -100,6 +103,7 @@ class ViewTest(TestCase):
'adaptiveclass':'PR1', 'adaptiveclass':'PR1',
'workouttype':'rower', 'workouttype':'rower',
'boattype':'1x', 'boattype':'1x',
'rpe':4,
'dragfactor':'112', 'dragfactor':'112',
'private':True, 'private':True,
'notes':'noot mies', 'notes':'noot mies',
@@ -141,6 +145,7 @@ class ViewTest(TestCase):
'workouttype':'rower', 'workouttype':'rower',
'boattype':'1x', 'boattype':'1x',
'notes':'aap noot mies', 'notes':'aap noot mies',
'rpe':6,
'make_plot':False, 'make_plot':False,
'upload_to_C2':False, 'upload_to_C2':False,
'upload_to_Strava':False, 'upload_to_Strava':False,
@@ -193,6 +198,7 @@ class ViewTest(TestCase):
'upload_to_c2':False, 'upload_to_c2':False,
'plottype':'timeplot', 'plottype':'timeplot',
'file': f, 'file': f,
'rpe':6,
} }
form = DocumentsForm(form_data,file_data) form = DocumentsForm(form_data,file_data)
@@ -229,6 +235,7 @@ class ViewTest(TestCase):
'upload_to_c2':False, 'upload_to_c2':False,
'plottype':'timeplot', 'plottype':'timeplot',
'file': f, 'file': f,
'rpe':6,
} }
form = DocumentsForm(form_data,file_data) form = DocumentsForm(form_data,file_data)
@@ -263,6 +270,7 @@ class ViewTest(TestCase):
'upload_to_c2':False, 'upload_to_c2':False,
'plottype':'timeplot', 'plottype':'timeplot',
'file': f, 'file': f,
'rpe':6,
} }
form = DocumentsForm(form_data,file_data) form = DocumentsForm(form_data,file_data)
@@ -313,6 +321,7 @@ class ViewTest(TestCase):
'upload_to_c2':False, 'upload_to_c2':False,
'plottype':'timeplot', 'plottype':'timeplot',
'file': f, 'file': f,
'rpe':6,
} }
form = DocumentsForm(form_data,file_data) form = DocumentsForm(form_data,file_data)
@@ -350,6 +359,7 @@ class ViewTest(TestCase):
'upload_to_c2':False, 'upload_to_c2':False,
'plottype':'timeplot', 'plottype':'timeplot',
'file': f, 'file': f,
'rpe':6,
} }
form = DocumentsForm(form_data,file_data) form = DocumentsForm(form_data,file_data)
@@ -389,6 +399,7 @@ class ViewTest(TestCase):
'upload_to_c2':False, 'upload_to_c2':False,
'plottype':'timeplot', 'plottype':'timeplot',
'file': f, 'file': f,
'rpe':6,
} }
form = DocumentsForm(form_data,file_data) form = DocumentsForm(form_data,file_data)
@@ -424,6 +435,7 @@ class ViewTest(TestCase):
'make_plot':False, 'make_plot':False,
'upload_to_c2':False, 'upload_to_c2':False,
'plottype':'timeplot', 'plottype':'timeplot',
'rpe':1,
'file': f, 'file': f,
} }
@@ -459,6 +471,7 @@ class ViewTest(TestCase):
'boattype':'1x', 'boattype':'1x',
'notes':'aap noot mies', 'notes':'aap noot mies',
'make_plot':False, 'make_plot':False,
'rpe':1,
'upload_to_c2':False, 'upload_to_c2':False,
'plottype':'timeplot', 'plottype':'timeplot',
'file': f, 'file': f,
@@ -531,6 +544,7 @@ class ViewTest(TestCase):
file_data = {'file': f} file_data = {'file': f}
form_data = { form_data = {
'title':'test', 'title':'test',
'rpe':1,
'workouttype':'water', 'workouttype':'water',
'boattype':'1x', 'boattype':'1x',
'notes':'aap noot mies', 'notes':'aap noot mies',
@@ -570,6 +584,7 @@ class ViewTest(TestCase):
'make_plot':False, 'make_plot':False,
'upload_to_c2':False, 'upload_to_c2':False,
'plottype':'timeplot', 'plottype':'timeplot',
'rpe':4,
'file': f, 'file': f,
} }
@@ -623,35 +638,37 @@ class ViewTest(TestCase):
@patch('rowers.dataprep.create_engine') @patch('rowers.dataprep.create_engine')
def test_upload_view_RP_interval(self, mocked_sqlalchemy): def test_upload_view_RP_interval(self, mocked_sqlalchemy):
self.c.login(username='john',password='koeinsloot') with transaction.atomic():
self.c.login(username='john',password='koeinsloot')
filename = 'rowers/tests/testdata/RP_interval.csv' filename = 'rowers/tests/testdata/RP_interval.csv'
f = open(filename,'rb') f = open(filename,'rb')
file_data = {'file': f} file_data = {'file': f}
form_data = { form_data = {
'title':'test', 'title':'test',
'workouttype':'rower', 'workouttype':'rower',
'boattype':'1x', 'boattype':'1x',
'notes':'aap noot mies', 'notes':'aap noot mies',
'make_plot':False, 'make_plot':False,
'upload_to_c2':False, 'upload_to_c2':False,
'plottype':'timeplot', 'plottype':'timeplot',
'file': f, 'rpe':1,
} 'file': f,
}
form = DocumentsForm(form_data,file_data) form = DocumentsForm(form_data,file_data)
response = self.c.post('/rowers/workout/upload/', form_data, follow=True) response = self.c.post('/rowers/workout/upload/', form_data, follow=True)
self.assertRedirects(response, expected_url='/rowers/workout/'+encoded1+'/edit/', self.assertRedirects(response, expected_url='/rowers/workout/'+encoded1+'/edit/',
status_code=302,target_status_code=200) status_code=302,target_status_code=200)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
w = Workout.objects.get(id=1) w = Workout.objects.get(id=1)
f_to_be_deleted = w.csvfilename f_to_be_deleted = w.csvfilename
try: try:
os.remove(f_to_be_deleted+'.gz') os.remove(f_to_be_deleted+'.gz')
except (FileNotFoundError,OSError): except (FileNotFoundError,OSError):
pass pass
@@ -667,6 +684,7 @@ class ViewTest(TestCase):
'workouttype':'rower', 'workouttype':'rower',
'boattype':'1x', 'boattype':'1x',
'notes':'aap noot mies', 'notes':'aap noot mies',
'rpe':4,
'make_plot':False, 'make_plot':False,
'upload_to_c2':False, 'upload_to_c2':False,
'plottype':'timeplot', 'plottype':'timeplot',
@@ -699,6 +717,7 @@ class ViewTest(TestCase):
'workouttype':'rower', 'workouttype':'rower',
'boattype':'1x', 'boattype':'1x',
'notes':'aap noot mies', 'notes':'aap noot mies',
'rpe':4,
'make_plot':False, 'make_plot':False,
'upload_to_c2':False, 'upload_to_c2':False,
'plottype':'timeplot', 'plottype':'timeplot',
@@ -731,6 +750,7 @@ class ViewTest(TestCase):
'workouttype':'rower', 'workouttype':'rower',
'boattype':'1x', 'boattype':'1x',
'notes':'aap noot mies', 'notes':'aap noot mies',
'rpe':4,
'make_plot':False, 'make_plot':False,
'upload_to_c2':False, 'upload_to_c2':False,
'plottype':'timeplot', 'plottype':'timeplot',
@@ -762,6 +782,7 @@ class ViewTest(TestCase):
'title':'test', 'title':'test',
'workouttype':'rower', 'workouttype':'rower',
'boattype':'1x', 'boattype':'1x',
'rpe':4,
'notes':'aap noot mies', 'notes':'aap noot mies',
'make_plot':False, 'make_plot':False,
'upload_to_c2':False, 'upload_to_c2':False,

View File

@@ -10,7 +10,9 @@ nu = datetime.datetime.now()
tested = [ tested = [
'/rowers/me/delete/' '/rowers/me/delete/',
'/rowers/performancemanager/'
] ]
#@pytest.mark.django_db #@pytest.mark.django_db
@@ -76,7 +78,7 @@ class URLTests(TestCase):
'/rowers/agegroupcp/30/1/', '/rowers/agegroupcp/30/1/',
'/rowers/agegrouprecords/male/hwt/', '/rowers/agegrouprecords/male/hwt/',
'/rowers/agegrouprecords/male/hwt/2000m/', '/rowers/agegrouprecords/male/hwt/2000m/',
'/rowers/agegrouprecords/male/hwt/2000min/', '/rowers/agegrouprecords/male/hwt/30min/',
'/rowers/ajax_agegroup/45/hwt/male/1/', '/rowers/ajax_agegroup/45/hwt/male/1/',
'/rowers/analysis/', '/rowers/analysis/',
'/rowers/analysis/user/1/', '/rowers/analysis/user/1/',
@@ -240,6 +242,8 @@ class URLTests(TestCase):
# '/rowers/workouts-join-select/2016-01-01/2016-12-31/', # '/rowers/workouts-join-select/2016-01-01/2016-12-31/',
] ]
# urlstotest = ['/rowers/createplan/user/1/'] # urlstotest = ['/rowers/createplan/user/1/']
lijst = [] lijst = []

View File

@@ -585,8 +585,11 @@ def addmanual_view(request,raceid=0):
weightcategory = form.cleaned_data['weightcategory'] weightcategory = form.cleaned_data['weightcategory']
adaptiveclass = form.cleaned_data['adaptiveclass'] adaptiveclass = form.cleaned_data['adaptiveclass']
distance = form.cleaned_data['distance'] distance = form.cleaned_data['distance']
rpe = form.cleaned_data['rpe'] try:
if not rpe: rpe = form.cleaned_data['rpe']
if not rpe:
rpe = -1
except KeyError:
rpe = -1 rpe = -1
notes = form.cleaned_data['notes'] notes = form.cleaned_data['notes']
thetimezone = form.cleaned_data['timezone'] thetimezone = form.cleaned_data['timezone']
@@ -4361,8 +4364,11 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
notes = form.cleaned_data['notes'] notes = form.cleaned_data['notes']
newdragfactor = form.cleaned_data['dragfactor'] newdragfactor = form.cleaned_data['dragfactor']
thetimezone = form.cleaned_data['timezone'] thetimezone = form.cleaned_data['timezone']
rpe = form.cleaned_data['rpe'] try:
if not rpe: rpe = form.cleaned_data['rpe']
if not rpe:
rpe = -1
except KeyError:
rpe = -1 rpe = -1
try: try:
@@ -4874,6 +4880,10 @@ def workout_upload_api(request):
t = form.cleaned_data['title'] t = form.cleaned_data['title']
boattype = form.cleaned_data['boattype'] boattype = form.cleaned_data['boattype']
workouttype = form.cleaned_data['workouttype'] workouttype = form.cleaned_data['workouttype']
try:
rpe = form.cleaned_data['rpe']
except KeyError:
rpe = -1
if rowerform.is_valid(): if rowerform.is_valid():
u = rowerform.cleaned_data['user'] u = rowerform.cleaned_data['user']
r = getrower(u) r = getrower(u)
@@ -4929,6 +4939,7 @@ def workout_upload_api(request):
boattype=boattype, boattype=boattype,
makeprivate=makeprivate, makeprivate=makeprivate,
title = t, title = t,
rpe=rpe,
notes=notes, notes=notes,
uploadoptions=post_data, uploadoptions=post_data,
) )
@@ -5049,6 +5060,13 @@ def workout_upload_view(request,
except KeyError: except KeyError:
boattype = '1x' boattype = '1x'
try:
rpe = docformoptions['rpe']
if not rpe:
rpe = -1
except KeyError:
rpe = -1
try: try:
notes = docformoptions['notes'] notes = docformoptions['notes']
except KeyError: except KeyError:
@@ -5126,6 +5144,10 @@ def workout_upload_view(request,
t = form.cleaned_data['title'] t = form.cleaned_data['title']
workouttype = form.cleaned_data['workouttype'] workouttype = form.cleaned_data['workouttype']
boattype = form.cleaned_data['boattype'] boattype = form.cleaned_data['boattype']
try:
rpe = form.cleaned_data['rpe']
except KeyError:
rpe = -1
request.session['docformoptions'] = { request.session['docformoptions'] = {
'workouttype':workouttype, 'workouttype':workouttype,
@@ -5166,6 +5188,7 @@ def workout_upload_view(request,
'upload_to_TrainingPeaks':upload_to_tp, 'upload_to_TrainingPeaks':upload_to_tp,
'landingpage':landingpage, 'landingpage':landingpage,
'boattype': boattype, 'boattype': boattype,
'rpe':rpe,
'workouttype': workouttype, 'workouttype': workouttype,
} }
@@ -5181,6 +5204,7 @@ def workout_upload_view(request,
workouttype=workouttype, workouttype=workouttype,
workoutsource=workoutsource, workoutsource=workoutsource,
boattype=boattype, boattype=boattype,
rpe=rpe,
makeprivate=makeprivate, makeprivate=makeprivate,
title = t, title = t,
notes=notes, notes=notes,