Private
Public Access
1
0

passing tests for nk_list

This commit is contained in:
Sander Roosendaal
2021-04-01 11:10:51 +02:00
parent 5c6ed8ef16
commit 047035f62e
6 changed files with 19 additions and 15 deletions

View File

@@ -97,6 +97,7 @@ def nk_open(user):
raise NoTokenError("User has no token")
else:
if (timezone.now()>r.nktokenexpirydate):
print('refreshing token')
thetoken = rower_nk_token_refresh(user)
if thetoken == None:
raise NoTokenError("User has no token")
@@ -115,10 +116,7 @@ def do_refresh_token(refreshtoken):
url = oauth_data['base_url']
response = requests.post(url,data=post_data,auth=HTTPBasicAuth(oauth_data['client_id'],oauth_data['client_secret']))
print(response.request.headers)
print(post_data)
print(response.status_code,response.text)
print(response.status_code)
if response.status_code != 200:
return [0,0,0]
@@ -152,11 +150,11 @@ def make_authorization_url(request):
def get_nk_workout_list(user,fake=False):
r = Rower.objects.get(user=user)
print(r.nktoken,r.nktokenexpirydate)
if (r.nktoken == '') or (r.nktoken is None):
s = "Token doesn't exist. Need to authorize"
return custom_exception_handler(401,s)
elif (r.nktokenexpirydate is None or timezone.now()+timedelta(seconds=3599)>r.nktokenexpirydate):
elif (r.nktokenexpirydate is None or timezone.now()+timedelta(seconds=10)>r.nktokenexpirydate):
s = "Token expired. Needs to refresh."
return custom_exception_handler(401,s)
else:
@@ -179,7 +177,7 @@ def get_nk_workout_list(user,fake=False):
} # start / end time
s = requests.get(url,headers=headers,params=params)
#print(s.status_code,s.json())
return s