further coverage increases
This commit is contained in:
@@ -222,8 +222,8 @@ def get_nk_workout_list(user,fake=False,startTime=0,endTime=0):
|
||||
else:
|
||||
# ready to fetch. Hurray
|
||||
if not endTime:
|
||||
endTime = int(arrow.now().timestamp())*1000
|
||||
endTime = str(endTime)
|
||||
endTime = arrow.now()+timedelta(days=1)
|
||||
endTime = str(int(endTime.timestamp())*1000)
|
||||
if not startTime:
|
||||
startTime = arrow.now()-timedelta(days=30)
|
||||
startTime = str(int(startTime.timestamp())*1000)
|
||||
|
||||
@@ -2818,6 +2818,7 @@ def handle_setcp(strokesdf,filename,workoutid,debug=False,**kwargs):
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
if not strokesdf.empty:
|
||||
|
||||
try:
|
||||
totaltime = strokesdf['time'].max()
|
||||
except KeyError:
|
||||
@@ -2827,6 +2828,7 @@ def handle_setcp(strokesdf,filename,workoutid,debug=False,**kwargs):
|
||||
except KeyError:
|
||||
powermean = 0
|
||||
|
||||
|
||||
if powermean != 0:
|
||||
thesecs = totaltime
|
||||
maxt = 1.05 * thesecs
|
||||
|
||||
@@ -5,7 +5,7 @@ pytestmark = pytest.mark.django_db
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
import re
|
||||
from nose_parameterized import parameterized
|
||||
from parameterized import parameterized
|
||||
from django.test import TestCase, Client,override_settings
|
||||
from django.core.management import call_command
|
||||
from django.utils.six import StringIO
|
||||
@@ -62,7 +62,7 @@ class AjaxTests(TestCase):
|
||||
starttime=self.nu.strftime('%H:%M:%S'),
|
||||
duration="0:55:00",distance=8000,
|
||||
csvfilename=self.filename)
|
||||
|
||||
|
||||
self.wote = Workout.objects.create(name='testworkout',
|
||||
workouttype='Indoor Rower',
|
||||
user=r,date=self.nu.strftime('%Y-%m-%d'),
|
||||
@@ -72,7 +72,7 @@ class AjaxTests(TestCase):
|
||||
|
||||
|
||||
self.c = Client()
|
||||
|
||||
|
||||
def test_toggle_ranking(self):
|
||||
response = self.c.get(
|
||||
'/rowers/workout/1/toggle-ranking/',
|
||||
|
||||
@@ -13,7 +13,7 @@ encoded13 = str(encoder.encode_hex(13))
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
import re
|
||||
from nose_parameterized import parameterized
|
||||
from parameterized import parameterized
|
||||
from django.test import TestCase, Client,override_settings
|
||||
from django.core.management import call_command
|
||||
from django.utils.six import StringIO
|
||||
|
||||
@@ -308,6 +308,25 @@ class WorkoutViewTest(TestCase):
|
||||
response = self.c.get(url,follow=True)
|
||||
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'})
|
||||
expected_url = reverse('workout_data_view',kwargs={'id':encoder.encode_hex(self.wwater.id)})
|
||||
|
||||
@@ -323,7 +342,7 @@ class WorkoutViewTest(TestCase):
|
||||
'cols':['driveenergy','spm']
|
||||
}
|
||||
form = DataFrameColumnsForm(form_data)
|
||||
|
||||
|
||||
self.assertTrue(form.is_valid())
|
||||
|
||||
response = self.c.post(url,form_data)
|
||||
|
||||
@@ -45,6 +45,13 @@ workout run
|
||||
copy('rowers/tests/testdata/emails/colin.csv',a2)
|
||||
a3 = 'media/mailbox_attachments/colin4.csv'
|
||||
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.save()
|
||||
|
||||
@@ -88,6 +95,29 @@ workout run
|
||||
self.assertEqual(w.name,'test')
|
||||
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')
|
||||
|
||||
@@ -56,10 +56,18 @@ class ViewTest(TestCase):
|
||||
'rpe':6,
|
||||
'upload_to_c2':False,
|
||||
'plottype':'timeplot',
|
||||
'landingpage':'workout_edit_view',
|
||||
'raceid':0,
|
||||
'file': f,
|
||||
}
|
||||
|
||||
request = RequestFactory()
|
||||
request.user = self.u
|
||||
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)
|
||||
|
||||
self.assertRedirects(response, expected_url='/rowers/workout/'+encoded1+'/edit/',
|
||||
@@ -105,6 +113,8 @@ class ViewTest(TestCase):
|
||||
'boattype':'1x',
|
||||
'rpe':4,
|
||||
'dragfactor':'112',
|
||||
'raceid':0,
|
||||
'landingpage':'workout_edit_view',
|
||||
'private':True,
|
||||
'notes':'noot mies',
|
||||
}
|
||||
@@ -153,6 +163,8 @@ class ViewTest(TestCase):
|
||||
'upload_to_RunKeeper':False,
|
||||
'upload_to_MapMyFitness':False,
|
||||
'plottype':'timeplot',
|
||||
'raceid':0,
|
||||
'landingpage':'workout_edit_view',
|
||||
'file': f,
|
||||
'makeprivate':False,
|
||||
'landingpage':'workout_edit_view',
|
||||
@@ -197,6 +209,8 @@ class ViewTest(TestCase):
|
||||
'make_plot':False,
|
||||
'upload_to_c2':False,
|
||||
'plottype':'timeplot',
|
||||
'raceid':0,
|
||||
'landingpage':'workout_edit_view',
|
||||
'file': f,
|
||||
'rpe':6,
|
||||
}
|
||||
@@ -234,6 +248,8 @@ class ViewTest(TestCase):
|
||||
'make_plot':False,
|
||||
'upload_to_c2':False,
|
||||
'plottype':'timeplot',
|
||||
'raceid':0,
|
||||
'landingpage':'workout_edit_view',
|
||||
'file': f,
|
||||
'rpe':6,
|
||||
}
|
||||
@@ -269,6 +285,8 @@ class ViewTest(TestCase):
|
||||
'make_plot':False,
|
||||
'upload_to_c2':False,
|
||||
'plottype':'timeplot',
|
||||
'raceid':0,
|
||||
'landingpage':'workout_edit_view',
|
||||
'file': f,
|
||||
'rpe':6,
|
||||
}
|
||||
@@ -320,6 +338,8 @@ class ViewTest(TestCase):
|
||||
'make_plot':False,
|
||||
'upload_to_c2':False,
|
||||
'plottype':'timeplot',
|
||||
'raceid':0,
|
||||
'landingpage':'workout_edit_view',
|
||||
'file': f,
|
||||
'rpe':6,
|
||||
}
|
||||
@@ -358,6 +378,8 @@ class ViewTest(TestCase):
|
||||
'make_plot':False,
|
||||
'upload_to_c2':False,
|
||||
'plottype':'timeplot',
|
||||
'raceid':0,
|
||||
'landingpage':'workout_edit_view',
|
||||
'file': f,
|
||||
'rpe':6,
|
||||
}
|
||||
@@ -396,6 +418,8 @@ class ViewTest(TestCase):
|
||||
'make_plot':False,
|
||||
'upload_to_c2':False,
|
||||
'plottype':'timeplot',
|
||||
'raceid':0,
|
||||
'landingpage':'workout_edit_view',
|
||||
'file': f,
|
||||
'rpe':6,
|
||||
}
|
||||
@@ -450,6 +474,8 @@ class ViewTest(TestCase):
|
||||
'make_plot':False,
|
||||
'upload_to_c2':False,
|
||||
'plottype':'timeplot',
|
||||
'raceid':0,
|
||||
'landingpage':'workout_edit_view',
|
||||
'file': f,
|
||||
'rpe':6,
|
||||
}
|
||||
@@ -487,6 +513,8 @@ class ViewTest(TestCase):
|
||||
'make_plot':False,
|
||||
'upload_to_c2':False,
|
||||
'plottype':'timeplot',
|
||||
'raceid':0,
|
||||
'landingpage':'workout_edit_view',
|
||||
'rpe':1,
|
||||
'file': f,
|
||||
}
|
||||
@@ -525,6 +553,8 @@ class ViewTest(TestCase):
|
||||
'make_plot':False,
|
||||
'rpe':1,
|
||||
'upload_to_c2':False,
|
||||
'raceid':0,
|
||||
'landingpage':'workout_edit_view',
|
||||
'plottype':'timeplot',
|
||||
'file': f,
|
||||
}
|
||||
@@ -564,6 +594,8 @@ class ViewTest(TestCase):
|
||||
'notes':'aap noot mies',
|
||||
'make_plot':False,
|
||||
'upload_to_c2':False,
|
||||
'raceid':0,
|
||||
'landingpage':'workout_edit_view',
|
||||
'plottype':'timeplot',
|
||||
'file': f,
|
||||
}
|
||||
@@ -602,6 +634,8 @@ class ViewTest(TestCase):
|
||||
'notes':'aap noot mies',
|
||||
'make_plot':False,
|
||||
'upload_to_c2':False,
|
||||
'raceid':0,
|
||||
'landingpage':'workout_edit_view',
|
||||
'plottype':'timeplot',
|
||||
'file': f,
|
||||
}
|
||||
@@ -636,6 +670,8 @@ class ViewTest(TestCase):
|
||||
'make_plot':False,
|
||||
'upload_to_c2':False,
|
||||
'plottype':'timeplot',
|
||||
'raceid':0,
|
||||
'landingpage':'workout_edit_view',
|
||||
'rpe':4,
|
||||
'file': f,
|
||||
}
|
||||
@@ -670,6 +706,8 @@ class ViewTest(TestCase):
|
||||
'make_plot':False,
|
||||
'upload_to_c2':False,
|
||||
'plottype':'timeplot',
|
||||
'raceid':0,
|
||||
'landingpage':'workout_edit_view',
|
||||
'file': f,
|
||||
}
|
||||
|
||||
@@ -704,6 +742,8 @@ class ViewTest(TestCase):
|
||||
'make_plot':False,
|
||||
'upload_to_c2':False,
|
||||
'plottype':'timeplot',
|
||||
'raceid':0,
|
||||
'landingpage':'workout_edit_view',
|
||||
'rpe':1,
|
||||
'file': f,
|
||||
}
|
||||
@@ -740,6 +780,8 @@ class ViewTest(TestCase):
|
||||
'make_plot':False,
|
||||
'upload_to_c2':False,
|
||||
'plottype':'timeplot',
|
||||
'raceid':0,
|
||||
'landingpage':'workout_edit_view',
|
||||
'file': f,
|
||||
}
|
||||
|
||||
@@ -773,6 +815,8 @@ class ViewTest(TestCase):
|
||||
'make_plot':False,
|
||||
'upload_to_c2':False,
|
||||
'plottype':'timeplot',
|
||||
'raceid':0,
|
||||
'landingpage':'workout_edit_view',
|
||||
'file': f,
|
||||
}
|
||||
|
||||
@@ -806,6 +850,8 @@ class ViewTest(TestCase):
|
||||
'make_plot':False,
|
||||
'upload_to_c2':False,
|
||||
'plottype':'timeplot',
|
||||
'raceid':0,
|
||||
'landingpage':'workout_edit_view',
|
||||
'file': f,
|
||||
}
|
||||
|
||||
@@ -839,6 +885,8 @@ class ViewTest(TestCase):
|
||||
'make_plot':False,
|
||||
'upload_to_c2':False,
|
||||
'plottype':'timeplot',
|
||||
'raceid':0,
|
||||
'landingpage':'workout_edit_view',
|
||||
'file': f,
|
||||
}
|
||||
|
||||
|
||||
@@ -3279,7 +3279,7 @@ def workout_data_view(request, id=0):
|
||||
|
||||
try:
|
||||
datadf = datadf[tcols]
|
||||
except KeyError:
|
||||
except KeyError: # pragma: no cover
|
||||
# tcols = list(set(datadf.columns(tolist)+tcols))
|
||||
try:
|
||||
datadf = datadf[tcols]
|
||||
@@ -3348,7 +3348,7 @@ def workout_stats_view(request,id=0,message="",successmessage=""):
|
||||
]
|
||||
|
||||
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'])
|
||||
|
||||
|
||||
@@ -3519,7 +3519,7 @@ def workflow_default_view(request):
|
||||
r = getrower(request.user)
|
||||
if r.defaultlandingpage == 'workout_edit_view':
|
||||
r.defaultlandingpage = 'workout_workflow_view'
|
||||
else:
|
||||
else: # pragma: no cover
|
||||
r.defaultlandingpage = 'workout_edit_view'
|
||||
|
||||
r.save()
|
||||
@@ -3543,56 +3543,29 @@ def workout_workflow_config2_view(request,userid=0):
|
||||
r = getrequestrower(request,userid=userid,notpermanent=True)
|
||||
|
||||
MiddlePanelFormSet = formset_factory(WorkFlowMiddlePanelElement,extra=1)
|
||||
LeftPanelFormSet = formset_factory(WorkFlowLeftPanelElement,extra=1)
|
||||
|
||||
|
||||
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,
|
||||
prefix='middlepanel')
|
||||
newmiddlepanel = []
|
||||
if middlepanel_formset.is_valid():
|
||||
for form in middlepanel_formset:
|
||||
value = form.cleaned_data.get('panel')
|
||||
if value != 'None':
|
||||
newmiddlepanel.append(value)
|
||||
middlepanel_formset = MiddlePanelFormSet(request.POST,
|
||||
prefix='middlepanel')
|
||||
newmiddlepanel = []
|
||||
if middlepanel_formset.is_valid():
|
||||
for form in middlepanel_formset:
|
||||
value = form.cleaned_data.get('panel')
|
||||
if value != 'None':
|
||||
newmiddlepanel.append(value)
|
||||
|
||||
|
||||
newmiddlepanel = [i for i in newmiddlepanel if i != None]
|
||||
r.workflowmiddlepanel = newmiddlepanel
|
||||
try:
|
||||
r.save()
|
||||
except IntegrityError:
|
||||
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]
|
||||
|
||||
newmiddlepanel = [i for i in newmiddlepanel if i != None]
|
||||
r.workflowmiddlepanel = newmiddlepanel
|
||||
try:
|
||||
r.save()
|
||||
except IntegrityError: # pragma: no cover
|
||||
messages.error(request,'Something went wrong')
|
||||
|
||||
middlepanelform_data = [{'panel':panel}
|
||||
for panel in r.workflowmiddlepanel]
|
||||
|
||||
leftpanel_formset = LeftPanelFormSet(initial=leftpanelform_data,
|
||||
prefix='leftpanel')
|
||||
middlepanel_formset = MiddlePanelFormSet(initial=middlepanelform_data,
|
||||
prefix='middlepanel')
|
||||
|
||||
@@ -3602,7 +3575,6 @@ def workout_workflow_config2_view(request,userid=0):
|
||||
return render(request,tmplt,
|
||||
{
|
||||
'rower':r,
|
||||
'leftpanel_formset':leftpanel_formset,
|
||||
'middlepanel_formset':middlepanel_formset,
|
||||
'workoutid': workoutid,
|
||||
})
|
||||
@@ -3707,7 +3679,7 @@ def workout_flexchart3_view(request,*args,**kwargs):
|
||||
except KeyError: # pragma: no cover
|
||||
raise Http404("Invalid workout number")
|
||||
|
||||
if 'promember' in kwargs:
|
||||
if 'promember' in kwargs: # pragma: no cover
|
||||
promember = kwargs['promember']
|
||||
else:
|
||||
promember = 0
|
||||
@@ -3769,7 +3741,7 @@ def workout_flexchart3_view(request,*args,**kwargs):
|
||||
else:
|
||||
if favorites:
|
||||
yparam2 = favorites[favoritenr].yparam2
|
||||
if yparam2 == '':
|
||||
if yparam2 == '': # pragma: no cover
|
||||
yparam2 = 'None'
|
||||
else:
|
||||
yparam2 = 'hr'
|
||||
@@ -3783,11 +3755,11 @@ def workout_flexchart3_view(request,*args,**kwargs):
|
||||
favoritechartnotes = ''
|
||||
else:
|
||||
favoritechartnotes = ''
|
||||
else:
|
||||
else: # pragma: no cover
|
||||
favoritechartnotes = ''
|
||||
favoritenr = 0
|
||||
|
||||
if 'plottype' in kwargs:
|
||||
if 'plottype' in kwargs: # pragma: no cover
|
||||
plottype = kwargs['plottype']
|
||||
else:
|
||||
if favorites:
|
||||
@@ -3795,7 +3767,7 @@ def workout_flexchart3_view(request,*args,**kwargs):
|
||||
else:
|
||||
plottype = 'line'
|
||||
|
||||
if 'workstrokesonly' in kwargs:
|
||||
if 'workstrokesonly' in kwargs: # pragma: no cover
|
||||
workstrokesonly = kwargs['workstrokesonly']
|
||||
else:
|
||||
if favorites:
|
||||
@@ -3820,7 +3792,7 @@ def workout_flexchart3_view(request,*args,**kwargs):
|
||||
reststrokes=reststrokes)
|
||||
f.save()
|
||||
|
||||
except KeyError:
|
||||
except KeyError: # pragma: no cover
|
||||
messages.error(request,'We cannot save the ad hoc metrics in a favorite chart')
|
||||
|
||||
if request.method == 'POST' and 'xaxis' in request.POST:
|
||||
@@ -3846,13 +3818,13 @@ def workout_flexchart3_view(request,*args,**kwargs):
|
||||
if not promember:
|
||||
for name,d in rowingmetrics:
|
||||
if d['type'] != 'basic':
|
||||
if xparam == name:
|
||||
if xparam == name: # pragma: no cover
|
||||
xparam = 'time'
|
||||
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'
|
||||
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'
|
||||
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):
|
||||
try:
|
||||
id = kwargs['id']
|
||||
except KeyError:
|
||||
except KeyError: # pragma: no cover
|
||||
raise Http404("Invalid workout number")
|
||||
|
||||
workout = get_workout(id)
|
||||
@@ -4006,7 +3978,7 @@ def workout_flexchart_stacked_view(request,*args,**kwargs):
|
||||
mode=workout.workouttype,
|
||||
)
|
||||
|
||||
if comment is not None:
|
||||
if comment is not None: # pragma: no cover
|
||||
messages.error(request,comment)
|
||||
|
||||
initial = {
|
||||
@@ -4118,7 +4090,7 @@ def workout_otwpowerplot_view(request,id=0,message="",successmessage=""):
|
||||
def workout_unsubscribe_view(request,id=0):
|
||||
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")
|
||||
|
||||
comments = WorkoutComment.objects.filter(workout=w,
|
||||
@@ -4148,7 +4120,7 @@ def workout_unsubscribe_view(request,id=0):
|
||||
def workout_comment_view(request,id=0):
|
||||
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")
|
||||
|
||||
comments = WorkoutComment.objects.filter(workout=w).order_by("created")
|
||||
@@ -4161,7 +4133,7 @@ def workout_comment_view(request,id=0):
|
||||
cd = form.cleaned_data
|
||||
comment = cd['comment']
|
||||
comment = bleach.clean(comment)
|
||||
try:
|
||||
try: # pragma: no cover
|
||||
if isinstance(comment,unicode):
|
||||
comment = comment.encode('utf8')
|
||||
elif isinstance(comment, str):
|
||||
@@ -4183,7 +4155,7 @@ def workout_comment_view(request,id=0):
|
||||
comment = comment,
|
||||
url = url,
|
||||
)
|
||||
if request.user != r.user:
|
||||
if request.user != r.user: # pragma: no cover
|
||||
a_messages.info(r.user,message.encode('ascii','ignore'))
|
||||
|
||||
res = myqueue(queuehigh,
|
||||
@@ -4197,7 +4169,7 @@ def workout_comment_view(request,id=0):
|
||||
)
|
||||
|
||||
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)
|
||||
if u != request.user and u != r.user:
|
||||
ocr = Rower.objects.get(user=u)
|
||||
@@ -4223,7 +4195,7 @@ def workout_comment_view(request,id=0):
|
||||
form = WorkoutCommentForm()
|
||||
|
||||
g = GraphImage.objects.filter(workout=w).order_by("-creationdatetime")
|
||||
for i in g:
|
||||
for i in g: # pragma: no cover
|
||||
try:
|
||||
width,height = Image.open(i.filename).size
|
||||
i.width = width
|
||||
@@ -4275,7 +4247,7 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
|
||||
|
||||
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)])
|
||||
try:
|
||||
if data['wash'].std() != 0:
|
||||
@@ -4287,7 +4259,7 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
|
||||
except:
|
||||
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)])
|
||||
try:
|
||||
if data['wash'].std() != 0:
|
||||
@@ -4321,41 +4293,28 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
|
||||
thetimezone = form.cleaned_data['timezone']
|
||||
try:
|
||||
rpe = form.cleaned_data['rpe']
|
||||
if not rpe:
|
||||
if not rpe: # pragma: no cover
|
||||
rpe = -1
|
||||
except KeyError: # pragma: no cover
|
||||
rpe = -1
|
||||
|
||||
ps = form.cleaned_data.get('plannedsession',None)
|
||||
|
||||
try:
|
||||
boattype = request.POST['boattype']
|
||||
except KeyError:
|
||||
boattype = Workout.objects.get(id=encoder.decode_hex(id)).boattype
|
||||
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
|
||||
boattype = request.POST.get('boattype',Workout.objects.get(id=encoder.decode_hex(id)).boattype)
|
||||
privacy = request.POST.get('privacy',Workout.objects.get(id=encoder.decode_hex(id)).privacy)
|
||||
rankingpiece = form.cleaned_data.get('rankingpiece',Workout.objects.get(id=row.id).rankingpiece)
|
||||
duplicate = form.cleaned_data.get('duplicate',Workout.objects.get(id=row.id).duplicate)
|
||||
|
||||
if private:
|
||||
privacy = 'private'
|
||||
else:
|
||||
else: # pragma: no cover
|
||||
privacy = 'visible'
|
||||
|
||||
try:
|
||||
startdatetime = datetime.datetime.combine(
|
||||
date,starttime
|
||||
)
|
||||
except TypeError:
|
||||
except TypeError: # pragma: no cover
|
||||
startdatetime = datetime.datetime.combine(
|
||||
date,datetime.datetime.min.time()
|
||||
)
|
||||
@@ -4364,18 +4323,18 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
|
||||
startdatetime = pytz.timezone(thetimezone).localize(
|
||||
startdatetime
|
||||
)
|
||||
except UnknownTimeZoneError:
|
||||
except UnknownTimeZoneError: # pragma: no cover
|
||||
pass
|
||||
|
||||
try:
|
||||
# aware object can be in any timezone
|
||||
out = startdatetime.astimezone(pytz.utc)
|
||||
except (ValueError, TypeError):
|
||||
except (ValueError, TypeError): # pragma: no cover
|
||||
startdatetime = timezone.make_aware(startdatetime)
|
||||
|
||||
try:
|
||||
startdatetime = startdatetime.astimezone(pytz.timezone(thetimezone))
|
||||
except UnknownTimeZoneError:
|
||||
except UnknownTimeZoneError: # pragma: no cover
|
||||
thetimezone = 'UTC'
|
||||
|
||||
timechanged = (startdatetime != row.startdatetime)
|
||||
@@ -4399,16 +4358,16 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
|
||||
row.plannedsession = ps
|
||||
|
||||
dragchanged = False
|
||||
if newdragfactor != row.dragfactor:
|
||||
if newdragfactor != row.dragfactor: # pragma: no cover
|
||||
row.dragfactor = newdragfactor
|
||||
dragchanged = True
|
||||
|
||||
try:
|
||||
row.save()
|
||||
except IntegrityError:
|
||||
except IntegrityError: # pragma: no cover
|
||||
pass
|
||||
|
||||
if ps:
|
||||
if ps: # pragma: no cover
|
||||
add_workouts_plannedsession([row],ps,row.user)
|
||||
|
||||
# change data in csv file
|
||||
@@ -4416,7 +4375,7 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
|
||||
if datachanged:
|
||||
r = rdata(csvfile=row.csvfilename)
|
||||
if dragchanged:
|
||||
try:
|
||||
try: # pragma: no cover
|
||||
r.change_drag(newdragfactor)
|
||||
except AttributeError:
|
||||
pass
|
||||
@@ -4429,7 +4388,7 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
|
||||
|
||||
successmessage = "Changes saved"
|
||||
|
||||
if rankingpiece:
|
||||
if rankingpiece: # pragma: no cover
|
||||
dataprep.runcpupdate(row.user,type=row.workouttype)
|
||||
|
||||
messages.info(request,successmessage)
|
||||
@@ -4437,7 +4396,7 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
|
||||
form = WorkoutForm(instance=row)
|
||||
|
||||
g = GraphImage.objects.filter(workout=row).order_by("-creationdatetime")
|
||||
for i in g:
|
||||
for i in g: # pragma: no cover
|
||||
try:
|
||||
width,height = Image.open(i.filename).size
|
||||
i.width = width
|
||||
@@ -4460,7 +4419,7 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
|
||||
try:
|
||||
latitude = rowdata.df[' latitude']
|
||||
longitude = rowdata.df[' longitude']
|
||||
if not latitude.std():
|
||||
if not latitude.std(): # pragma: no cover
|
||||
hascoordinates = 0
|
||||
if not longitude.std():
|
||||
hascoordinates = 0
|
||||
@@ -4599,8 +4558,8 @@ def workout_map_view(request,id=0):
|
||||
|
||||
# Image upload
|
||||
@permission_required('workout.change_workout',fn=get_workout_by_opaqueid,raise_exception=True)
|
||||
def workout_uploadimage_view(request,id):
|
||||
is_ajax = False
|
||||
def workout_uploadimage_view(request,id): # pragma: no cover
|
||||
is_ajax = False # pragma: no cover
|
||||
if request.is_ajax():
|
||||
is_ajax = True
|
||||
|
||||
@@ -4629,7 +4588,7 @@ def workout_uploadimage_view(request,id):
|
||||
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"
|
||||
messages.error(request,message)
|
||||
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,
|
||||
imagename=imagename
|
||||
)
|
||||
if res == 0:
|
||||
if res == 0: # pragma: no cover
|
||||
messages.error(request,jobid)
|
||||
else:
|
||||
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)
|
||||
def workout_toggle_ranking(request,id=0):
|
||||
is_ajax = False
|
||||
if request.is_ajax():
|
||||
if request.is_ajax(): # pragma: no cover
|
||||
is_ajax = True
|
||||
|
||||
row = get_workout_by_opaqueid(request,id)
|
||||
@@ -4750,7 +4709,7 @@ def workout_toggle_ranking(request,id=0):
|
||||
row.rankingpiece = not row.rankingpiece
|
||||
row.save()
|
||||
|
||||
if is_ajax:
|
||||
if is_ajax: # pragma: no cover
|
||||
response = JSONResponse({'result':row.rankingpiece},
|
||||
content_type='application/json')
|
||||
|
||||
@@ -4765,7 +4724,7 @@ def workout_toggle_ranking(request,id=0):
|
||||
@csrf_exempt
|
||||
def workout_upload_api(request):
|
||||
stravaid = ''
|
||||
if request.method != 'POST':
|
||||
if request.method != 'POST': # pragma: no cover
|
||||
message = {'status':'false','message':'this view cannot be accessed through GET'}
|
||||
return JSONResponse(status=403,data=message)
|
||||
|
||||
@@ -4842,9 +4801,9 @@ def workout_upload_api(request):
|
||||
rpe = form.cleaned_data['rpe']
|
||||
try:
|
||||
rpe = int(rpe)
|
||||
except ValueError:
|
||||
except ValueError: # pragma: no cover
|
||||
rpe = 0
|
||||
except KeyError:
|
||||
except KeyError: # pragma: no cover
|
||||
rpe = -1
|
||||
if rowerform.is_valid():
|
||||
u = rowerform.cleaned_data['user']
|
||||
@@ -4853,7 +4812,7 @@ def workout_upload_api(request):
|
||||
|
||||
if 'useremail' in post_data:
|
||||
us = User.objects.filter(email=post_data['useremail'])
|
||||
if len(us):
|
||||
if len(us): # pragma: no cover
|
||||
u = us[0]
|
||||
r = getrower(u)
|
||||
else:
|
||||
@@ -4864,12 +4823,12 @@ def workout_upload_api(request):
|
||||
r = rwr
|
||||
break
|
||||
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'}
|
||||
return JSONResponse(status=400,data=message)
|
||||
|
||||
|
||||
if r is None:
|
||||
if r is None: # pragma: no cover
|
||||
message = {'status':'false','message':'invalid user'}
|
||||
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_tp = optionsform.cleaned_data['upload_to_TrainingPeaks']
|
||||
makeprivate = optionsform.cleaned_data['makeprivate']
|
||||
else:
|
||||
else: # pragma: no cover
|
||||
message = optionsform.errors
|
||||
return JSONResponse(status=400,data=message)
|
||||
|
||||
if r is None:
|
||||
if r is None: # pragma: no cover
|
||||
message = {'status':'false','message':'something went wrong'}
|
||||
return JSONResponse(status=400,data=message)
|
||||
|
||||
@@ -4911,48 +4870,49 @@ def workout_upload_api(request):
|
||||
impeller=useImpeller,
|
||||
)
|
||||
|
||||
if id == 0:
|
||||
if id == 0: # pragma: no cover
|
||||
if message is not None:
|
||||
message = {'status':'false','message':'unable to process file: '+message}
|
||||
else:
|
||||
message = {'status': 'false', 'message': 'unable to process file'}
|
||||
|
||||
return JSONResponse(status=400,data=message)
|
||||
if id == -1:
|
||||
if id == -1: # pragma: no cover
|
||||
message = {'status': 'true', 'message':message}
|
||||
return JSONResponse(status=200,data=message)
|
||||
|
||||
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)
|
||||
elif r.staticchartonupload != 'None':
|
||||
elif r.staticchartonupload != 'None': # pragma: no cover
|
||||
plottype = r.staticchartonupload
|
||||
res, jobid = uploads.make_plot(r,w,f1,f2,plottype,t)
|
||||
|
||||
if inboard:
|
||||
if inboard: # pragma: no cover
|
||||
w.inboard = inboard
|
||||
w.save()
|
||||
if oarlength:
|
||||
if oarlength: # pragma: no cover
|
||||
w.oarlength = oarlength
|
||||
w.save()
|
||||
|
||||
if totalDistance:
|
||||
if totalDistance: # pragma: no cover
|
||||
w.distance = totalDistance
|
||||
w.save()
|
||||
|
||||
if elapsedTime:
|
||||
if elapsedTime: # pragma: no cover
|
||||
w.duration = totaltime_sec_to_string(elapsedTime)
|
||||
|
||||
if summary:
|
||||
if summary: # pragma: no cover
|
||||
w.summary = summary
|
||||
w.save()
|
||||
|
||||
uploads.do_sync(w,post_data,quick=True)
|
||||
|
||||
|
||||
else: # form invalid
|
||||
else: # pragma: no cover
|
||||
# form invalid
|
||||
if fstr:
|
||||
os.remove(fstr)
|
||||
message = form.errors
|
||||
@@ -4963,11 +4923,11 @@ def workout_upload_api(request):
|
||||
if fstr:
|
||||
try:
|
||||
os.remove(fstr)
|
||||
except FileNotFoundError:
|
||||
except FileNotFoundError: # pragma: no cover
|
||||
message = {'status': 'true', 'id':w.id,'message': 'Error deleting temporary file'}
|
||||
statuscode = 500
|
||||
|
||||
if r.getemailnotifications and not r.emailbounced:
|
||||
if r.getemailnotifications and not r.emailbounced: # pragma: no cover
|
||||
link = settings.SITE_URL+reverse(
|
||||
r.defaultlandingpage,
|
||||
kwargs = {
|
||||
@@ -4994,11 +4954,11 @@ def workout_upload_view(request,
|
||||
raceid=0):
|
||||
|
||||
is_ajax = False
|
||||
if request.is_ajax():
|
||||
if request.is_ajax(): # pragma: no cover
|
||||
is_ajax = True
|
||||
|
||||
r = getrower(request.user)
|
||||
if r.rowerplan == 'freecoach':
|
||||
if r.rowerplan == 'freecoach': # pragma: no cover
|
||||
url = reverse('team_workout_upload_view')
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
@@ -5017,7 +4977,7 @@ def workout_upload_view(request,
|
||||
uploadoptions = request.session['uploadoptions']
|
||||
try:
|
||||
defaultlandingpage = uploadoptions['landingpage']
|
||||
except KeyError:
|
||||
except KeyError: # pragma: no cover
|
||||
uploadoptions['landingpage'] = r.defaultlandingpage
|
||||
defaultlandingpage = r.defaultlandingpage
|
||||
else:
|
||||
@@ -5028,28 +4988,15 @@ def workout_upload_view(request,
|
||||
else:
|
||||
request.session['docformoptions'] = docformoptions
|
||||
|
||||
try:
|
||||
makeprivate = uploadoptions['makeprivate']
|
||||
except KeyError:
|
||||
makeprivate = False
|
||||
try:
|
||||
make_plot = uploadoptions['make_plot']
|
||||
except KeyError:
|
||||
make_plot = False
|
||||
makeprivate = uploadoptions.get('makeprivate',False)
|
||||
make_plot = uploadoptions.get('make_plot',False)
|
||||
workouttype = uploadoptions.get('WorkoutType','rower')
|
||||
boattype = docformoptions.get('boattype','1x')
|
||||
|
||||
try:
|
||||
workouttype = docformoptions['workouttype']
|
||||
except KeyError:
|
||||
workouttype = 'rower'
|
||||
|
||||
try:
|
||||
boattype = docformoptions['boattype']
|
||||
except KeyError:
|
||||
boattype = '1x'
|
||||
|
||||
try:
|
||||
rpe = docformoptions['rpe']
|
||||
try:
|
||||
try: # pragma: no cover
|
||||
rpe = int(rpe)
|
||||
except ValueError:
|
||||
rpe = 0
|
||||
@@ -5058,59 +5005,16 @@ def workout_upload_view(request,
|
||||
except KeyError:
|
||||
rpe = -1
|
||||
|
||||
try:
|
||||
notes = docformoptions['notes']
|
||||
except KeyError:
|
||||
notes = ''
|
||||
|
||||
try:
|
||||
workoutsource = uploadoptions['workoutsource']
|
||||
except KeyError:
|
||||
workoutsource = None
|
||||
|
||||
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
|
||||
|
||||
|
||||
|
||||
notes = docformoptions.get('notes','')
|
||||
workoutsource = uploadoptions.get('workoutsource',None)
|
||||
plottype = uploadoptions.get('plottype','timeplot')
|
||||
landingpage = uploadoptions.get('landingpage',r.defaultlandingpage)
|
||||
upload_to_c2 = uploadoptions.get('upload_to_C2',False)
|
||||
upload_to_strava = uploadoptions.get('upload_to_Strava',False)
|
||||
upload_to_st = uploadoptions.get('upload_to_SportTracks',False)
|
||||
upload_to_rk = uploadoptions.get('upload_to_RunKeeper',False)
|
||||
upload_to_ua = uploadoptions.get('upload_to_MapMyFitness',False)
|
||||
upload_to_tp = uploadoptions.get('upload_to_TrainingPeaks',False)
|
||||
|
||||
response = {}
|
||||
if request.method == 'POST':
|
||||
@@ -5123,7 +5027,7 @@ def workout_upload_view(request,
|
||||
|
||||
if f is not None:
|
||||
res = handle_uploaded_file(f)
|
||||
else:
|
||||
else: # pragma: no cover
|
||||
messages.error(request,
|
||||
"Something went wrong - no file attached")
|
||||
url = reverse('workout_upload_view')
|
||||
@@ -5141,7 +5045,7 @@ def workout_upload_view(request,
|
||||
rpe = int(rpe)
|
||||
except ValueError:
|
||||
rpe = 0
|
||||
except KeyError:
|
||||
except KeyError: # pragma: no cover
|
||||
rpe = -1
|
||||
|
||||
request.session['docformoptions'] = {
|
||||
@@ -5204,7 +5108,7 @@ def workout_upload_view(request,
|
||||
title = t,
|
||||
notes=notes,
|
||||
)
|
||||
else:
|
||||
else: # pragma: no cover
|
||||
workoutsbox = Mailbox.objects.filter(name='workouts')[0]
|
||||
uploadoptions['fromuploadform'] = True
|
||||
bodyyaml = yaml.safe_dump(
|
||||
@@ -5229,7 +5133,7 @@ def workout_upload_view(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")
|
||||
url = reverse('workout_upload_view')
|
||||
if is_ajax:
|
||||
if is_ajax: # pragma: no cover
|
||||
return JSONResponse({'result':1,'url':url})
|
||||
else:
|
||||
response = HttpResponseRedirect(url)
|
||||
|
||||
Reference in New Issue
Block a user