better tests
This commit is contained in:
@@ -94,7 +94,7 @@ SITE_URL_DEV = CFG['site_url']
|
||||
PROGRESS_CACHE_SECRET = CFG['progress_cache_secret']
|
||||
try:
|
||||
SETTINGS_NAME = CFG['settings_name']
|
||||
except KeyError:
|
||||
except KeyError: # pragma: no cover
|
||||
SETTINGS_NAME = 'rowsandall_ap.settings'
|
||||
|
||||
try:
|
||||
@@ -321,7 +321,7 @@ def summaryfromsplitdata(splitdata, data, filename, sep='|', workouttype='rower'
|
||||
return sums, sa, results
|
||||
|
||||
@app.task
|
||||
def handle_post_workout_api(uploadoptions, debug=False, **kwargs):
|
||||
def handle_post_workout_api(uploadoptions, debug=False, **kwargs): # pragma: no cover
|
||||
session = requests.session()
|
||||
newHeaders = {'Content-type': 'application/json', 'Accept': 'text/plain'}
|
||||
session.headers.update(newHeaders)
|
||||
@@ -335,14 +335,14 @@ def handle_post_workout_api(uploadoptions, debug=False, **kwargs):
|
||||
|
||||
|
||||
@app.task
|
||||
def handle_remove_workouts_team(ws, t, debug=False, **kwargs):
|
||||
def handle_remove_workouts_team(ws, t, debug=False, **kwargs): # pragma: no cover
|
||||
for w in ws:
|
||||
w.team.remove(t)
|
||||
|
||||
return 1
|
||||
|
||||
@app.task
|
||||
def handle_add_workouts_team(ws, t, debug=False, **kwargs):
|
||||
def handle_add_workouts_team(ws, t, debug=False, **kwargs): # pragma: no cover
|
||||
|
||||
for w in ws:
|
||||
w.team.add(t)
|
||||
@@ -350,7 +350,7 @@ def handle_add_workouts_team(ws, t, debug=False, **kwargs):
|
||||
return 1
|
||||
|
||||
def uploadactivity(access_token, filename, description='',
|
||||
name='Rowsandall.com workout'):
|
||||
name='Rowsandall.com workout'): # pragma: no cover
|
||||
|
||||
data_gz = BytesIO()
|
||||
try:
|
||||
@@ -393,7 +393,7 @@ def uploadactivity(access_token, filename, description='',
|
||||
|
||||
|
||||
@app.task
|
||||
def check_tp_workout_id(workout, location, attempts=5, debug=False, **kwargs):
|
||||
def check_tp_workout_id(workout, location, attempts=5, debug=False, **kwargs): # pragma: no cover
|
||||
authorizationstring = str('Bearer ' + workout.user.tptoken)
|
||||
headers = {'Authorization': authorizationstring,
|
||||
'user-agent': 'sanderroosendaal',
|
||||
@@ -411,7 +411,7 @@ def check_tp_workout_id(workout, location, attempts=5, debug=False, **kwargs):
|
||||
return 1
|
||||
|
||||
@app.task
|
||||
def handle_workout_tp_upload(w, thetoken, tcxfilename, debug=False, **kwargs):
|
||||
def handle_workout_tp_upload(w, thetoken, tcxfilename, debug=False, **kwargs): # pragma: no cover
|
||||
tpid = 0
|
||||
r = w.user
|
||||
if not tcxfilename:
|
||||
@@ -443,7 +443,7 @@ def handle_workout_tp_upload(w, thetoken, tcxfilename, debug=False, **kwargs):
|
||||
return tpid
|
||||
|
||||
@app.task
|
||||
def instroke_static(w, metric, debug=False, **kwargs):
|
||||
def instroke_static(w, metric, debug=False, **kwargs): # pragma: no cover
|
||||
f1 = w.csvfilename[6:-4]
|
||||
rowdata = rdata(csvfile=w.csvfilename)
|
||||
|
||||
@@ -512,7 +512,7 @@ def handle_c2_sync(workoutid, url, headers, data, debug=False, **kwargs):
|
||||
|
||||
try:
|
||||
workout = Workout.objects.get(id=workoutid)
|
||||
except Workout.DoesNotExist:
|
||||
except Workout.DoesNotExist: # pragma: no cover
|
||||
dologging('c2_log.log','failed for c2id {c2id}'.format(c2id=c2id))
|
||||
return 0
|
||||
|
||||
@@ -531,7 +531,7 @@ def handle_c2_sync(workoutid, url, headers, data, debug=False, **kwargs):
|
||||
|
||||
return 1
|
||||
|
||||
def splitstdata(lijst):
|
||||
def splitstdata(lijst): # pragma: no cover
|
||||
t = []
|
||||
latlong = []
|
||||
while len(lijst) >= 2:
|
||||
@@ -543,7 +543,7 @@ def splitstdata(lijst):
|
||||
|
||||
@app.task
|
||||
def handle_sporttracks_workout_from_data(user, importid, source,
|
||||
workoutsource, debug=False, **kwargs):
|
||||
workoutsource, debug=False, **kwargs): # pragma: no cover
|
||||
|
||||
r = user.rower
|
||||
authorizationstring = str('Bearer ' + r.sporttrackstoken)
|
||||
@@ -812,7 +812,7 @@ def handle_strava_sync(stravatoken,
|
||||
if not failed:
|
||||
try:
|
||||
workout = Workout.objects.get(id=workoutid)
|
||||
except Workout.DoesNotExist:
|
||||
except Workout.DoesNotExist: # pragma: no cover
|
||||
return 0
|
||||
|
||||
workout.uploadedtostrava = res.id
|
||||
@@ -1562,7 +1562,7 @@ def handle_calctrimp(id,
|
||||
|
||||
try:
|
||||
workout = Workout.objects.get(id=id)
|
||||
except Workout.DoesNotExist:
|
||||
except Workout.DoesNotExist: # pragma: no cover
|
||||
dologging('metrics.log','Could not find workout {id}'.format(id=id))
|
||||
return 0
|
||||
|
||||
@@ -2037,7 +2037,7 @@ def handle_sendemail_expired(useremail, userfirstname, userlastname, expireddate
|
||||
return 1
|
||||
|
||||
@app.task
|
||||
def handle_sendemail_newftp(rower,power,mode, **kwargs):
|
||||
def handle_sendemail_newftp(rower,power,mode, **kwargs): # pragma: no cover
|
||||
subject = "You may want to update your FTP on rowsandall.com"
|
||||
from_email = 'Rowsandall <info@rowsandall.com>'
|
||||
|
||||
@@ -2069,7 +2069,7 @@ def handle_sendemail_breakthrough(workoutid, useremail,
|
||||
|
||||
lastname = ''
|
||||
|
||||
if surname:
|
||||
if surname: # pragma: no cover
|
||||
lastname = userlastname
|
||||
|
||||
tablevalues = [
|
||||
@@ -2122,7 +2122,7 @@ def handle_sendemail_hard(workoutid, useremail,
|
||||
]
|
||||
|
||||
lastname = ''
|
||||
if surname:
|
||||
if surname: # pragma: no cover
|
||||
lastname = userlastname
|
||||
|
||||
# send email with attachment
|
||||
@@ -3414,7 +3414,7 @@ def handle_nk_async_workout(alldata, userid, nktoken, nkid, delaysec, defaulttim
|
||||
jsonData = response.json()
|
||||
try:
|
||||
strokeData = jsonData[str(nkid)]
|
||||
except KeyError:
|
||||
except KeyError: # pragma: no cover
|
||||
dologging('nklog.log','Could not find strokeData')
|
||||
return 0
|
||||
|
||||
@@ -3424,7 +3424,7 @@ def handle_nk_async_workout(alldata, userid, nktoken, nkid, delaysec, defaulttim
|
||||
if oarlockSessions:
|
||||
oarlocksession = oarlockSessions[0]
|
||||
seatNumber = oarlocksession['seatNumber']
|
||||
except KeyError:
|
||||
except KeyError: # pragma: no cover
|
||||
pass
|
||||
|
||||
df = strokeDataToDf(strokeData, seatIndex=seatNumber)
|
||||
@@ -3439,14 +3439,14 @@ def handle_nk_async_workout(alldata, userid, nktoken, nkid, delaysec, defaulttim
|
||||
workoutid, error = add_workout_from_data(userid, nkid, data, df)
|
||||
|
||||
# dologging('nklog.log','NK Workout ID {id}'.format(id=workoutid))
|
||||
if workoutid == 0:
|
||||
if workoutid == 0: # pragma: no cover
|
||||
return 0
|
||||
|
||||
try:
|
||||
workout = Workout.objects.get(id=workoutid)
|
||||
newnkid = workout.uploadedtonk
|
||||
sr = create_or_update_syncrecord(workout.user, workout, nkid=newnkid)
|
||||
except Workout.DoesNotExist:
|
||||
except Workout.DoesNotExist: # pragma: no cover
|
||||
pass
|
||||
|
||||
return workoutid
|
||||
@@ -3775,7 +3775,7 @@ def handle_c2_async_workout(alldata, userid, c2token, c2id, delaysec,
|
||||
return workoutid
|
||||
|
||||
@app.task
|
||||
def fetch_rojabo_session(id,alldata,userid,rowerid,debug=False, **kwargs):
|
||||
def fetch_rojabo_session(id,alldata,userid,rowerid,debug=False, **kwargs): # pragma: no cover
|
||||
try:
|
||||
item = alldata[id]
|
||||
except KeyError:
|
||||
@@ -3880,7 +3880,7 @@ def fetch_strava_workout(stravatoken, oauth_data, stravaid, csvfilename, userid,
|
||||
wsize = round(5./dt)
|
||||
|
||||
velo2 = ewmovingaverage(velo, wsize)
|
||||
except ValueError:
|
||||
except ValueError: # pragma: no cover
|
||||
velo2 = velo
|
||||
|
||||
if coords is not None:
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -7,6 +7,7 @@ from __future__ import unicode_literals
|
||||
from .statements import *
|
||||
nu = datetime.datetime.now()
|
||||
|
||||
import rowers.courses as courses
|
||||
|
||||
|
||||
tested = [
|
||||
@@ -27,6 +28,14 @@ class URLTests(TestCase):
|
||||
r = Rower.objects.create(user=u,rowerplan='coach',gdproptin=True, ftpset=True,
|
||||
gdproptindate=timezone.now())
|
||||
self.c = Client()
|
||||
cs = courses.kmltocourse('rowers/tests/testdata/thyro.kml')
|
||||
course = cs[0]
|
||||
cname = course['name']
|
||||
cnotes = course['description']
|
||||
polygons = course['polygons']
|
||||
self.ThyroBaantje = courses.createcourse(r,cname,polygons,notes=cnotes)
|
||||
self.ThyroBaantje.save()
|
||||
|
||||
|
||||
self.nu = datetime.datetime.now()
|
||||
filename = 'rowers/tests/testdata/testdata.csv'
|
||||
@@ -168,6 +177,19 @@ class URLTests(TestCase):
|
||||
'/rowers/workout/upload/team/',
|
||||
'/rowers/workouts-join/',
|
||||
'/rowers/workouts-join-select/',
|
||||
'/rowers/api/courses/',
|
||||
'/rowers/api/courses/?name=Brno',
|
||||
'/rowers/api/courses/?course_distance=2000',
|
||||
'/rowers/api/courses/?course_distance=aap',
|
||||
'/rowers/api/courses/?distance_from=52&latitude=42&longitude=7',
|
||||
'/rowers/api/courses/?distance_from=50&latitude=42&longitude=-aap',
|
||||
'/rowers/api/courses/',
|
||||
'/rowers/api/courses/1/',
|
||||
'/rowers/list-workouts/?selectworkouts=true',
|
||||
'/rowers/api/courses/kml/',
|
||||
'/rowers/api/courses/kml/?id=1',
|
||||
'/rowers/api/courses/kml?id=1&id=4/',
|
||||
'/rowers/api/courses/kml/?id=aap',
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ class XMLParser(BaseParser):
|
||||
dologging("apilog.log", "XML Parser")
|
||||
try:
|
||||
s = ET.parse(stream).getroot()
|
||||
except Exception as e:
|
||||
except Exception as e: # pragma: no cover
|
||||
dologging("apilog.log",e)
|
||||
return HttpResponse(status=500)
|
||||
return s
|
||||
@@ -231,11 +231,11 @@ def strokedataform_v2(request, id=0):
|
||||
def part_of_day(hour):
|
||||
if 5 <= hour < 12:
|
||||
return "Morning"
|
||||
elif 12 <= hour < 18:
|
||||
elif 12 <= hour < 18: # pragma: no cover
|
||||
return "Afternoon"
|
||||
elif 18 <= hour < 24:
|
||||
elif 18 <= hour < 24: # pragma: no cover
|
||||
return "Evening"
|
||||
else:
|
||||
else: # pragma: no cover
|
||||
return "Night"
|
||||
|
||||
# KML API views
|
||||
@@ -254,7 +254,7 @@ Optional, not for CN
|
||||
@api_view(["GET"])
|
||||
@permission_classes([AllowAny])
|
||||
def course_list(request):
|
||||
if request.method != 'GET':
|
||||
if request.method != 'GET': # pragma: no cover
|
||||
dologging('apilog.log','{m} request to KML endpoint'.format(m=request.method))
|
||||
return HttpResponseNotAllowed("Method not supported")
|
||||
|
||||
@@ -281,7 +281,7 @@ def course_list(request):
|
||||
newlist = []
|
||||
for c in courses:
|
||||
distance = geo_distance(float(latitude), float(longitude), c.coord[0], c.coord[1])[0]
|
||||
if distance < float(distance_from):
|
||||
if distance < float(distance_from): # pragma: no cover
|
||||
newlist.append(c)
|
||||
courses = newlist
|
||||
except ValueError:
|
||||
@@ -307,13 +307,13 @@ def course_list(request):
|
||||
@api_view(["GET"])
|
||||
@permission_classes([AllowAny])
|
||||
def get_crewnerd_kml(request,id=0):
|
||||
if request.method != 'GET':
|
||||
if request.method != 'GET': # pragma: no cover
|
||||
dologging('apilog.log','{m} request to CrewNerd KML endpoint'.format(m=request.method))
|
||||
return HttpResponseNotAllowed("Method not supported")
|
||||
|
||||
try:
|
||||
c = GeoCourse.objects.get(id=id)
|
||||
except GeoCourse.DoesNotExist:
|
||||
except GeoCourse.DoesNotExist: # pragma: no cover
|
||||
raise Http404("This course does not exist")
|
||||
|
||||
kml = coursetokml(c, cn=True)
|
||||
@@ -324,14 +324,20 @@ def get_crewnerd_kml(request,id=0):
|
||||
@api_view(["GET"])
|
||||
@permission_classes([AllowAny])
|
||||
def get_crewnerd_multiple(request):
|
||||
if request.method != 'GET':
|
||||
if request.method != 'GET': # pragma: no cover
|
||||
dologging('apilog.log','{m} request to CrewNerd KML endpoint'.format(m=request.method))
|
||||
return HttpResponseNotAllowed("Method not supported")
|
||||
|
||||
ids = request.GET.get('id')
|
||||
if ids is not None:
|
||||
tdict = dict(request.GET.lists())
|
||||
ids = [int(id) for id in tdict['id']]
|
||||
idsnew = []
|
||||
for id in tdict['id']:
|
||||
try:
|
||||
idsnew.append(int(id))
|
||||
except ValueError:
|
||||
pass
|
||||
ids = idsnew
|
||||
else:
|
||||
gcs = GeoCourse.objects.all()
|
||||
ids = [c.id for c in gcs]
|
||||
@@ -351,11 +357,11 @@ def strokedata_tcx(request):
|
||||
"""
|
||||
Upload a TCX file through API
|
||||
"""
|
||||
if request.method != 'POST':
|
||||
if request.method != 'POST': # pragma: no cover
|
||||
dologging('apilog.log','GET request to TCX endpoint')
|
||||
return HttpResponseNotAllowed("Method not supported") # pragma: no cover
|
||||
return HttpResponseNotAllowed("Method not supported")
|
||||
|
||||
if 'application/xml' not in request.content_type.lower():
|
||||
if 'application/xml' not in request.content_type.lower(): # pragma: no cover
|
||||
dologging('apilog.log','POST data not application/xml, request to TCX endpoint')
|
||||
dologging('apilog.log', request.content_type.lower())
|
||||
return HttpResponseNotAllowed("Need application/xml")
|
||||
@@ -382,7 +388,7 @@ def strokedata_tcx(request):
|
||||
lap_duration_seconds = float(lap_duration_node.text)
|
||||
total_duration += lap_duration_seconds
|
||||
|
||||
except Exception as e:
|
||||
except Exception as e: # pragma: no cover
|
||||
dologging('apilog.log','TCX')
|
||||
dologging('apilog.log',e)
|
||||
return HttpResponseNotAllowed("Could not parse TCX data")
|
||||
@@ -436,7 +442,7 @@ def strokedata_tcx(request):
|
||||
"workout id": workoutid,
|
||||
"status": "success",
|
||||
})
|
||||
except Exception as e:
|
||||
except Exception as e: # pragma: no cover
|
||||
dologging('apilog.log','TCX API endpoint')
|
||||
dologging('apilog.log',e)
|
||||
return HttpResponse(status=500)
|
||||
@@ -489,7 +495,7 @@ def strokedatajson_v3(request):
|
||||
title = request.data.get('name','')
|
||||
try:
|
||||
elapsedTime = request.data['elapsedTime']
|
||||
except KeyError:
|
||||
except KeyError: # pragma: no cover
|
||||
try:
|
||||
duration = request.data['duration']
|
||||
try:
|
||||
@@ -501,7 +507,7 @@ def strokedatajson_v3(request):
|
||||
return HttpResponse("Missing Elapsed Time", status=400)
|
||||
try:
|
||||
totalDistance = request.data['distance']
|
||||
except KeyError:
|
||||
except KeyError: # pragma: no cover
|
||||
return HttpResponse("Missing Total Distance", status=400)
|
||||
timeZone = request.data.get('timezone','UTC')
|
||||
workouttype = request.data.get('workouttype','rower')
|
||||
@@ -522,12 +528,12 @@ def strokedatajson_v3(request):
|
||||
df = pd.DataFrame()
|
||||
try:
|
||||
strokes = request.data['strokes']
|
||||
except KeyError:
|
||||
except KeyError: # pragma: no cover
|
||||
return HttpResponse("No Stroke Data in JSON", status=400)
|
||||
|
||||
try:
|
||||
df = pd.DataFrame(strokes['data'])
|
||||
except KeyError:
|
||||
except KeyError: # pragma: no cover
|
||||
try:
|
||||
df = pd.DataFrame(request.data['strokedata'])
|
||||
except:
|
||||
@@ -538,7 +544,7 @@ def strokedatajson_v3(request):
|
||||
|
||||
status, comment, data = api_get_dataframe(startdatetime, df)
|
||||
|
||||
if status != 200:
|
||||
if status != 200: # pragma: no cover
|
||||
return HttpResponse(comment, status=status)
|
||||
|
||||
|
||||
@@ -648,7 +654,7 @@ def strokedatajson_v2(request, id):
|
||||
try:
|
||||
for d in request.data['data']:
|
||||
dologging('apilog.log',json.dumps(d))
|
||||
except KeyError:
|
||||
except KeyError: # pragma: no cover
|
||||
try:
|
||||
for d in request.data['strokedata']:
|
||||
dologging('apilog.log',json.dumps(d))
|
||||
@@ -672,7 +678,7 @@ def strokedatajson_v2(request, id):
|
||||
df.sort_index(inplace=True)
|
||||
|
||||
status, comment, data = api_get_dataframe(row.startdatetime, df)
|
||||
if status != 200:
|
||||
if status != 200: # pragma: no cover
|
||||
return HttpResponse(comment, status=status)
|
||||
|
||||
r = getrower(request.user)
|
||||
|
||||
@@ -1664,7 +1664,7 @@ def course_compare_view(request, id=0):
|
||||
labeldict = {
|
||||
int(w.id): w.__str__() for w in workouts
|
||||
}
|
||||
except:
|
||||
except: # pragma: no cover
|
||||
labeldict = {}
|
||||
|
||||
res = interactive_multiple_compare_chart(workoutids, xparam, yparam,
|
||||
@@ -1846,7 +1846,7 @@ def virtualevent_compare_view(request, id=0):
|
||||
labeldict = {
|
||||
int(w.id): w.__str__() for w in workouts
|
||||
}
|
||||
except:
|
||||
except: # pragma: no cover
|
||||
labeldict = {}
|
||||
|
||||
res = interactive_multiple_compare_chart(workoutids, xparam, yparam,
|
||||
@@ -2085,7 +2085,7 @@ def workouts_bulk_actions(request):
|
||||
destination=destination))
|
||||
url = reverse('workouts_view')
|
||||
return HttpResponseRedirect(url)
|
||||
else:
|
||||
else: # pragma: no cover
|
||||
if len(workouts) == 0:
|
||||
url = reverse(workouts_view)
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
Reference in New Issue
Block a user