coverage
This commit is contained in:
@@ -106,8 +106,7 @@ def make_new_workout_from_email(rower, datafile, name, cntr=0,testing=False):
|
|||||||
path='media/')[6:]
|
path='media/')[6:]
|
||||||
fileformat = fileformat[2]
|
fileformat = fileformat[2]
|
||||||
|
|
||||||
if testing:
|
|
||||||
print('Fileformat = ',fileformat)
|
|
||||||
|
|
||||||
|
|
||||||
f,e = os.path.splitext(datafilename)
|
f,e = os.path.splitext(datafilename)
|
||||||
|
|||||||
@@ -282,14 +282,14 @@ def summaryfromsplitdata(splitdata,data,filename,sep='|',workouttype='rower'):
|
|||||||
|
|
||||||
|
|
||||||
@app.task
|
@app.task
|
||||||
def add(x, y):
|
def add(x, y): # pragma: no cover
|
||||||
return x + y
|
return x + y
|
||||||
|
|
||||||
|
|
||||||
@app.task
|
@app.task
|
||||||
def handle_c2_sync(workoutid,url,headers,data,debug=False,**kwargs):
|
def handle_c2_sync(workoutid,url,headers,data,debug=False,**kwargs):
|
||||||
response = requests.post(url,headers=headers,data=data)
|
response = requests.post(url,headers=headers,data=data)
|
||||||
if response.status_code not in [200,201]:
|
if response.status_code not in [200,201]: # pragma: no cover
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
s = response.json()
|
s = response.json()
|
||||||
@@ -302,7 +302,7 @@ def handle_c2_sync(workoutid,url,headers,data,debug=False,**kwargs):
|
|||||||
@app.task
|
@app.task
|
||||||
def handle_sporttracks_sync(workoutid,url,headers,data,debug=False,**kwargs):
|
def handle_sporttracks_sync(workoutid,url,headers,data,debug=False,**kwargs):
|
||||||
response = requests.post(url,headers=headers,data=data)
|
response = requests.post(url,headers=headers,data=data)
|
||||||
if response.status_code not in [200,201]:
|
if response.status_code not in [200,201]: # pragma: no cover
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
t = response.json()
|
t = response.json()
|
||||||
@@ -319,7 +319,7 @@ def handle_sporttracks_sync(workoutid,url,headers,data,debug=False,**kwargs):
|
|||||||
@app.task
|
@app.task
|
||||||
def handle_runkeeper_sync(workoutid,url,headers,data,debug=False,**kwargs):
|
def handle_runkeeper_sync(workoutid,url,headers,data,debug=False,**kwargs):
|
||||||
response = requests.post(url,headers=headers,data=data)
|
response = requests.post(url,headers=headers,data=data)
|
||||||
if response.status_code not in [200,201]:
|
if response.status_code not in [200,201]: # pragma: no cover
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
uri = response.headers["Location"]
|
uri = response.headers["Location"]
|
||||||
@@ -379,7 +379,7 @@ def handle_c2_import_stroke_data(c2token,
|
|||||||
starttimeunix,
|
starttimeunix,
|
||||||
csvfilename,debug=True,**kwargs):
|
csvfilename,debug=True,**kwargs):
|
||||||
|
|
||||||
if 'workouttype' in kwargs:
|
if 'workouttype' in kwargs: # pragma: no cover
|
||||||
workouttype = kwargs['workouttype']
|
workouttype = kwargs['workouttype']
|
||||||
else:
|
else:
|
||||||
workouttype = 'rower'
|
workouttype = 'rower'
|
||||||
@@ -398,7 +398,7 @@ def handle_c2_import_stroke_data(c2token,
|
|||||||
)
|
)
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
else:
|
else: # pragma: no cover
|
||||||
url = "https://log.concept2.com/api/users/me/results/{id}".format(id=c2id)
|
url = "https://log.concept2.com/api/users/me/results/{id}".format(id=c2id)
|
||||||
|
|
||||||
s = requests.get(url,headers=headers)
|
s = requests.get(url,headers=headers)
|
||||||
@@ -456,7 +456,7 @@ def getagegrouprecord(age,sex='male',weightcategory='hwt',
|
|||||||
duration = 60*int(duration)
|
duration = 60*int(duration)
|
||||||
try:
|
try:
|
||||||
df = indf[indf['duration'] == duration]
|
df = indf[indf['duration'] == duration]
|
||||||
except KeyError:
|
except KeyError: # pragma: no cover
|
||||||
df = pd.DataFrame()
|
df = pd.DataFrame()
|
||||||
|
|
||||||
if not df.empty:
|
if not df.empty:
|
||||||
@@ -478,13 +478,13 @@ def getagegrouprecord(age,sex='male',weightcategory='hwt',
|
|||||||
#power = np.polyval(poly_coefficients,age)
|
#power = np.polyval(poly_coefficients,age)
|
||||||
|
|
||||||
power = 0.5*(np.abs(power)+power)
|
power = 0.5*(np.abs(power)+power)
|
||||||
elif age is not None:
|
elif age is not None: # pragma: no cover
|
||||||
new_age = np.range([age])
|
new_age = np.range([age])
|
||||||
ww = griddata(ages.values,
|
ww = griddata(ages.values,
|
||||||
powers.values,
|
powers.values,
|
||||||
new_age,method='linear',rescale=True)
|
new_age,method='linear',rescale=True)
|
||||||
power = 0.5*(np.abs(power)+power)
|
power = 0.5*(np.abs(power)+power)
|
||||||
else:
|
else: # pragma: no cover
|
||||||
power = 0
|
power = 0
|
||||||
|
|
||||||
return power
|
return power
|
||||||
|
|||||||
@@ -349,9 +349,16 @@ def mocked_cpraw(*args, **kwargs):
|
|||||||
|
|
||||||
return df
|
return df
|
||||||
|
|
||||||
def StravaActivity():
|
class StravalibResponse():
|
||||||
|
def __init__(self,*args, **kwargs):
|
||||||
|
self.id = 1
|
||||||
|
|
||||||
|
class StravaActivity():
|
||||||
def wait(*args, **kwargs):
|
def wait(*args, **kwargs):
|
||||||
return 1
|
return StravalibResponse()
|
||||||
|
|
||||||
|
def __init__(*args, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -362,6 +369,9 @@ class MockStravalibClient():
|
|||||||
def update_activity(*args, **kwargs):
|
def update_activity(*args, **kwargs):
|
||||||
return StravaActivity()
|
return StravaActivity()
|
||||||
|
|
||||||
|
def __init__(*args,**kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
# Mocked Braintree
|
# Mocked Braintree
|
||||||
|
|
||||||
## Higher level - unfortunately didn't succeed in mocking the gateway
|
## Higher level - unfortunately didn't succeed in mocking the gateway
|
||||||
|
|||||||
@@ -68,6 +68,85 @@ class AsyncTaskTests(TestCase):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def test_summaryfromsplitdata(self):
|
||||||
|
splitdata = [
|
||||||
|
{
|
||||||
|
"type": "distance",
|
||||||
|
"time": 415,
|
||||||
|
"rest_time": 600,
|
||||||
|
"stroke_rate": 35,
|
||||||
|
"distance": 220,
|
||||||
|
"heart_rate": {
|
||||||
|
"ending": 160,
|
||||||
|
"rest": 60
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "distance",
|
||||||
|
"time": 347,
|
||||||
|
"rest_time": 600,
|
||||||
|
"stroke_rate": 45,
|
||||||
|
"distance": 220,
|
||||||
|
"heart_rate": {
|
||||||
|
"ending": 170,
|
||||||
|
"rest": 70
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"date": "2015-08-30 14:24:00",
|
||||||
|
"timezone": "Europe/London",
|
||||||
|
"distance": 440,
|
||||||
|
"time": 762,
|
||||||
|
"type": "rower",
|
||||||
|
"weight_class": "H",
|
||||||
|
"heart_rate": {
|
||||||
|
"average": 140
|
||||||
|
},
|
||||||
|
"workout_type": "FixedDistanceInterval",
|
||||||
|
"rest_distance": 43,
|
||||||
|
"rest_time": 1200,
|
||||||
|
"workout": {
|
||||||
|
"targets": {
|
||||||
|
"stroke_rate": 30,
|
||||||
|
"heart_rate_zone": 4,
|
||||||
|
"pace": 1050
|
||||||
|
},
|
||||||
|
"intervals": [
|
||||||
|
{
|
||||||
|
"type": "distance",
|
||||||
|
"time": 415,
|
||||||
|
"rest_time": 600,
|
||||||
|
"stroke_rate": 35,
|
||||||
|
"distance": 220,
|
||||||
|
"heart_rate": {
|
||||||
|
"ending": 160,
|
||||||
|
"rest": 60
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "distance",
|
||||||
|
"time": 347,
|
||||||
|
"rest_time": 600,
|
||||||
|
"stroke_rate": 45,
|
||||||
|
"distance": 220,
|
||||||
|
"heart_rate": {
|
||||||
|
"ending": 170,
|
||||||
|
"rest": 70
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res = tasks.summaryfromsplitdata(splitdata,data,'test.csv')
|
||||||
|
|
||||||
|
self.assertEqual(len(res[0]),478)
|
||||||
|
|
||||||
|
@patch('rowers.tasks.stravalib.Client', side_effect=MockStravalibClient)
|
||||||
|
def test_strava_sync(self,MockStravalibClient):
|
||||||
|
res = tasks.handle_strava_sync('aap',self.wwater.id,self.wwater.csvfilename,'aap','activitytype','aa')
|
||||||
|
self.assertEqual(res,1)
|
||||||
|
|
||||||
def test_safetimedelta(self):
|
def test_safetimedelta(self):
|
||||||
x = 5
|
x = 5
|
||||||
|
|||||||
Reference in New Issue
Block a user