increase test coverage
This commit is contained in:
@@ -247,7 +247,7 @@ def get_nk_workout_list(user,fake=False,after=0,before=0):
|
||||
|
||||
#
|
||||
|
||||
def get_workout(user,nkid,do_async=False):
|
||||
def get_workout(user,nkid,do_async=True):
|
||||
r = Rower.objects.get(user=user)
|
||||
if (r.nktoken == '') or (r.nktoken is None): # pragma: no cover
|
||||
s = "Token doesn't exist. Need to authorize"
|
||||
@@ -260,79 +260,22 @@ def get_workout(user,nkid,do_async=False):
|
||||
'sessionIds': nkid,
|
||||
}
|
||||
|
||||
if do_async: # pragma: no cover
|
||||
res = get_nk_workout_list(r.user)
|
||||
if res.status_code != 200:
|
||||
return 0
|
||||
alldata = {}
|
||||
for item in res.json():
|
||||
alldata[item['id']] = item
|
||||
res = get_nk_workout_list(r.user)
|
||||
if res.status_code != 200: # pragma: no cover
|
||||
return 0
|
||||
alldata = {}
|
||||
for item in res.json():
|
||||
alldata[item['id']] = item
|
||||
|
||||
res = myqueue(
|
||||
queuehigh,
|
||||
handle_nk_async_workout,
|
||||
alldata,
|
||||
r.user.id,
|
||||
r.nktoken,
|
||||
nkid,
|
||||
0,
|
||||
r.defaulttimezone,
|
||||
)
|
||||
res = myqueue(
|
||||
queuehigh,
|
||||
handle_nk_async_workout,
|
||||
alldata,
|
||||
r.user.id,
|
||||
r.nktoken,
|
||||
nkid,
|
||||
0,
|
||||
r.defaulttimezone,
|
||||
)
|
||||
|
||||
return {},pd.DataFrame()
|
||||
|
||||
|
||||
authorizationstring = str('Bearer ' + r.nktoken)
|
||||
headers = {'Authorization': authorizationstring,
|
||||
'user-agent': 'sanderroosendaal',
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
|
||||
# get strokes
|
||||
url = NK_API_LOCATION+"api/v1/sessions/strokes"
|
||||
|
||||
response = requests.get(url,headers=headers,params=params)
|
||||
|
||||
if response.status_code != 200: # pragma: no cover
|
||||
# error handling and logging
|
||||
return {},pd.DataFrame()
|
||||
|
||||
jsonData = response.json()
|
||||
|
||||
strokeData = jsonData[str(nkid)]
|
||||
|
||||
df = strokeDataToDf(strokeData)
|
||||
|
||||
# get workout data
|
||||
after = df['timestamp'].min()
|
||||
before = df['timestamp'].max()
|
||||
|
||||
after = arrow.get(after/1000.)
|
||||
before = arrow.get(before/1000.)
|
||||
after = after-timedelta(days=1)
|
||||
before = before+timedelta(days=1)
|
||||
before = str(int(before.timestamp())*1000)
|
||||
after = str(int(after.timestamp())*1000)
|
||||
|
||||
|
||||
url = NK_API_LOCATION+"api/v1/sessions/"
|
||||
params = {
|
||||
'after':after,
|
||||
'before': before,
|
||||
}
|
||||
|
||||
response = requests.get(url, headers=headers,params=params)
|
||||
|
||||
if response.status_code != 200: # pragma: no cover
|
||||
# error handling and logging
|
||||
return {},df
|
||||
|
||||
jsondata = response.json()
|
||||
workoutdata = {}
|
||||
|
||||
for w in jsondata:
|
||||
if str(w['id']) == str(nkid):
|
||||
workoutdata = w
|
||||
|
||||
|
||||
return workoutdata, df
|
||||
return res
|
||||
|
||||
Reference in New Issue
Block a user