Private
Public Access
1
0

better tests

This commit is contained in:
2024-02-29 18:08:46 +01:00
parent 4fd98fbbab
commit cf31c1e750
5 changed files with 894 additions and 835 deletions

View File

@@ -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)

View File

@@ -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)