passing tests
This commit is contained in:
@@ -2958,6 +2958,7 @@ def handle_rp3_async_workout(userid,rp3token,rp3id,startdatetime,max_attempts,de
|
|||||||
@app.task
|
@app.task
|
||||||
def handle_nk_async_workout(alldata,userid,nktoken,nkid,delaysec,defaulttimezone,debug=False,**kwargs):
|
def handle_nk_async_workout(alldata,userid,nktoken,nkid,delaysec,defaulttimezone,debug=False,**kwargs):
|
||||||
time.sleep(delaysec)
|
time.sleep(delaysec)
|
||||||
|
|
||||||
data = alldata[nkid]
|
data = alldata[nkid]
|
||||||
|
|
||||||
params = {
|
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')
|
df.to_csv(csvfilename, index_label='index', compression='gzip')
|
||||||
|
|
||||||
#res = add_workout_from_data(userid,nkid,data,df)
|
workoutid,error = 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
|
|
||||||
|
|
||||||
if debug:
|
if debug:
|
||||||
engine = create_engine(database_url_debug, echo=False)
|
engine = create_engine(database_url_debug, echo=False)
|
||||||
|
|||||||
@@ -424,6 +424,25 @@ class NKObjects(DjangoTestCase):
|
|||||||
|
|
||||||
self.assertEqual(response.status_code,200)
|
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.get', side_effect=mocked_requests)
|
||||||
@patch('rowers.nkstuff.requests.post', side_effect=mocked_requests)
|
@patch('rowers.nkstuff.requests.post', side_effect=mocked_requests)
|
||||||
|
|||||||
Reference in New Issue
Block a user