Private
Public Access
1
0

adding some tests for garmin training api

This commit is contained in:
Sander Roosendaal
2021-05-17 09:07:04 +02:00
parent e88553a04c
commit d195f03a55
3 changed files with 82 additions and 10 deletions

View File

@@ -133,7 +133,7 @@ def garmin_processcallback(redirect_response,resource_owner_key,resource_owner_s
verifier = oauth_response.get('oauth_verifier')
token = oauth_response.get('oauth_token')
access_token_url = 'https://connectapi.garmin.com/oauth-service/oauth/access_token'
print(token,access_token_url)
# Using OAuth1Session
garmin = OAuth1Session(oauth_data['client_id'],
@@ -193,9 +193,9 @@ def get_garmin_workout_list(user): # pragma: no cover
return result
def garmin_can_export_session(user): # pragma: no cover
def garmin_can_export_session(user):
if user.rower.rowerplan not in ['coach','plan']:
return False
return False # pragma: no cover
result = get_garmin_permissions(user)
if 'WORKOUT_IMPORT' in result:
return True
@@ -215,10 +215,10 @@ def step_to_garmin(step,order=0):
except KeyError:
intensity = None
#durationvaluetype = ''
if durationtype == 'Time': # pragma: no cover
if durationtype == 'Time':
durationtype = 'TIME'
durationvalue = int(durationvalue/1000.)
elif durationtype == 'Distance': # pragma: no cover
elif durationtype == 'Distance':
durationtype = 'DISTANCE'
durationvalue = int(durationvalue/100)
durationvaluetype = 'METER'
@@ -375,7 +375,7 @@ def ps_to_garmin(ps,r):
def get_garmin_permissions(user): # pragma: no cover
def get_garmin_permissions(user):
r = Rower.objects.get(user=user)
if (r.garmintoken == '') or (r.garmintoken is None):
s = "Token doesn't exist. Need to authorize"
@@ -399,7 +399,7 @@ def get_garmin_permissions(user): # pragma: no cover
return []
def garmin_session_create(ps,user): # pragma: no cover
def garmin_session_create(ps,user):
if not ps.steps:
return 0
if not garmin_can_export_session(user):
@@ -427,15 +427,13 @@ def garmin_session_create(ps,user): # pragma: no cover
response = requests.post(url,auth=garminheaders,json=payload)
if response.status_code != 200:
return 0
garmin_workout_id = response.json()['workoutId']
url = 'http://apis.garmin.com/training-api/schedule'
url = 'https://apis.garmin.com/training-api/schedule'
payload = {
'workoutId': garmin_workout_id,
@@ -444,6 +442,7 @@ def garmin_session_create(ps,user): # pragma: no cover
response = requests.post(url,auth=garminheaders,json=payload)
if response.status_code != 200:
return 0