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