testing c2 import
This commit is contained in:
@@ -848,6 +848,9 @@ def get_workout(user,c2id,do_async=False):
|
||||
|
||||
data = s.json()['data']
|
||||
splitdata = None
|
||||
#with open('c2temp.json','w') as f:
|
||||
# f.write(json.dumps(s.json()))
|
||||
# print(s.json())
|
||||
|
||||
if 'workout' in data:
|
||||
if 'splits' in data['workout']: # pragma: no cover
|
||||
|
||||
@@ -2017,12 +2017,12 @@ def new_workout_from_file(r, f2,
|
||||
return -1, message, f2
|
||||
|
||||
# Some people try to upload Concept2 logbook summaries
|
||||
if fileformat == 'imageformat':
|
||||
if fileformat == 'imageformat': # pragma: no cover
|
||||
os.remove(f2)
|
||||
message = "You cannot upload image files here"
|
||||
return (0, message, f2)
|
||||
|
||||
if fileformat == 'json':
|
||||
if fileformat == 'json': # pragma: no cover
|
||||
os.remove(f2)
|
||||
message = "JSON format not supported in direct upload"
|
||||
return (0, message, f2)
|
||||
|
||||
@@ -994,32 +994,6 @@ class PowerIntervalUpdateForm(forms.Form):
|
||||
activeminutesmin = forms.IntegerField(required=False,initial=0,widget=forms.HiddenInput())
|
||||
activeminutesmax = forms.IntegerField(required=False,initial=0,widget=forms.HiddenInput())
|
||||
|
||||
# Form used to update interval stats
|
||||
class IntervalUpdateForm(forms.Form):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
typechoices = (
|
||||
(1,'single time'),
|
||||
(2,'single distance'),
|
||||
(3,'rest (time based)'),
|
||||
(3,'rest (distance based)'),
|
||||
(4,'work (time based)'),
|
||||
(5,'work (distance based)'),
|
||||
)
|
||||
aantal = int(kwargs.pop('aantal'))
|
||||
super(IntervalUpdateForm, self).__init__(*args, **kwargs)
|
||||
|
||||
for i in range(aantal):
|
||||
self.fields['intervalt_%s' % i] = forms.DurationField(label='Time '+str(i+1))
|
||||
self.fields['intervald_%s' % i] = forms.IntegerField(label='Distance '+str(i+1))
|
||||
self.fields['type_%s' % i] = forms.ChoiceField(choices=typechoices,
|
||||
required=True,
|
||||
initial=4,
|
||||
label = 'Type '+str(i+1))
|
||||
self.fields['intervalt_%s' % i].widget.attrs['style'] = 'width:76px; height: 16px;'
|
||||
self.fields['intervald_%s' % i].widget.attrs['style'] = 'width:76px; height: 16px;'
|
||||
self.fields['type_%s' % i].widget.attrs['style'] = 'width:156px; height: 22px;'
|
||||
self.fields['intervald_%s' % i].widget = forms.TimeInput(format='%H:%M:%S.%f')
|
||||
|
||||
boattypes = mytypes.boattypes
|
||||
workouttypes = mytypes.workouttypes
|
||||
|
||||
@@ -559,7 +559,7 @@ def iterrows(df): # pragma: no cover
|
||||
return df.iterrows()
|
||||
|
||||
@register.filter(name='times')
|
||||
def times(number):
|
||||
def times(number): # pragma: no cover
|
||||
return range(number)
|
||||
|
||||
@register.simple_tag
|
||||
@@ -567,7 +567,7 @@ def get_df_iloc(data,i,j): # pragma: no cover
|
||||
return data.iloc(i,j)
|
||||
|
||||
@register.simple_tag
|
||||
def get_field_id(id,s,form):
|
||||
def get_field_id(id,s,form): # pragma: no cover
|
||||
field_name = s+str(id)
|
||||
return form.__getitem__(field_name)
|
||||
|
||||
|
||||
@@ -716,6 +716,10 @@ def mocked_requests(*args, **kwargs):
|
||||
with open('rowers/tests/testdata/c2_timezone.json','r') as infile:
|
||||
c2timezoneworkoutdata = json.load(infile)
|
||||
|
||||
with open('rowers/tests/testdata/c2_timezone2.json','r') as infile:
|
||||
c2timezoneworkoutdata2 = json.load(infile)
|
||||
|
||||
|
||||
with open('rowers/tests/testdata/c2jsonstrokedata.txt','r') as infile:
|
||||
c2strokedata = json.load(infile)
|
||||
|
||||
@@ -1186,6 +1190,8 @@ def mocked_requests(*args, **kwargs):
|
||||
elif c2importtester.match(args[0]):
|
||||
if '12' in args[0]:
|
||||
return MockResponse(c2workoutdata,200)
|
||||
elif '31' in args[0]:
|
||||
return MockResponse(c2timezoneworkoutdata2,200)
|
||||
else:
|
||||
return MockResponse(c2timezoneworkoutdata,200)
|
||||
elif c2workoutlisttester.match(args[0]):
|
||||
|
||||
@@ -276,6 +276,24 @@ class C2Objects(DjangoTestCase):
|
||||
w = Workout.objects.get(id=2)
|
||||
self.assertEqual(w.timezone,'Europe/Prague')
|
||||
|
||||
@patch('rowers.c2stuff.requests.get', side_effect=mocked_requests)
|
||||
@patch('rowers.dataprep.create_engine')
|
||||
def test_c2_import_tz2(self, mock_get, mocked_sqlalchemy):
|
||||
|
||||
response = self.c.get('/rowers/workout/c2import/31/',follow=True)
|
||||
|
||||
self.assertRedirects(response,
|
||||
expected_url='/rowers/workout/'+encoded2+'/edit/',
|
||||
status_code=302,target_status_code=200)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
w = Workout.objects.get(id=2)
|
||||
self.assertEqual(w.timezone,'Europe/Amsterdam')
|
||||
|
||||
self.assertEqual(w.starttime.strftime("%H:%M:%S"),"20:04:56")
|
||||
|
||||
|
||||
|
||||
@patch('rowers.dataprep.create_engine')
|
||||
def test_strokedata(self, mocked_sqlalchemy):
|
||||
|
||||
@@ -699,7 +699,7 @@ def step_to_time_dist(step,avgspeed = 3.2,ftp=200,ftspm=25,ftv=3.7):
|
||||
|
||||
rscore = 100.*(avgpower/ftp)*seconds/3600.
|
||||
|
||||
if targettype == 'Cadence':
|
||||
if targettype == 'Cadence': # pragma: no cover
|
||||
value = step.get('targetValue',0)
|
||||
valuelow = step.get('targetValueLow',0)
|
||||
valuehigh = step.get('targetValueHigh',0)
|
||||
@@ -1166,26 +1166,26 @@ def request_is_ajax(request):
|
||||
return is_ajax
|
||||
|
||||
def intervals_to_string(vals, units, typ):
|
||||
if vals is None or units is None or typ is None:
|
||||
if vals is None or units is None or typ is None: # pragma: no cover
|
||||
return ''
|
||||
if len(vals) != len(units) or len(vals) != len(typ):
|
||||
if len(vals) != len(units) or len(vals) != len(typ): # pragma: no cover
|
||||
return ''
|
||||
|
||||
s = ''
|
||||
previous = 'rest'
|
||||
for i in range(len(vals)):
|
||||
if typ[i] == 'rest' and previous == 'rest':
|
||||
if units[i] == 'min':
|
||||
if units[i] == 'min': # pragma: no cover
|
||||
val = int(vals[i])*60
|
||||
unit = 'sec'
|
||||
else:
|
||||
val = int(vals[i])
|
||||
if units[i] == 'meters':
|
||||
if units[i] == 'meters': # pragma: no cover
|
||||
unit = 'm'
|
||||
if units[i] == 'seconds':
|
||||
unit = 'sec'
|
||||
s += '+0min/{val}{unit}'.format(val=val,unit=unit)
|
||||
elif typ[i] == 'rest':
|
||||
elif typ[i] == 'rest': # pragma: no cover
|
||||
if units[i] == 'min':
|
||||
val = int(vals[i])*60
|
||||
unit = 'sec'
|
||||
@@ -1197,7 +1197,7 @@ def intervals_to_string(vals, units, typ):
|
||||
unit = 'sec'
|
||||
s += '/{val}{unit}'.format(val=val,unit=unit)
|
||||
previous = 'rest'
|
||||
else: # work interval
|
||||
else: # pragma: no cover # work interval
|
||||
if units[i] == 'min':
|
||||
val = int(vals[i])*60
|
||||
unit = 'sec'
|
||||
|
||||
@@ -91,7 +91,7 @@ from django.utils.datastructures import MultiValueDictKeyError
|
||||
from django.utils import timezone,translation
|
||||
from django.core.mail import send_mail, BadHeaderError
|
||||
from rowers.forms import (
|
||||
SummaryStringForm,IntervalUpdateForm,StrokeDataForm,
|
||||
SummaryStringForm,StrokeDataForm,
|
||||
StatsOptionsForm,PredictedPieceForm,DateRangeForm,DeltaDaysForm,
|
||||
FitnessMetricForm,PredictedPieceFormNoDistance,
|
||||
EmailForm, RegistrationForm, RegistrationFormTermsOfService,
|
||||
@@ -1161,7 +1161,7 @@ def get_my_teams(user):
|
||||
return teams
|
||||
|
||||
# Used for the interval editor - translates seconds to a time object
|
||||
def get_time(second):
|
||||
def get_time(second): # pragma: no cover
|
||||
if (second<=0) or (second>1e9):
|
||||
hours = 0
|
||||
minutes=0
|
||||
|
||||
Reference in New Issue
Block a user