Private
Public Access
1
0

more payment view coverage tests

This commit is contained in:
Sander Roosendaal
2021-04-25 17:41:04 +02:00
parent e19158926d
commit df86eaac0c
11 changed files with 448 additions and 169 deletions

View File

@@ -50,7 +50,7 @@ from rowers.utils import (
def cleanbody(body):
try:
body = body.decode('utf-8')
except AttributeError:
except AttributeError: # pragma: no cover
pass
regex = r".*---\n([\s\S]*?)\.\.\..*"
@@ -72,7 +72,7 @@ def matchsource(line):
testert = '^source.*(%s)' % s
tester = re.compile(testert)
if tester.match(line.lower()):
if tester.match(line.lower()): # pragma: no cover
return tester.match(line.lower()).group(1)
# currently only matches one chart
@@ -88,7 +88,7 @@ def matchchart(line):
tester3 = re.compile(tester3t)
tester4 = re.compile(tester4t)
if tester.match(line.lower()):
if tester.match(line.lower()): # pragma: no cover
if tester2.match(line.lower()):
return 'distanceplot'
if tester3.match(line.lower()):
@@ -112,7 +112,7 @@ def matchrace(line):
words = line.split()
try:
return int(words[1])
except:
except: # pragma: no cover
return None
return None
@@ -129,7 +129,7 @@ def matchsync(line):
tester = re.compile(tester)
if tester.match(line.lower()):
if tester.match(line.lower()): # pragma: no cover
testers = [
('upload_to_C2',re.compile(tester2)),
('upload_totp',re.compile(tester3)),
@@ -148,7 +148,7 @@ def getstravaid(uploadoptions,body):
stravaid = 0
tester = re.compile('^(stravaid)(.*?)(\d+)')
for line in body.splitlines():
if tester.match(line.lower()):
if tester.match(line.lower()): # pragma: no cover
stravaid = tester.match(line.lower()).group(3)
uploadoptions['stravaid'] = int(stravaid)
@@ -183,7 +183,7 @@ def gettypeoptions_body2(uploadoptions,body):
def getprivateoptions_body2(uploadoptions,body):
tester = re.compile('^(priva)')
for line in body.splitlines():
if tester.match(line.lower()):
if tester.match(line.lower()): # pragma: no cover
v = True
negs = ['false','False','None','no']
for neg in negs:
@@ -199,7 +199,7 @@ def getprivateoptions_body2(uploadoptions,body):
def getworkoutsources(uploadoptions,body):
for line in body.splitlines():
workoutsource = matchsource(line)
if workoutsource:
if workoutsource: # pragma: no cover
uploadoptions['workoutsource'] = workoutsource
return uploadoptions
@@ -207,7 +207,7 @@ def getworkoutsources(uploadoptions,body):
def getplotoptions_body2(uploadoptions,body):
for line in body.splitlines():
chart = matchchart(line)
if chart:
if chart: # pragma: no cover
uploadoptions['make_plot'] = True
uploadoptions['plottype'] = chart
@@ -236,12 +236,12 @@ def getsyncoptions_body2(uploadoptions,body):
result = list(set(result))
for r in result:
for r in result: # pragma: no cover
uploadoptions[r] = True
return uploadoptions
def getsyncoptions(uploadoptions,values):
def getsyncoptions(uploadoptions,values): # pragma: no cover
try:
value = values.lower()
values = [values]
@@ -269,7 +269,7 @@ def getsyncoptions(uploadoptions,values):
return uploadoptions
def getplotoptions(uploadoptions,value):
def getplotoptions(uploadoptions,value): # pragma: no cover
try:
v = value.lower()
if v in ['pieplot','timeplot','distanceplot']:
@@ -290,7 +290,7 @@ def getplotoptions(uploadoptions,value):
return uploadoptions
def gettype(uploadoptions,value,key):
def gettype(uploadoptions,value,key): # pragma: no cover
workouttype = 'rower'
for typ,verb in workouttypes_ordered.items():
if value == typ:
@@ -304,7 +304,7 @@ def gettype(uploadoptions,value,key):
return uploadoptions
def getboattype(uploadoptions,value,key):
def getboattype(uploadoptions,value,key): # pragma: no cover
boattype = '1x'
for type,verb in boattypes:
if value == type:
@@ -316,12 +316,12 @@ def getboattype(uploadoptions,value,key):
return uploadoptions
def getuser(uploadoptions,value,key):
def getuser(uploadoptions,value,key): # pragma: no cover
uploadoptions['username'] = value
return uploadoptions
def getrace(uploadoptions,value,key):
def getrace(uploadoptions,value,key): # pragma: no cover
try:
raceid = int(value)
uploadoptions['raceid'] = raceid
@@ -330,7 +330,7 @@ def getrace(uploadoptions,value,key):
return uploadoptions
def getsource(uploadoptions,value,key):
def getsource(uploadoptions,value,key): # pragma: no cover
workoutsource = 'unknown'
for type,verb in workoutsources:
if value == type:
@@ -342,7 +342,7 @@ def getsource(uploadoptions,value,key):
return uploadoptions
def getboolean(uploadoptions,value,key):
def getboolean(uploadoptions,value,key): # pragma: no cover
b = True
if not value:
b = False
@@ -361,10 +361,10 @@ def upload_options(body):
body = cleanbody(body)
try:
yml = (yaml.safe_load(body))
if yml and 'fromuploadform' in yml:
if yml and 'fromuploadform' in yml: # pragma: no cover
return yml
try:
for key, value in yml.iteritems():
for key, value in yml.iteritems(): # pragma: no cover
lowkey = key.lower()
if lowkey == 'sync' or lowkey == 'synchronization' or lowkey == 'export':
uploadoptions = getsyncoptions(uploadoptions,value)
@@ -395,7 +395,7 @@ def upload_options(body):
uploadoptions = getworkoutsources(uploadoptions,body)
uploadoptions = getuseroptions_body2(uploadoptions,body)
uploadoptions = getraceoptions_body2(uploadoptions,body)
except IOError:
except IOError: # pragma: no cover
pm = exc.problem_mark
strpm = str(pm)
pbm = "Your email has an issue on line {} at position {}. The error is: ".format(
@@ -404,7 +404,7 @@ def upload_options(body):
)+strpm
return {'error':pbm}
if uploadoptions == {}:
if uploadoptions == {}: # pragma: no cover
uploadoptions['message'] = 'No parsing issue. No valid commands detected'
return uploadoptions
@@ -445,7 +445,7 @@ def make_plot(r,w,f1,f2,plottype,title,imagename='',plotnr=0):
}
axis = r.staticgrids
if axis == None:
if axis == None: # pragma: no cover
gridtrue = False
axis = 'both'
else:
@@ -482,7 +482,7 @@ def make_plot(r,w,f1,f2,plottype,title,imagename='',plotnr=0):
width=width,height=height)
i.save()
else:
else: # pragma: no cover
return 0,'You have reached the maximum number of static images for this workout. Delete an image first'
return i.id,job.id
@@ -500,24 +500,24 @@ def set_workouttype(w,options):
try:
w.workouttype = options['workouttype']
w.save()
except KeyError:
except KeyError: # pragma: no cover
pass
try:
w.boattype = options['boattype']
w.save()
except KeyError:
except KeyError: # pragma: no cover
pass
return 1
def set_workoutsource(w,options):
def set_workoutsource(w,options): # pragma: no cover
try:
w.workoutsource = options['workoutsource']
w.save()
except KeyError:
except KeyError: # pragma: no cover
pass
def make_private(w,options):
def make_private(w,options): # pragma: no cover
if 'makeprivate' in options and options['makeprivate']:
w.privacy = 'hidden'
w.save()
@@ -533,7 +533,7 @@ def do_sync(w,options, quick=False):
upload_to_strava = False
try:
if options['stravaid'] != 0 and options['stravaid'] != '':
if options['stravaid'] != 0 and options['stravaid'] != '': # pragma: no cover
w.uploadedtostrava = options['stravaid']
upload_to_strava = False
do_strava_export = False
@@ -542,27 +542,27 @@ def do_sync(w,options, quick=False):
pass
try:
if options['nkid'] != 0 and options['nkid'] != '':
if options['nkid'] != 0 and options['nkid'] != '': # pragma: no cover
w.uploadedtonk = options['nkid']
w.save()
except KeyError:
pass
try:
if options['inboard'] != 0 and options['inboard'] != '':
if options['inboard'] != 0 and options['inboard'] != '': # pragma: no cover
w.inboard = options['inboard']
except KeyError:
pass
try:
if options['oarlength'] != 0 and options['oarlength'] != '':
if options['oarlength'] != 0 and options['oarlength'] != '': # pragma: no cover
w.oarlength = options['oarlength']
except KeyError:
pass
try:
if options['garminid'] != 0 and options['garminid'] != '':
if options['garminid'] != 0 and options['garminid'] != '': # pragma: no cover
w.uploadedtogarmin = options['garminid']
w.save()
except KeyError:
@@ -575,7 +575,7 @@ def do_sync(w,options, quick=False):
upload_to_c2 = False
try:
if options['c2id'] != 0 and options['c2id'] != '':
if options['c2id'] != 0 and options['c2id'] != '': # pragma: no cover
w.uploadedtoc2 = options['c2id']
upload_to_c2 = False
do_c2_export = False
@@ -584,7 +584,7 @@ def do_sync(w,options, quick=False):
pass
try:
if options['rp3id'] != 0 and options['rp3id'] != '':
if options['rp3id'] != 0 and options['rp3id'] != '': # pragma: no cover
w.uploadedtorp3 = options['rp3id']
w.save()
except KeyError:
@@ -599,15 +599,15 @@ def do_sync(w,options, quick=False):
except NoTokenError:
id = 0
message = "Something went wrong with the Concept2 sync"
except:
except: # pragma: no cover
pass
if do_strava_export:
if do_strava_export: # pragma: no cover
try:
message,id = stravastuff.workout_strava_upload(
w.user.user,w,quick=quick,asynchron=True,
)
except NoTokenError:
except NoTokenError: # pragma: no cover
id = 0
message = "Please connect to Strava first"
except:
@@ -626,7 +626,7 @@ def do_sync(w,options, quick=False):
message,id = sporttracksstuff.workout_sporttracks_upload(
w.user.user,w,asynchron=True,
)
with open('st_export.log','a') as logfile:
with open('st_export.log','a') as logfile: # pragma: no cover
logfile.write(str(timezone.now())+': ')
logfile.write('Workout uploaded '+str(w.id)+'\n')
except NoTokenError:
@@ -637,7 +637,7 @@ def do_sync(w,options, quick=False):
id = 0
if ('upload_to_RunKeeper' in options and options['upload_to_RunKeeper']) or (w.user.runkeeper_auto_export):
if ('upload_to_RunKeeper' in options and options['upload_to_RunKeeper']) or (w.user.runkeeper_auto_export): # pragma: no cover
try:
message,id = runkeeperstuff.workout_runkeeper_upload(
w.user.user,w,asynchron=True,
@@ -646,7 +646,7 @@ def do_sync(w,options, quick=False):
message = "Please connect to Runkeeper first"
id = 0
if ('upload_to_MapMyFitness' in options and options['upload_to_MapMyFitness']) or (w.user.mapmyfitness_auto_export):
if ('upload_to_MapMyFitness' in options and options['upload_to_MapMyFitness']) or (w.user.mapmyfitness_auto_export): # pragma: no cover
try:
message,id = underarmourstuff.workout_ua_upload(
w.user.user,w
@@ -656,7 +656,7 @@ def do_sync(w,options, quick=False):
id = 0
if ('upload_to_TrainingPeaks' in options and options['upload_to_TrainingPeaks']) or (w.user.trainingpeaks_auto_export):
if ('upload_to_TrainingPeaks' in options and options['upload_to_TrainingPeaks']) or (w.user.trainingpeaks_auto_export): # pragma: no cover
try:
message,id = tpstuff.workout_tp_upload(
w.user.user,w