Private
Public Access
1
0

passing tests

This commit is contained in:
Sander Roosendaal
2021-04-07 08:49:25 +02:00
parent c0b4b517ed
commit 13af1d3d71
2 changed files with 21 additions and 54 deletions

View File

@@ -2958,6 +2958,7 @@ def handle_rp3_async_workout(userid,rp3token,rp3id,startdatetime,max_attempts,de
@app.task
def handle_nk_async_workout(alldata,userid,nktoken,nkid,delaysec,defaulttimezone,debug=False,**kwargs):
time.sleep(delaysec)
data = alldata[nkid]
params = {
@@ -2995,60 +2996,7 @@ def handle_nk_async_workout(alldata,userid,nktoken,nkid,delaysec,defaulttimezone
df.to_csv(csvfilename, index_label='index', compression='gzip')
#res = add_workout_from_data(userid,nkid,data,df)
title = data["name"]
speedInput = data["speedInput"]
elapsedTime = data["elapsedTime"]
totalDistanceGps = data["totalDistanceGps"]
totalDistanceImp = data["totalDistanceImp"]
intervals = data["intervals"] # add intervals
oarlockSessions = data["oarlockSessions"]
deviceId = data["deviceId"] # you could get the firmware version
summary = get_nk_allstats(data,df)
# oarlock inboard, length, boat name
if oarlockSessions:
oarlocksession = oarlockSessions[0] # should take seatIndex
boatName = oarlocksession["boatName"]
oarLength = oarlocksession["oarLength"] # cm
oarInboardLength = oarlocksession["oarInboardLength"] # cm
seatNumber = oarlocksession["seatNumber"]
else:
boatName = ''
oarLength = 289
oarInboardLength = 88
seatNumber = 1
workouttype = "water"
boattype = "1x"
uploadoptions = {
'secret': UPLOAD_SERVICE_SECRET,
'user':userid,
'file': csvfilename,
'title': title,
'workouttype': workouttype,
'boattype': boattype,
'nkid':nkid,
'inboard': oarInboardLength/100.,
'oarlength': oarLength/100.,
'summary':summary,
}
session = requests.session()
newHeaders = {'Content-type': 'application/json', 'Accept': 'text/plain'}
session.headers.update(newHeaders)
response = session.post(UPLOAD_SERVICE_URL,json=uploadoptions)
if response.status_code != 200:
return 0,response.text
try:
workoutid = response.json()['id']
except KeyError:
workoutid = 1
workoutid,error = add_workout_from_data(userid,nkid,data,df)
if debug:
engine = create_engine(database_url_debug, echo=False)

View File

@@ -424,6 +424,25 @@ class NKObjects(DjangoTestCase):
self.assertEqual(response.status_code,200)
@patch('rowers.nkimportutils.requests.session', side_effect=mocked_session)
@patch('rowers.tasks.requests.get', side_effects=mocked_requests)
def test_handle_nk_get_workouts(self, mocked_session, mock_get):
with open('rowers/tests/testdata/nk_list.json','r') as f:
data = json.load(f)
with open('rowers/tests/testdata/nk_strokes.json','r') as f:
strokeData = json.load(f)
alldata = {}
for item in data:
alldata[item['id']] = item
result = rowers.nkstuff.rower_nk_token_refresh(self.u)
res = tasks.handle_nk_async_workout(
alldata,self.r.user.id,self.r.nktoken,469,0,'UTC'
)
@patch('rowers.nkstuff.requests.get', side_effect=mocked_requests)
@patch('rowers.nkstuff.requests.post', side_effect=mocked_requests)