Private
Public Access
1
0

further coverage increases

This commit is contained in:
Sander Roosendaal
2021-04-13 19:20:04 +02:00
parent 08dbd43b61
commit 9c6cf18ee5
8 changed files with 208 additions and 205 deletions

View File

@@ -222,8 +222,8 @@ def get_nk_workout_list(user,fake=False,startTime=0,endTime=0):
else: else:
# ready to fetch. Hurray # ready to fetch. Hurray
if not endTime: if not endTime:
endTime = int(arrow.now().timestamp())*1000 endTime = arrow.now()+timedelta(days=1)
endTime = str(endTime) endTime = str(int(endTime.timestamp())*1000)
if not startTime: if not startTime:
startTime = arrow.now()-timedelta(days=30) startTime = arrow.now()-timedelta(days=30)
startTime = str(int(startTime.timestamp())*1000) startTime = str(int(startTime.timestamp())*1000)

View File

@@ -2818,6 +2818,7 @@ def handle_setcp(strokesdf,filename,workoutid,debug=False,**kwargs):
except FileNotFoundError: except FileNotFoundError:
pass pass
if not strokesdf.empty: if not strokesdf.empty:
try: try:
totaltime = strokesdf['time'].max() totaltime = strokesdf['time'].max()
except KeyError: except KeyError:
@@ -2827,6 +2828,7 @@ def handle_setcp(strokesdf,filename,workoutid,debug=False,**kwargs):
except KeyError: except KeyError:
powermean = 0 powermean = 0
if powermean != 0: if powermean != 0:
thesecs = totaltime thesecs = totaltime
maxt = 1.05 * thesecs maxt = 1.05 * thesecs

View File

@@ -5,7 +5,7 @@ pytestmark = pytest.mark.django_db
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
import re import re
from nose_parameterized import parameterized from parameterized import parameterized
from django.test import TestCase, Client,override_settings from django.test import TestCase, Client,override_settings
from django.core.management import call_command from django.core.management import call_command
from django.utils.six import StringIO from django.utils.six import StringIO

View File

@@ -13,7 +13,7 @@ encoded13 = str(encoder.encode_hex(13))
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
import re import re
from nose_parameterized import parameterized from parameterized import parameterized
from django.test import TestCase, Client,override_settings from django.test import TestCase, Client,override_settings
from django.core.management import call_command from django.core.management import call_command
from django.utils.six import StringIO from django.utils.six import StringIO

View File

@@ -308,6 +308,25 @@ class WorkoutViewTest(TestCase):
response = self.c.get(url,follow=True) response = self.c.get(url,follow=True)
self.assertEqual(response.status_code,200) self.assertEqual(response.status_code,200)
# Stacked Flex Chart
url = reverse('workout_flexchart_stacked_view',kwargs={
'id': encoder.encode_hex(self.wwater.id),
})
response = self.c.get(url,follow=True)
self.assertEqual(response.status_code,200)
form_data = {
'xparam':'distance',
'yparam1':'power',
'yparam2':'driveenergy',
'yparam3':'hr',
'yparam4':'strokedistance'
}
response = self.c.post(url,form_data)
self.assertEqual(response.status_code,200)
url = reverse('workout_erase_column_view',kwargs={'id':encoder.encode_hex(self.wwater.id),'column':'hr'}) url = reverse('workout_erase_column_view',kwargs={'id':encoder.encode_hex(self.wwater.id),'column':'hr'})
expected_url = reverse('workout_data_view',kwargs={'id':encoder.encode_hex(self.wwater.id)}) expected_url = reverse('workout_data_view',kwargs={'id':encoder.encode_hex(self.wwater.id)})

View File

@@ -45,6 +45,13 @@ workout run
copy('rowers/tests/testdata/emails/colin.csv',a2) copy('rowers/tests/testdata/emails/colin.csv',a2)
a3 = 'media/mailbox_attachments/colin4.csv' a3 = 'media/mailbox_attachments/colin4.csv'
copy('rowers/tests/testdata/emails/colin.csv',a3) copy('rowers/tests/testdata/emails/colin.csv',a3)
a4 = 'media/mailbox_attachments/colin5.csv'
copy('rowers/tests/testdata/emails/colin.csv',a4)
a5 = 'media/mailbox_attachments/colin6.csv'
copy('rowers/tests/testdata/emails/colin.csv',a5)
a6 = 'media/mailbox_attachments/colin7.csv'
copy('rowers/tests/testdata/emails/colin.csv',a6)
a = MessageAttachment(message=m,document=a2[6:]) a = MessageAttachment(message=m,document=a2[6:])
a.save() a.save()
@@ -88,6 +95,29 @@ workout run
self.assertEqual(w.name,'test') self.assertEqual(w.name,'test')
self.assertEqual(w.notes,'aap noot mies') self.assertEqual(w.notes,'aap noot mies')
# test exceptions
secret = form_data.pop('secret')
form_data['file'] = 'media/mailbox_attachments/colin5.csv'
response = self.c.post(url,form_data,HTTP_HOST='127.0.0.1:4533')
self.assertEqual(response.status_code,400)
form_data['secret'] = 'wrong'
form_data['file'] = 'media/mailbox_attachments/colin6.csv'
response = self.c.post(url,form_data,HTTP_HOST='127.0.0.1:4533')
self.assertEqual(response.status_code,403)
form_data['secret'] = secret
filename = form_data.pop('file')
response = self.c.post(url,form_data,HTTP_HOST='127.0.0.1:4533')
self.assertEqual(response.status_code,400)
form_data['file'] = filename
os.remove(filename)
response = self.c.post(url,form_data,HTTP_HOST='127.0.0.1:4533')
self.assertEqual(response.status_code,400)
@patch('rowers.dataprep.create_engine') @patch('rowers.dataprep.create_engine')

View File

@@ -56,10 +56,18 @@ class ViewTest(TestCase):
'rpe':6, 'rpe':6,
'upload_to_c2':False, 'upload_to_c2':False,
'plottype':'timeplot', 'plottype':'timeplot',
'landingpage':'workout_edit_view',
'raceid':0,
'file': f, 'file': f,
} }
request = RequestFactory()
request.user = self.u
form = DocumentsForm(form_data,file_data) form = DocumentsForm(form_data,file_data)
optionsform = UploadOptionsForm(form_data,request=request)
self.assertTrue(optionsform.is_valid())
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/',
@@ -105,6 +113,8 @@ class ViewTest(TestCase):
'boattype':'1x', 'boattype':'1x',
'rpe':4, 'rpe':4,
'dragfactor':'112', 'dragfactor':'112',
'raceid':0,
'landingpage':'workout_edit_view',
'private':True, 'private':True,
'notes':'noot mies', 'notes':'noot mies',
} }
@@ -153,6 +163,8 @@ class ViewTest(TestCase):
'upload_to_RunKeeper':False, 'upload_to_RunKeeper':False,
'upload_to_MapMyFitness':False, 'upload_to_MapMyFitness':False,
'plottype':'timeplot', 'plottype':'timeplot',
'raceid':0,
'landingpage':'workout_edit_view',
'file': f, 'file': f,
'makeprivate':False, 'makeprivate':False,
'landingpage':'workout_edit_view', 'landingpage':'workout_edit_view',
@@ -197,6 +209,8 @@ class ViewTest(TestCase):
'make_plot':False, 'make_plot':False,
'upload_to_c2':False, 'upload_to_c2':False,
'plottype':'timeplot', 'plottype':'timeplot',
'raceid':0,
'landingpage':'workout_edit_view',
'file': f, 'file': f,
'rpe':6, 'rpe':6,
} }
@@ -234,6 +248,8 @@ class ViewTest(TestCase):
'make_plot':False, 'make_plot':False,
'upload_to_c2':False, 'upload_to_c2':False,
'plottype':'timeplot', 'plottype':'timeplot',
'raceid':0,
'landingpage':'workout_edit_view',
'file': f, 'file': f,
'rpe':6, 'rpe':6,
} }
@@ -269,6 +285,8 @@ class ViewTest(TestCase):
'make_plot':False, 'make_plot':False,
'upload_to_c2':False, 'upload_to_c2':False,
'plottype':'timeplot', 'plottype':'timeplot',
'raceid':0,
'landingpage':'workout_edit_view',
'file': f, 'file': f,
'rpe':6, 'rpe':6,
} }
@@ -320,6 +338,8 @@ class ViewTest(TestCase):
'make_plot':False, 'make_plot':False,
'upload_to_c2':False, 'upload_to_c2':False,
'plottype':'timeplot', 'plottype':'timeplot',
'raceid':0,
'landingpage':'workout_edit_view',
'file': f, 'file': f,
'rpe':6, 'rpe':6,
} }
@@ -358,6 +378,8 @@ class ViewTest(TestCase):
'make_plot':False, 'make_plot':False,
'upload_to_c2':False, 'upload_to_c2':False,
'plottype':'timeplot', 'plottype':'timeplot',
'raceid':0,
'landingpage':'workout_edit_view',
'file': f, 'file': f,
'rpe':6, 'rpe':6,
} }
@@ -396,6 +418,8 @@ class ViewTest(TestCase):
'make_plot':False, 'make_plot':False,
'upload_to_c2':False, 'upload_to_c2':False,
'plottype':'timeplot', 'plottype':'timeplot',
'raceid':0,
'landingpage':'workout_edit_view',
'file': f, 'file': f,
'rpe':6, 'rpe':6,
} }
@@ -450,6 +474,8 @@ class ViewTest(TestCase):
'make_plot':False, 'make_plot':False,
'upload_to_c2':False, 'upload_to_c2':False,
'plottype':'timeplot', 'plottype':'timeplot',
'raceid':0,
'landingpage':'workout_edit_view',
'file': f, 'file': f,
'rpe':6, 'rpe':6,
} }
@@ -487,6 +513,8 @@ class ViewTest(TestCase):
'make_plot':False, 'make_plot':False,
'upload_to_c2':False, 'upload_to_c2':False,
'plottype':'timeplot', 'plottype':'timeplot',
'raceid':0,
'landingpage':'workout_edit_view',
'rpe':1, 'rpe':1,
'file': f, 'file': f,
} }
@@ -525,6 +553,8 @@ class ViewTest(TestCase):
'make_plot':False, 'make_plot':False,
'rpe':1, 'rpe':1,
'upload_to_c2':False, 'upload_to_c2':False,
'raceid':0,
'landingpage':'workout_edit_view',
'plottype':'timeplot', 'plottype':'timeplot',
'file': f, 'file': f,
} }
@@ -564,6 +594,8 @@ class ViewTest(TestCase):
'notes':'aap noot mies', 'notes':'aap noot mies',
'make_plot':False, 'make_plot':False,
'upload_to_c2':False, 'upload_to_c2':False,
'raceid':0,
'landingpage':'workout_edit_view',
'plottype':'timeplot', 'plottype':'timeplot',
'file': f, 'file': f,
} }
@@ -602,6 +634,8 @@ class ViewTest(TestCase):
'notes':'aap noot mies', 'notes':'aap noot mies',
'make_plot':False, 'make_plot':False,
'upload_to_c2':False, 'upload_to_c2':False,
'raceid':0,
'landingpage':'workout_edit_view',
'plottype':'timeplot', 'plottype':'timeplot',
'file': f, 'file': f,
} }
@@ -636,6 +670,8 @@ class ViewTest(TestCase):
'make_plot':False, 'make_plot':False,
'upload_to_c2':False, 'upload_to_c2':False,
'plottype':'timeplot', 'plottype':'timeplot',
'raceid':0,
'landingpage':'workout_edit_view',
'rpe':4, 'rpe':4,
'file': f, 'file': f,
} }
@@ -670,6 +706,8 @@ class ViewTest(TestCase):
'make_plot':False, 'make_plot':False,
'upload_to_c2':False, 'upload_to_c2':False,
'plottype':'timeplot', 'plottype':'timeplot',
'raceid':0,
'landingpage':'workout_edit_view',
'file': f, 'file': f,
} }
@@ -704,6 +742,8 @@ class ViewTest(TestCase):
'make_plot':False, 'make_plot':False,
'upload_to_c2':False, 'upload_to_c2':False,
'plottype':'timeplot', 'plottype':'timeplot',
'raceid':0,
'landingpage':'workout_edit_view',
'rpe':1, 'rpe':1,
'file': f, 'file': f,
} }
@@ -740,6 +780,8 @@ class ViewTest(TestCase):
'make_plot':False, 'make_plot':False,
'upload_to_c2':False, 'upload_to_c2':False,
'plottype':'timeplot', 'plottype':'timeplot',
'raceid':0,
'landingpage':'workout_edit_view',
'file': f, 'file': f,
} }
@@ -773,6 +815,8 @@ class ViewTest(TestCase):
'make_plot':False, 'make_plot':False,
'upload_to_c2':False, 'upload_to_c2':False,
'plottype':'timeplot', 'plottype':'timeplot',
'raceid':0,
'landingpage':'workout_edit_view',
'file': f, 'file': f,
} }
@@ -806,6 +850,8 @@ class ViewTest(TestCase):
'make_plot':False, 'make_plot':False,
'upload_to_c2':False, 'upload_to_c2':False,
'plottype':'timeplot', 'plottype':'timeplot',
'raceid':0,
'landingpage':'workout_edit_view',
'file': f, 'file': f,
} }
@@ -839,6 +885,8 @@ class ViewTest(TestCase):
'make_plot':False, 'make_plot':False,
'upload_to_c2':False, 'upload_to_c2':False,
'plottype':'timeplot', 'plottype':'timeplot',
'raceid':0,
'landingpage':'workout_edit_view',
'file': f, 'file': f,
} }

View File

@@ -3279,7 +3279,7 @@ def workout_data_view(request, id=0):
try: try:
datadf = datadf[tcols] datadf = datadf[tcols]
except KeyError: except KeyError: # pragma: no cover
# tcols = list(set(datadf.columns(tolist)+tcols)) # tcols = list(set(datadf.columns(tolist)+tcols))
try: try:
datadf = datadf[tcols] datadf = datadf[tcols]
@@ -3348,7 +3348,7 @@ def workout_stats_view(request,id=0,message="",successmessage=""):
] ]
workstrokesonly = True workstrokesonly = True
if request.method == 'POST' and 'workstrokesonly' in request.POST: if request.method == 'POST' and 'workstrokesonly' in request.POST: # pragma: no cover
workstrokesonly = str2bool(request.POST['workstrokesonly']) workstrokesonly = str2bool(request.POST['workstrokesonly'])
@@ -3519,7 +3519,7 @@ def workflow_default_view(request):
r = getrower(request.user) r = getrower(request.user)
if r.defaultlandingpage == 'workout_edit_view': if r.defaultlandingpage == 'workout_edit_view':
r.defaultlandingpage = 'workout_workflow_view' r.defaultlandingpage = 'workout_workflow_view'
else: else: # pragma: no cover
r.defaultlandingpage = 'workout_edit_view' r.defaultlandingpage = 'workout_edit_view'
r.save() r.save()
@@ -3543,13 +3543,9 @@ def workout_workflow_config2_view(request,userid=0):
r = getrequestrower(request,userid=userid,notpermanent=True) r = getrequestrower(request,userid=userid,notpermanent=True)
MiddlePanelFormSet = formset_factory(WorkFlowMiddlePanelElement,extra=1) MiddlePanelFormSet = formset_factory(WorkFlowMiddlePanelElement,extra=1)
LeftPanelFormSet = formset_factory(WorkFlowLeftPanelElement,extra=1)
if request.method == 'POST': if request.method == 'POST':
wasmiddle = [1 for key,value in request.POST.items() if 'middlepanel' in key.lower()]
wasleft = [1 for key,valye in request.POST.items() if 'leftpanel' in key.lower()]
if wasmiddle:
middlepanel_formset = MiddlePanelFormSet(request.POST, middlepanel_formset = MiddlePanelFormSet(request.POST,
prefix='middlepanel') prefix='middlepanel')
newmiddlepanel = [] newmiddlepanel = []
@@ -3564,35 +3560,12 @@ def workout_workflow_config2_view(request,userid=0):
r.workflowmiddlepanel = newmiddlepanel r.workflowmiddlepanel = newmiddlepanel
try: try:
r.save() r.save()
except IntegrityError: except IntegrityError: # pragma: no cover
messages.error(request,'Something went wrong') messages.error(request,'Something went wrong')
if wasleft:
leftpanel_formset = LeftPanelFormSet(request.POST,
prefix='leftpanel')
newleftpanel = []
if leftpanel_formset.is_valid():
for form in leftpanel_formset:
value = form.cleaned_data.get('panel')
if value != 'None':
newleftpanel.append(value)
newleftpanel = [i for i in newleftpanel if i != None]
r.workflowleftpanel = newleftpanel
try:
r.save()
except IntegrityError:
messages.error(request,'Something went wrong')
leftpanelform_data = [{'panel':panel}
for panel in r.workflowleftpanel]
middlepanelform_data = [{'panel':panel} middlepanelform_data = [{'panel':panel}
for panel in r.workflowmiddlepanel] for panel in r.workflowmiddlepanel]
leftpanel_formset = LeftPanelFormSet(initial=leftpanelform_data,
prefix='leftpanel')
middlepanel_formset = MiddlePanelFormSet(initial=middlepanelform_data, middlepanel_formset = MiddlePanelFormSet(initial=middlepanelform_data,
prefix='middlepanel') prefix='middlepanel')
@@ -3602,7 +3575,6 @@ def workout_workflow_config2_view(request,userid=0):
return render(request,tmplt, return render(request,tmplt,
{ {
'rower':r, 'rower':r,
'leftpanel_formset':leftpanel_formset,
'middlepanel_formset':middlepanel_formset, 'middlepanel_formset':middlepanel_formset,
'workoutid': workoutid, 'workoutid': workoutid,
}) })
@@ -3707,7 +3679,7 @@ def workout_flexchart3_view(request,*args,**kwargs):
except KeyError: # pragma: no cover except KeyError: # pragma: no cover
raise Http404("Invalid workout number") raise Http404("Invalid workout number")
if 'promember' in kwargs: if 'promember' in kwargs: # pragma: no cover
promember = kwargs['promember'] promember = kwargs['promember']
else: else:
promember = 0 promember = 0
@@ -3769,7 +3741,7 @@ def workout_flexchart3_view(request,*args,**kwargs):
else: else:
if favorites: if favorites:
yparam2 = favorites[favoritenr].yparam2 yparam2 = favorites[favoritenr].yparam2
if yparam2 == '': if yparam2 == '': # pragma: no cover
yparam2 = 'None' yparam2 = 'None'
else: else:
yparam2 = 'hr' yparam2 = 'hr'
@@ -3783,11 +3755,11 @@ def workout_flexchart3_view(request,*args,**kwargs):
favoritechartnotes = '' favoritechartnotes = ''
else: else:
favoritechartnotes = '' favoritechartnotes = ''
else: else: # pragma: no cover
favoritechartnotes = '' favoritechartnotes = ''
favoritenr = 0 favoritenr = 0
if 'plottype' in kwargs: if 'plottype' in kwargs: # pragma: no cover
plottype = kwargs['plottype'] plottype = kwargs['plottype']
else: else:
if favorites: if favorites:
@@ -3795,7 +3767,7 @@ def workout_flexchart3_view(request,*args,**kwargs):
else: else:
plottype = 'line' plottype = 'line'
if 'workstrokesonly' in kwargs: if 'workstrokesonly' in kwargs: # pragma: no cover
workstrokesonly = kwargs['workstrokesonly'] workstrokesonly = kwargs['workstrokesonly']
else: else:
if favorites: if favorites:
@@ -3820,7 +3792,7 @@ def workout_flexchart3_view(request,*args,**kwargs):
reststrokes=reststrokes) reststrokes=reststrokes)
f.save() f.save()
except KeyError: except KeyError: # pragma: no cover
messages.error(request,'We cannot save the ad hoc metrics in a favorite chart') messages.error(request,'We cannot save the ad hoc metrics in a favorite chart')
if request.method == 'POST' and 'xaxis' in request.POST: if request.method == 'POST' and 'xaxis' in request.POST:
@@ -3846,13 +3818,13 @@ def workout_flexchart3_view(request,*args,**kwargs):
if not promember: if not promember:
for name,d in rowingmetrics: for name,d in rowingmetrics:
if d['type'] != 'basic': if d['type'] != 'basic':
if xparam == name: if xparam == name: # pragma: no cover
xparam = 'time' xparam = 'time'
messages.info(request,'To use '+d['verbose_name']+', you have to be Pro member') messages.info(request,'To use '+d['verbose_name']+', you have to be Pro member')
if yparam1 == name: if yparam1 == name: # pragma: no cover
yparam1 = 'pace' yparam1 = 'pace'
messages.info(request,'To use '+d['verbose_name']+', you have to be Pro member') messages.info(request,'To use '+d['verbose_name']+', you have to be Pro member')
if yparam2 == name: if yparam2 == name: # pragma: no cover
yparam2 = 'spm' yparam2 = 'spm'
messages.info(request,'To use '+d['verbose_name']+', you have to be Pro member') messages.info(request,'To use '+d['verbose_name']+', you have to be Pro member')
@@ -3973,7 +3945,7 @@ def workout_flexchart3_view(request,*args,**kwargs):
def workout_flexchart_stacked_view(request,*args,**kwargs): def workout_flexchart_stacked_view(request,*args,**kwargs):
try: try:
id = kwargs['id'] id = kwargs['id']
except KeyError: except KeyError: # pragma: no cover
raise Http404("Invalid workout number") raise Http404("Invalid workout number")
workout = get_workout(id) workout = get_workout(id)
@@ -4006,7 +3978,7 @@ def workout_flexchart_stacked_view(request,*args,**kwargs):
mode=workout.workouttype, mode=workout.workouttype,
) )
if comment is not None: if comment is not None: # pragma: no cover
messages.error(request,comment) messages.error(request,comment)
initial = { initial = {
@@ -4118,7 +4090,7 @@ def workout_otwpowerplot_view(request,id=0,message="",successmessage=""):
def workout_unsubscribe_view(request,id=0): def workout_unsubscribe_view(request,id=0):
w = get_workout(id) w = get_workout(id)
if w.privacy == 'private' and w.user.user != request.user: if w.privacy == 'private' and w.user.user != request.user: # pragma: no cover
return HttpResponseForbidden("Permission error") return HttpResponseForbidden("Permission error")
comments = WorkoutComment.objects.filter(workout=w, comments = WorkoutComment.objects.filter(workout=w,
@@ -4148,7 +4120,7 @@ def workout_unsubscribe_view(request,id=0):
def workout_comment_view(request,id=0): def workout_comment_view(request,id=0):
w = get_workout(id) w = get_workout(id)
if w.privacy == 'private' and w.user.user != request.user: if w.privacy == 'private' and w.user.user != request.user: # pragma: no cover
return HttpResponseForbidden("Permission error") return HttpResponseForbidden("Permission error")
comments = WorkoutComment.objects.filter(workout=w).order_by("created") comments = WorkoutComment.objects.filter(workout=w).order_by("created")
@@ -4161,7 +4133,7 @@ def workout_comment_view(request,id=0):
cd = form.cleaned_data cd = form.cleaned_data
comment = cd['comment'] comment = cd['comment']
comment = bleach.clean(comment) comment = bleach.clean(comment)
try: try: # pragma: no cover
if isinstance(comment,unicode): if isinstance(comment,unicode):
comment = comment.encode('utf8') comment = comment.encode('utf8')
elif isinstance(comment, str): elif isinstance(comment, str):
@@ -4183,7 +4155,7 @@ def workout_comment_view(request,id=0):
comment = comment, comment = comment,
url = url, url = url,
) )
if request.user != r.user: if request.user != r.user: # pragma: no cover
a_messages.info(r.user,message.encode('ascii','ignore')) a_messages.info(r.user,message.encode('ascii','ignore'))
res = myqueue(queuehigh, res = myqueue(queuehigh,
@@ -4197,7 +4169,7 @@ def workout_comment_view(request,id=0):
) )
commenters = {oc.user for oc in comments if oc.notification} commenters = {oc.user for oc in comments if oc.notification}
for u in commenters: for u in commenters: # pragma: no cover
a_messages.info(u,message) a_messages.info(u,message)
if u != request.user and u != r.user: if u != request.user and u != r.user:
ocr = Rower.objects.get(user=u) ocr = Rower.objects.get(user=u)
@@ -4223,7 +4195,7 @@ def workout_comment_view(request,id=0):
form = WorkoutCommentForm() form = WorkoutCommentForm()
g = GraphImage.objects.filter(workout=w).order_by("-creationdatetime") g = GraphImage.objects.filter(workout=w).order_by("-creationdatetime")
for i in g: for i in g: # pragma: no cover
try: try:
width,height = Image.open(i.filename).size width,height = Image.open(i.filename).size
i.width = width i.width = width
@@ -4275,7 +4247,7 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
row = get_workoutuser(id,request) row = get_workoutuser(id,request)
if request.user.rower.rowerplan == 'basic' and 'speedcoach2' in row.workoutsource: if request.user.rower.rowerplan == 'basic' and 'speedcoach2' in row.workoutsource: # pragma: no cover
data = getsmallrowdata_db(['wash'],ids=[encoder.decode_hex(id)]) data = getsmallrowdata_db(['wash'],ids=[encoder.decode_hex(id)])
try: try:
if data['wash'].std() != 0: if data['wash'].std() != 0:
@@ -4287,7 +4259,7 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
except: except:
pass pass
if request.user.rower.rowerplan == 'basic' and 'nklinklogbook' in row.workoutsource: if request.user.rower.rowerplan == 'basic' and 'nklinklogbook' in row.workoutsource: # pragma: no cover
data = getsmallrowdata_db(['wash'],ids=[encoder.decode_hex(id)]) data = getsmallrowdata_db(['wash'],ids=[encoder.decode_hex(id)])
try: try:
if data['wash'].std() != 0: if data['wash'].std() != 0:
@@ -4321,41 +4293,28 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
thetimezone = form.cleaned_data['timezone'] thetimezone = form.cleaned_data['timezone']
try: try:
rpe = form.cleaned_data['rpe'] rpe = form.cleaned_data['rpe']
if not rpe: if not rpe: # pragma: no cover
rpe = -1 rpe = -1
except KeyError: # pragma: no cover except KeyError: # pragma: no cover
rpe = -1 rpe = -1
ps = form.cleaned_data.get('plannedsession',None) ps = form.cleaned_data.get('plannedsession',None)
try: boattype = request.POST.get('boattype',Workout.objects.get(id=encoder.decode_hex(id)).boattype)
boattype = request.POST['boattype'] privacy = request.POST.get('privacy',Workout.objects.get(id=encoder.decode_hex(id)).privacy)
except KeyError: rankingpiece = form.cleaned_data.get('rankingpiece',Workout.objects.get(id=row.id).rankingpiece)
boattype = Workout.objects.get(id=encoder.decode_hex(id)).boattype duplicate = form.cleaned_data.get('duplicate',Workout.objects.get(id=row.id).duplicate)
try:
privacy = request.POST['privacy']
except KeyError:
privacy = Workout.objects.get(id=row.id).privacy
try:
rankingpiece = form.cleaned_data['rankingpiece']
except KeyError:
rankingpiece =- Workout.objects.get(id=row.id).rankingpiece
try:
duplicate = form.cleaned_data['duplicate']
except KeyError:
duplicate = Workout.objects.get(id=row.id).duplicate
if private: if private:
privacy = 'private' privacy = 'private'
else: else: # pragma: no cover
privacy = 'visible' privacy = 'visible'
try: try:
startdatetime = datetime.datetime.combine( startdatetime = datetime.datetime.combine(
date,starttime date,starttime
) )
except TypeError: except TypeError: # pragma: no cover
startdatetime = datetime.datetime.combine( startdatetime = datetime.datetime.combine(
date,datetime.datetime.min.time() date,datetime.datetime.min.time()
) )
@@ -4364,18 +4323,18 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
startdatetime = pytz.timezone(thetimezone).localize( startdatetime = pytz.timezone(thetimezone).localize(
startdatetime startdatetime
) )
except UnknownTimeZoneError: except UnknownTimeZoneError: # pragma: no cover
pass pass
try: try:
# aware object can be in any timezone # aware object can be in any timezone
out = startdatetime.astimezone(pytz.utc) out = startdatetime.astimezone(pytz.utc)
except (ValueError, TypeError): except (ValueError, TypeError): # pragma: no cover
startdatetime = timezone.make_aware(startdatetime) startdatetime = timezone.make_aware(startdatetime)
try: try:
startdatetime = startdatetime.astimezone(pytz.timezone(thetimezone)) startdatetime = startdatetime.astimezone(pytz.timezone(thetimezone))
except UnknownTimeZoneError: except UnknownTimeZoneError: # pragma: no cover
thetimezone = 'UTC' thetimezone = 'UTC'
timechanged = (startdatetime != row.startdatetime) timechanged = (startdatetime != row.startdatetime)
@@ -4399,16 +4358,16 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
row.plannedsession = ps row.plannedsession = ps
dragchanged = False dragchanged = False
if newdragfactor != row.dragfactor: if newdragfactor != row.dragfactor: # pragma: no cover
row.dragfactor = newdragfactor row.dragfactor = newdragfactor
dragchanged = True dragchanged = True
try: try:
row.save() row.save()
except IntegrityError: except IntegrityError: # pragma: no cover
pass pass
if ps: if ps: # pragma: no cover
add_workouts_plannedsession([row],ps,row.user) add_workouts_plannedsession([row],ps,row.user)
# change data in csv file # change data in csv file
@@ -4416,7 +4375,7 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
if datachanged: if datachanged:
r = rdata(csvfile=row.csvfilename) r = rdata(csvfile=row.csvfilename)
if dragchanged: if dragchanged:
try: try: # pragma: no cover
r.change_drag(newdragfactor) r.change_drag(newdragfactor)
except AttributeError: except AttributeError:
pass pass
@@ -4429,7 +4388,7 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
successmessage = "Changes saved" successmessage = "Changes saved"
if rankingpiece: if rankingpiece: # pragma: no cover
dataprep.runcpupdate(row.user,type=row.workouttype) dataprep.runcpupdate(row.user,type=row.workouttype)
messages.info(request,successmessage) messages.info(request,successmessage)
@@ -4437,7 +4396,7 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
form = WorkoutForm(instance=row) form = WorkoutForm(instance=row)
g = GraphImage.objects.filter(workout=row).order_by("-creationdatetime") g = GraphImage.objects.filter(workout=row).order_by("-creationdatetime")
for i in g: for i in g: # pragma: no cover
try: try:
width,height = Image.open(i.filename).size width,height = Image.open(i.filename).size
i.width = width i.width = width
@@ -4460,7 +4419,7 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
try: try:
latitude = rowdata.df[' latitude'] latitude = rowdata.df[' latitude']
longitude = rowdata.df[' longitude'] longitude = rowdata.df[' longitude']
if not latitude.std(): if not latitude.std(): # pragma: no cover
hascoordinates = 0 hascoordinates = 0
if not longitude.std(): if not longitude.std():
hascoordinates = 0 hascoordinates = 0
@@ -4599,8 +4558,8 @@ def workout_map_view(request,id=0):
# Image upload # Image upload
@permission_required('workout.change_workout',fn=get_workout_by_opaqueid,raise_exception=True) @permission_required('workout.change_workout',fn=get_workout_by_opaqueid,raise_exception=True)
def workout_uploadimage_view(request,id): def workout_uploadimage_view(request,id): # pragma: no cover
is_ajax = False is_ajax = False # pragma: no cover
if request.is_ajax(): if request.is_ajax():
is_ajax = True is_ajax = True
@@ -4629,7 +4588,7 @@ def workout_uploadimage_view(request,id):
images = GraphImage.objects.filter(workout=w) images = GraphImage.objects.filter(workout=w)
if images.count() >= 6: if images.count() >= 6: # pragma: no cover
message = "You have reached the maximum number of static images for this workout" message = "You have reached the maximum number of static images for this workout"
messages.error(request,message) messages.error(request,message)
url = reverse(r.defaultlandingpage, url = reverse(r.defaultlandingpage,
@@ -4721,7 +4680,7 @@ def workout_add_chart_view(request,id,plotnr=1):
r,w,f1,w.csvfilename,'timeplot',title,plotnr=plotnr, r,w,f1,w.csvfilename,'timeplot',title,plotnr=plotnr,
imagename=imagename imagename=imagename
) )
if res == 0: if res == 0: # pragma: no cover
messages.error(request,jobid) messages.error(request,jobid)
else: else:
try: try:
@@ -4742,7 +4701,7 @@ def workout_add_chart_view(request,id,plotnr=1):
@permission_required('workout.change_workout',fn=get_workout_by_opaqueid,raise_exception=True) @permission_required('workout.change_workout',fn=get_workout_by_opaqueid,raise_exception=True)
def workout_toggle_ranking(request,id=0): def workout_toggle_ranking(request,id=0):
is_ajax = False is_ajax = False
if request.is_ajax(): if request.is_ajax(): # pragma: no cover
is_ajax = True is_ajax = True
row = get_workout_by_opaqueid(request,id) row = get_workout_by_opaqueid(request,id)
@@ -4750,7 +4709,7 @@ def workout_toggle_ranking(request,id=0):
row.rankingpiece = not row.rankingpiece row.rankingpiece = not row.rankingpiece
row.save() row.save()
if is_ajax: if is_ajax: # pragma: no cover
response = JSONResponse({'result':row.rankingpiece}, response = JSONResponse({'result':row.rankingpiece},
content_type='application/json') content_type='application/json')
@@ -4765,7 +4724,7 @@ def workout_toggle_ranking(request,id=0):
@csrf_exempt @csrf_exempt
def workout_upload_api(request): def workout_upload_api(request):
stravaid = '' stravaid = ''
if request.method != 'POST': if request.method != 'POST': # pragma: no cover
message = {'status':'false','message':'this view cannot be accessed through GET'} message = {'status':'false','message':'this view cannot be accessed through GET'}
return JSONResponse(status=403,data=message) return JSONResponse(status=403,data=message)
@@ -4842,9 +4801,9 @@ def workout_upload_api(request):
rpe = form.cleaned_data['rpe'] rpe = form.cleaned_data['rpe']
try: try:
rpe = int(rpe) rpe = int(rpe)
except ValueError: except ValueError: # pragma: no cover
rpe = 0 rpe = 0
except KeyError: except KeyError: # pragma: no cover
rpe = -1 rpe = -1
if rowerform.is_valid(): if rowerform.is_valid():
u = rowerform.cleaned_data['user'] u = rowerform.cleaned_data['user']
@@ -4853,7 +4812,7 @@ def workout_upload_api(request):
if 'useremail' in post_data: if 'useremail' in post_data:
us = User.objects.filter(email=post_data['useremail']) us = User.objects.filter(email=post_data['useremail'])
if len(us): if len(us): # pragma: no cover
u = us[0] u = us[0]
r = getrower(u) r = getrower(u)
else: else:
@@ -4864,12 +4823,12 @@ def workout_upload_api(request):
r = rwr r = rwr
break break
if r is not None and r.emailalternatives is not None: if r is not None and r.emailalternatives is not None:
if post_data['useremail'] not in r.emailalternatives: if post_data['useremail'] not in r.emailalternatives: # pragma: no cover
message = {'status':'false','message':'could not find user'} message = {'status':'false','message':'could not find user'}
return JSONResponse(status=400,data=message) return JSONResponse(status=400,data=message)
if r is None: if r is None: # pragma: no cover
message = {'status':'false','message':'invalid user'} message = {'status':'false','message':'invalid user'}
return JSONResponse(status=400,data=message) return JSONResponse(status=400,data=message)
@@ -4886,11 +4845,11 @@ def workout_upload_api(request):
upload_to_ua = optionsform.cleaned_data['upload_to_MapMyFitness'] upload_to_ua = optionsform.cleaned_data['upload_to_MapMyFitness']
upload_to_tp = optionsform.cleaned_data['upload_to_TrainingPeaks'] upload_to_tp = optionsform.cleaned_data['upload_to_TrainingPeaks']
makeprivate = optionsform.cleaned_data['makeprivate'] makeprivate = optionsform.cleaned_data['makeprivate']
else: else: # pragma: no cover
message = optionsform.errors message = optionsform.errors
return JSONResponse(status=400,data=message) return JSONResponse(status=400,data=message)
if r is None: if r is None: # pragma: no cover
message = {'status':'false','message':'something went wrong'} message = {'status':'false','message':'something went wrong'}
return JSONResponse(status=400,data=message) return JSONResponse(status=400,data=message)
@@ -4911,48 +4870,49 @@ def workout_upload_api(request):
impeller=useImpeller, impeller=useImpeller,
) )
if id == 0: if id == 0: # pragma: no cover
if message is not None: if message is not None:
message = {'status':'false','message':'unable to process file: '+message} message = {'status':'false','message':'unable to process file: '+message}
else: else:
message = {'status': 'false', 'message': 'unable to process file'} message = {'status': 'false', 'message': 'unable to process file'}
return JSONResponse(status=400,data=message) return JSONResponse(status=400,data=message)
if id == -1: if id == -1: # pragma: no cover
message = {'status': 'true', 'message':message} message = {'status': 'true', 'message':message}
return JSONResponse(status=200,data=message) return JSONResponse(status=200,data=message)
w = Workout.objects.get(id=id) w = Workout.objects.get(id=id)
if make_plot: if make_plot: # pragma: no cover
res, jobid = uploads.make_plot(r,w,f1,f2,plottype,t) res, jobid = uploads.make_plot(r,w,f1,f2,plottype,t)
elif r.staticchartonupload != 'None': elif r.staticchartonupload != 'None': # pragma: no cover
plottype = r.staticchartonupload plottype = r.staticchartonupload
res, jobid = uploads.make_plot(r,w,f1,f2,plottype,t) res, jobid = uploads.make_plot(r,w,f1,f2,plottype,t)
if inboard: if inboard: # pragma: no cover
w.inboard = inboard w.inboard = inboard
w.save() w.save()
if oarlength: if oarlength: # pragma: no cover
w.oarlength = oarlength w.oarlength = oarlength
w.save() w.save()
if totalDistance: if totalDistance: # pragma: no cover
w.distance = totalDistance w.distance = totalDistance
w.save() w.save()
if elapsedTime: if elapsedTime: # pragma: no cover
w.duration = totaltime_sec_to_string(elapsedTime) w.duration = totaltime_sec_to_string(elapsedTime)
if summary: if summary: # pragma: no cover
w.summary = summary w.summary = summary
w.save() w.save()
uploads.do_sync(w,post_data,quick=True) uploads.do_sync(w,post_data,quick=True)
else: # form invalid else: # pragma: no cover
# form invalid
if fstr: if fstr:
os.remove(fstr) os.remove(fstr)
message = form.errors message = form.errors
@@ -4963,11 +4923,11 @@ def workout_upload_api(request):
if fstr: if fstr:
try: try:
os.remove(fstr) os.remove(fstr)
except FileNotFoundError: except FileNotFoundError: # pragma: no cover
message = {'status': 'true', 'id':w.id,'message': 'Error deleting temporary file'} message = {'status': 'true', 'id':w.id,'message': 'Error deleting temporary file'}
statuscode = 500 statuscode = 500
if r.getemailnotifications and not r.emailbounced: if r.getemailnotifications and not r.emailbounced: # pragma: no cover
link = settings.SITE_URL+reverse( link = settings.SITE_URL+reverse(
r.defaultlandingpage, r.defaultlandingpage,
kwargs = { kwargs = {
@@ -4994,11 +4954,11 @@ def workout_upload_view(request,
raceid=0): raceid=0):
is_ajax = False is_ajax = False
if request.is_ajax(): if request.is_ajax(): # pragma: no cover
is_ajax = True is_ajax = True
r = getrower(request.user) r = getrower(request.user)
if r.rowerplan == 'freecoach': if r.rowerplan == 'freecoach': # pragma: no cover
url = reverse('team_workout_upload_view') url = reverse('team_workout_upload_view')
return HttpResponseRedirect(url) return HttpResponseRedirect(url)
@@ -5017,7 +4977,7 @@ def workout_upload_view(request,
uploadoptions = request.session['uploadoptions'] uploadoptions = request.session['uploadoptions']
try: try:
defaultlandingpage = uploadoptions['landingpage'] defaultlandingpage = uploadoptions['landingpage']
except KeyError: except KeyError: # pragma: no cover
uploadoptions['landingpage'] = r.defaultlandingpage uploadoptions['landingpage'] = r.defaultlandingpage
defaultlandingpage = r.defaultlandingpage defaultlandingpage = r.defaultlandingpage
else: else:
@@ -5028,28 +4988,15 @@ def workout_upload_view(request,
else: else:
request.session['docformoptions'] = docformoptions request.session['docformoptions'] = docformoptions
try: makeprivate = uploadoptions.get('makeprivate',False)
makeprivate = uploadoptions['makeprivate'] make_plot = uploadoptions.get('make_plot',False)
except KeyError: workouttype = uploadoptions.get('WorkoutType','rower')
makeprivate = False boattype = docformoptions.get('boattype','1x')
try:
make_plot = uploadoptions['make_plot']
except KeyError:
make_plot = False
try:
workouttype = docformoptions['workouttype']
except KeyError:
workouttype = 'rower'
try:
boattype = docformoptions['boattype']
except KeyError:
boattype = '1x'
try: try:
rpe = docformoptions['rpe'] rpe = docformoptions['rpe']
try: try: # pragma: no cover
rpe = int(rpe) rpe = int(rpe)
except ValueError: except ValueError:
rpe = 0 rpe = 0
@@ -5058,59 +5005,16 @@ def workout_upload_view(request,
except KeyError: except KeyError:
rpe = -1 rpe = -1
try: notes = docformoptions.get('notes','')
notes = docformoptions['notes'] workoutsource = uploadoptions.get('workoutsource',None)
except KeyError: plottype = uploadoptions.get('plottype','timeplot')
notes = '' landingpage = uploadoptions.get('landingpage',r.defaultlandingpage)
upload_to_c2 = uploadoptions.get('upload_to_C2',False)
try: upload_to_strava = uploadoptions.get('upload_to_Strava',False)
workoutsource = uploadoptions['workoutsource'] upload_to_st = uploadoptions.get('upload_to_SportTracks',False)
except KeyError: upload_to_rk = uploadoptions.get('upload_to_RunKeeper',False)
workoutsource = None upload_to_ua = uploadoptions.get('upload_to_MapMyFitness',False)
upload_to_tp = uploadoptions.get('upload_to_TrainingPeaks',False)
try:
plottype = uploadoptions['plottype']
except KeyError:
plottype = 'timeplot'
try:
landingpage = uploadoptions['landingpage']
except KeyError:
landingpage = r.defaultlandingpage
uploadoptions['landingpage'] = landingpage
try:
upload_to_c2 = uploadoptions['upload_to_C2']
except KeyError:
upload_to_c2 = False
try:
upload_to_strava = uploadoptions['upload_to_Strava']
except KeyError:
upload_to_strava = False
try:
upload_to_st = uploadoptions['upload_to_SportTracks']
except KeyError:
upload_to_st = False
try:
upload_to_rk = uploadoptions['upload_to_RunKeeper']
except KeyError:
upload_to_rk = False
try:
upload_to_ua = uploadoptions['upload_to_MapMyFitness']
except KeyError:
upload_to_ua = False
try:
upload_to_tp = uploadoptions['upload_to_TrainingPeaks']
except KeyError:
upload_to_tp = False
response = {} response = {}
if request.method == 'POST': if request.method == 'POST':
@@ -5123,7 +5027,7 @@ def workout_upload_view(request,
if f is not None: if f is not None:
res = handle_uploaded_file(f) res = handle_uploaded_file(f)
else: else: # pragma: no cover
messages.error(request, messages.error(request,
"Something went wrong - no file attached") "Something went wrong - no file attached")
url = reverse('workout_upload_view') url = reverse('workout_upload_view')
@@ -5141,7 +5045,7 @@ def workout_upload_view(request,
rpe = int(rpe) rpe = int(rpe)
except ValueError: except ValueError:
rpe = 0 rpe = 0
except KeyError: except KeyError: # pragma: no cover
rpe = -1 rpe = -1
request.session['docformoptions'] = { request.session['docformoptions'] = {
@@ -5204,7 +5108,7 @@ def workout_upload_view(request,
title = t, title = t,
notes=notes, notes=notes,
) )
else: else: # pragma: no cover
workoutsbox = Mailbox.objects.filter(name='workouts')[0] workoutsbox = Mailbox.objects.filter(name='workouts')[0]
uploadoptions['fromuploadform'] = True uploadoptions['fromuploadform'] = True
bodyyaml = yaml.safe_dump( bodyyaml = yaml.safe_dump(
@@ -5229,7 +5133,7 @@ def workout_upload_view(request,
request, request,
"The file was too large to process in real time. It will be processed in a background process. You will receive an email when it is ready") "The file was too large to process in real time. It will be processed in a background process. You will receive an email when it is ready")
url = reverse('workout_upload_view') url = reverse('workout_upload_view')
if is_ajax: if is_ajax: # pragma: no cover
return JSONResponse({'result':1,'url':url}) return JSONResponse({'result':1,'url':url})
else: else:
response = HttpResponseRedirect(url) response = HttpResponseRedirect(url)