Merge branch 'develop' into feature/newdataflow
This commit is contained in:
@@ -3247,9 +3247,6 @@ def handle_intervals_updateworkout(workout, debug=False, **kwargs):
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def df_from_summary(data):
|
def df_from_summary(data):
|
||||||
# distance = data['distance']
|
# distance = data['distance']
|
||||||
# c2id = data['id']
|
# c2id = data['id']
|
||||||
|
|||||||
@@ -955,6 +955,9 @@ def mocked_requests(*args, **kwargs):
|
|||||||
with open('rowers/tests/testdata/tpuploadresponse.txt','r') as f:
|
with open('rowers/tests/testdata/tpuploadresponse.txt','r') as f:
|
||||||
tpuploadresponse = json.load(f)
|
tpuploadresponse = json.load(f)
|
||||||
|
|
||||||
|
with open('rowers/tests/testdata/intervals.json','r') as f:
|
||||||
|
intervalsjson = json.load(f)
|
||||||
|
|
||||||
stravastreamjson = {
|
stravastreamjson = {
|
||||||
'time':stravatimejson,
|
'time':stravatimejson,
|
||||||
'velocity_smooth':stravavelojson,
|
'velocity_smooth':stravavelojson,
|
||||||
@@ -1136,6 +1139,7 @@ def mocked_requests(*args, **kwargs):
|
|||||||
garmintester = re.compile(r'.*?garmin\.com')
|
garmintester = re.compile(r'.*?garmin\.com')
|
||||||
fakturoidtester = re.compile(r'.*?fakturoid\.cz')
|
fakturoidtester = re.compile(r'.*?fakturoid\.cz')
|
||||||
idokladtester = re.compile(r'.*?idoklad\.cz')
|
idokladtester = re.compile(r'.*?idoklad\.cz')
|
||||||
|
intervalstester = re.compile(r'.*?intervals\.icu')
|
||||||
|
|
||||||
polarlistregex = r'.*?polaraccesslink\.com\/.*\/(\d+)$'
|
polarlistregex = r'.*?polaraccesslink\.com\/.*\/(\d+)$'
|
||||||
polarlisttester = re.compile(polarlistregex)
|
polarlisttester = re.compile(polarlistregex)
|
||||||
@@ -1441,10 +1445,6 @@ def mocked_requests(*args, **kwargs):
|
|||||||
pass
|
pass
|
||||||
json_data = rp3workoutlist
|
json_data = rp3workoutlist
|
||||||
return MockResponse(json_data,200)
|
return MockResponse(json_data,200)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if stravatester.match(args[0]):
|
if stravatester.match(args[0]):
|
||||||
if stravaworkoutlisttester.match(args[0]):
|
if stravaworkoutlisttester.match(args[0]):
|
||||||
@@ -1559,6 +1559,10 @@ def mocked_requests(*args, **kwargs):
|
|||||||
]
|
]
|
||||||
return MockResponse(response,200)
|
return MockResponse(response,200)
|
||||||
|
|
||||||
|
if intervalstester.match(args[0]):
|
||||||
|
return MockResponse(intervalsjson,200)
|
||||||
|
|
||||||
|
|
||||||
return MockResponse(None,404)
|
return MockResponse(None,404)
|
||||||
|
|
||||||
class MockEmailMessage:
|
class MockEmailMessage:
|
||||||
|
|||||||
@@ -27,6 +27,82 @@ import rowers.garmin_stuff as gs
|
|||||||
import rowers.integrations.strava as strava
|
import rowers.integrations.strava as strava
|
||||||
from rowers.nkimportutils import *
|
from rowers.nkimportutils import *
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
@override_settings(TESTING=True)
|
||||||
|
class IntervalsObjects(DjangoTestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.c = Client()
|
||||||
|
self.u = User.objects.create_user('john',
|
||||||
|
'sander@ds.ds',
|
||||||
|
'koeinsloot')
|
||||||
|
|
||||||
|
self.u.first_name = 'John'
|
||||||
|
self.u.last_name = 'Sander'
|
||||||
|
self.u.save()
|
||||||
|
self.r = Rower.objects.create(user=self.u,gdproptin=True, ftpset=True,surveydone=True,
|
||||||
|
gdproptindate=timezone.now()
|
||||||
|
)
|
||||||
|
self.r.save()
|
||||||
|
self.c.login(username='john',password='koeinsloot')
|
||||||
|
self.nu = datetime.datetime.now()
|
||||||
|
|
||||||
|
filename = 'rowers/tests/testdata/testdata.csv'
|
||||||
|
|
||||||
|
rr = rrower(hrmax=self.r.max,hrut2=self.r.ut2,
|
||||||
|
hrut1=self.r.ut1,hrat=self.r.at,
|
||||||
|
hrtr=self.r.tr,hran=self.r.an,ftp=self.r.ftp)
|
||||||
|
row = rdata(csvfile=filename,rower=rr)
|
||||||
|
totaldist = row.df['cum_dist'].max()
|
||||||
|
totaltime = row.df['TimeStamp (sec)'].max()-row.df['TimeStamp (sec)'].min()
|
||||||
|
totaltime = totaltime+row.df.loc[:,' ElapsedTime (sec)'].iloc[0]
|
||||||
|
|
||||||
|
|
||||||
|
hours = int(totaltime/3600.)
|
||||||
|
minutes = int((totaltime - 3600.*hours)/60.)
|
||||||
|
seconds = int(totaltime - 3600.*hours - 60.*minutes)
|
||||||
|
tenths = int(10*(totaltime - 3600.*hours - 60.*minutes - seconds))
|
||||||
|
|
||||||
|
duration = "%s:%s:%s.%s" % (hours,minutes,seconds,tenths)
|
||||||
|
|
||||||
|
|
||||||
|
workoutdate = row.rowdatetime.strftime('%Y-%m-%d')
|
||||||
|
workoutstarttime = row.rowdatetime.strftime('%H:%M:%S')
|
||||||
|
|
||||||
|
self.w = Workout.objects.create(
|
||||||
|
name='testworkout',workouttype='water',
|
||||||
|
user=self.r,date=self.nu.strftime('%Y-%m-%d'),
|
||||||
|
starttime=workoutstarttime,
|
||||||
|
startdatetime=row.rowdatetime,
|
||||||
|
duration=duration,distance=totaldist,
|
||||||
|
csvfilename=filename
|
||||||
|
)
|
||||||
|
self.u2 = User.objects.create_user('john2',
|
||||||
|
'ba@ds.ds',
|
||||||
|
'koeinsloot2')
|
||||||
|
self.u2.first_name = 'John'
|
||||||
|
self.u2.last_name = 'Sander2'
|
||||||
|
self.u2.save()
|
||||||
|
self.r2 = Rower.objects.create(user=self.u2,gdproptin=True, ftpset=True,surveydone=True,
|
||||||
|
gdproptindate=timezone.now()
|
||||||
|
)
|
||||||
|
|
||||||
|
self.w2 = Workout.objects.create(
|
||||||
|
name='testworkout',workouttype='water',
|
||||||
|
user=self.r2,date=self.nu.strftime('%Y-%m-%d'),
|
||||||
|
starttime=workoutstarttime,
|
||||||
|
startdatetime=row.rowdatetime,
|
||||||
|
duration=duration,distance=totaldist,
|
||||||
|
csvfilename=filename
|
||||||
|
)
|
||||||
|
|
||||||
|
@patch('rowers.tasks.requests.get', side_effect=mocked_requests)
|
||||||
|
@patch('rowers.tasks.requests.post', side_effect=mocked_requests)
|
||||||
|
def test_intervals_import(self, mock_get, mock_post):
|
||||||
|
res = tasks.handle_intervals_getworkout(self.r,
|
||||||
|
'12345',
|
||||||
|
'i101042071')
|
||||||
|
self.assertEqual(res,1)
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
@override_settings(TESTING=True)
|
@override_settings(TESTING=True)
|
||||||
class RojaboObjects(DjangoTestCase):
|
class RojaboObjects(DjangoTestCase):
|
||||||
|
|||||||
BIN
rowers/tests/testdata/testdata.tcx.gz
vendored
BIN
rowers/tests/testdata/testdata.tcx.gz
vendored
Binary file not shown.
@@ -133,6 +133,14 @@ def handle_intervals_getworkout(rower, intervalstoken, workoutid, debug=False, *
|
|||||||
|
|
||||||
data = response.json()
|
data = response.json()
|
||||||
|
|
||||||
|
try:
|
||||||
|
workoutsource = data['device_name']
|
||||||
|
except KeyError:
|
||||||
|
workoutsource = 'intervals.icu'
|
||||||
|
|
||||||
|
if 'garmin' in workoutsource.lower():
|
||||||
|
title = 'Garmin: '+ title
|
||||||
|
|
||||||
try:
|
try:
|
||||||
title = data['name']
|
title = data['name']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
@@ -205,6 +213,7 @@ def handle_intervals_getworkout(rower, intervalstoken, workoutid, debug=False, *
|
|||||||
'user': rower.user.id,
|
'user': rower.user.id,
|
||||||
'boattype': '1x',
|
'boattype': '1x',
|
||||||
'workouttype': workouttype,
|
'workouttype': workouttype,
|
||||||
|
'workoutsource': workoutsource,
|
||||||
'file': fit_filename,
|
'file': fit_filename,
|
||||||
'intervalsid': workoutid,
|
'intervalsid': workoutid,
|
||||||
'title': title,
|
'title': title,
|
||||||
|
|||||||
Reference in New Issue
Block a user