fixing #490
This commit is contained in:
@@ -30,7 +30,7 @@ cycler==0.10.0
|
|||||||
dask==1.1.4
|
dask==1.1.4
|
||||||
decorator==4.4.0
|
decorator==4.4.0
|
||||||
defusedxml==0.5.0
|
defusedxml==0.5.0
|
||||||
Django==2.1.7
|
Django==2.2.1
|
||||||
django-analytical==2.5.0
|
django-analytical==2.5.0
|
||||||
django-async-messages==0.3.1
|
django-async-messages==0.3.1
|
||||||
django-braces==1.13.0
|
django-braces==1.13.0
|
||||||
@@ -157,7 +157,7 @@ ratelim==0.1.6
|
|||||||
redis==3.2.1
|
redis==3.2.1
|
||||||
requests==2.21.0
|
requests==2.21.0
|
||||||
requests-oauthlib==1.2.0
|
requests-oauthlib==1.2.0
|
||||||
rowingdata==2.3.9
|
rowingdata==2.4.4
|
||||||
rowingphysics==0.5.0
|
rowingphysics==0.5.0
|
||||||
rq==1.0
|
rq==1.0
|
||||||
rq-dashboard==0.4.0
|
rq-dashboard==0.4.0
|
||||||
@@ -190,6 +190,7 @@ wcwidth==0.1.7
|
|||||||
webencodings==0.5.1
|
webencodings==0.5.1
|
||||||
Werkzeug==0.15.2
|
Werkzeug==0.15.2
|
||||||
widgetsnbextension==3.4.2
|
widgetsnbextension==3.4.2
|
||||||
|
xlrd==1.2.0
|
||||||
xmltodict==0.12.0
|
xmltodict==0.12.0
|
||||||
yamjam==0.1.7
|
yamjam==0.1.7
|
||||||
yamllint==1.15.0
|
yamllint==1.15.0
|
||||||
|
|||||||
@@ -5,37 +5,42 @@ from __future__ import unicode_literals
|
|||||||
from six import iteritems
|
from six import iteritems
|
||||||
import collections
|
import collections
|
||||||
|
|
||||||
workouttypes = (
|
workouttypes_ordered = collections.OrderedDict({
|
||||||
('water','Standard Racing Shell'),
|
'water':'Standard Racing Shell',
|
||||||
('rower','Indoor Rower'),
|
'rower':'Indoor Rower',
|
||||||
('skierg','Ski Erg'),
|
'skierg':'Ski Erg',
|
||||||
('bike','Bike Erg'),
|
'bikeerg':'Bike Erg',
|
||||||
('dynamic','Dynamic Indoor Rower'),
|
'dynamic':'Dynamic Indoor Rower',
|
||||||
('slides','Indoor Rower on Slides'),
|
'slides':'Indoor Rower on Slides',
|
||||||
('paddle','Paddle Adapter'),
|
'paddle':'Paddle Adapter',
|
||||||
('snow','On-snow'),
|
'snow':'On-snow',
|
||||||
('coastal','Coastal'),
|
'coastal':'Coastal',
|
||||||
('c-boat','Dutch C boat'),
|
'c-boat':'Dutch C boat',
|
||||||
('churchboat','Finnish Church boat'),
|
'churchboat':'Finnish Church boat',
|
||||||
('Ride','Ride'),
|
'Ride':'Ride',
|
||||||
('Bike','Bike'),
|
'Bike':'Bike',
|
||||||
('Run','Run'),
|
'Run':'Run',
|
||||||
('NordicSki','NordicSki'),
|
'NordicSki':'NordicSki',
|
||||||
('Swim','Swim'),
|
'Swim':'Swim',
|
||||||
('Hike','Hike'),
|
'Hike':'Hike',
|
||||||
('Walk','Walk'),
|
'Walk':'Walk',
|
||||||
('Canoeing','Canoeing'),
|
'Canoeing':'Canoeing',
|
||||||
('Crossfit','Crossfit'),
|
'Crossfit':'Crossfit',
|
||||||
('StandUpPaddling','StandUpPaddling'),
|
'StandUpPaddling':'StandUpPaddling',
|
||||||
('IceSkate','IceSkate'),
|
'IceSkate':'IceSkate',
|
||||||
('WeightTraining','WeightTraining'),
|
'WeightTraining':'WeightTraining',
|
||||||
('InlineSkate','InlineSkate'),
|
'InlineSkate':'InlineSkate',
|
||||||
('Kayaking','Kayaking'),
|
'Kayaking':'Kayaking',
|
||||||
('Workout','Workout'),
|
'Workout':'Workout',
|
||||||
('Yoga','Yoga'),
|
'Yoga':'Yoga',
|
||||||
('other','Other'),
|
'other':'Other',
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
workouttypes = tuple((key, value) for key, value in workouttypes_ordered.items())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
stravamapping = collections.OrderedDict({
|
stravamapping = collections.OrderedDict({
|
||||||
'water':'Rowing',
|
'water':'Rowing',
|
||||||
'rower':'Rowing',
|
'rower':'Rowing',
|
||||||
|
|||||||
@@ -67,6 +67,68 @@ workout run
|
|||||||
self.assertEqual(w.workouttype,'Run')
|
self.assertEqual(w.workouttype,'Run')
|
||||||
|
|
||||||
|
|
||||||
|
@override_settings(TESTING=True)
|
||||||
|
class EmailBikeErgUpload(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
redis_connection.publish('tasks','KILL')
|
||||||
|
u = User.objects.create_user('john',
|
||||||
|
'sander@ds.ds',
|
||||||
|
'koeinsloot')
|
||||||
|
r = Rower.objects.create(user=u,gdproptin=True,
|
||||||
|
gdproptindate=timezone.now()
|
||||||
|
)
|
||||||
|
|
||||||
|
self.theadmin = UserFactory(is_staff=True)
|
||||||
|
self.rtheadmin = Rower.objects.create(user=self.theadmin,
|
||||||
|
birthdate = faker.profile()['birthdate'],
|
||||||
|
gdproptin=True,
|
||||||
|
gdproptindate=timezone.now(),
|
||||||
|
rowerplan='coach')
|
||||||
|
|
||||||
|
nu = datetime.datetime.now()
|
||||||
|
workoutsbox = Mailbox.objects.create(name='workouts')
|
||||||
|
workoutsbox.save()
|
||||||
|
failbox = Mailbox.objects.create(name='Failed')
|
||||||
|
failbox.save()
|
||||||
|
|
||||||
|
m = Message(mailbox=workoutsbox,
|
||||||
|
from_header = u.email,
|
||||||
|
subject = "bikeerg",
|
||||||
|
body = """
|
||||||
|
workout bikeerg
|
||||||
|
""")
|
||||||
|
m.save()
|
||||||
|
a2 = 'media/mailbox_attachments/colin3.csv'
|
||||||
|
copy('rowers/tests/testdata/emails/colin.csv',a2)
|
||||||
|
a = MessageAttachment(message=m,document=a2[6:])
|
||||||
|
a.save()
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
for filename in os.listdir('media/mailbox_attachments'):
|
||||||
|
path = os.path.join('media/mailbox_attachments/',filename)
|
||||||
|
if not os.path.isdir(path):
|
||||||
|
try:
|
||||||
|
os.remove(path)
|
||||||
|
except (IOError,FileNotFoundError,OSError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@patch('rowers.dataprep.create_engine')
|
||||||
|
@patch('rowers.polarstuff.get_polar_notifications')
|
||||||
|
@patch('rowers.c2stuff.requests.get', side_effect=mocked_requests)
|
||||||
|
@patch('rowers.c2stuff.requests.post', side_effect=mocked_requests)
|
||||||
|
def test_emailupload(
|
||||||
|
self, mocked_sqlalchemy,mocked_polar_notifications, mock_get, mock_post):
|
||||||
|
out = StringIO()
|
||||||
|
call_command('processemail', stdout=out,testing=True)
|
||||||
|
self.assertIn('Successfully processed email attachments',out.getvalue())
|
||||||
|
|
||||||
|
ws = Workout.objects.filter(name="bikeerg")
|
||||||
|
|
||||||
|
self.assertEqual(len(ws),1)
|
||||||
|
w = ws[0]
|
||||||
|
self.assertEqual(w.workouttype,'bikeerg')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#@pytest.mark.django_db
|
#@pytest.mark.django_db
|
||||||
@override_settings(TESTING=True)
|
@override_settings(TESTING=True)
|
||||||
|
|||||||
BIN
rowers/tests/testdata/testdata.csv.gz
vendored
BIN
rowers/tests/testdata/testdata.csv.gz
vendored
Binary file not shown.
@@ -30,7 +30,7 @@ queue = django_rq.get_queue('default')
|
|||||||
queuelow = django_rq.get_queue('low')
|
queuelow = django_rq.get_queue('low')
|
||||||
queuehigh = django_rq.get_queue('high')
|
queuehigh = django_rq.get_queue('high')
|
||||||
|
|
||||||
from rowers.mytypes import workouttypes,boattypes,otwtypes,workoutsources
|
from rowers.mytypes import workouttypes,boattypes,otwtypes,workoutsources, workouttypes_ordered
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
@@ -156,13 +156,14 @@ def gettypeoptions_body2(uploadoptions,body):
|
|||||||
testerb = re.compile('^(boat)')
|
testerb = re.compile('^(boat)')
|
||||||
for line in body.splitlines():
|
for line in body.splitlines():
|
||||||
if tester.match(line.lower()):
|
if tester.match(line.lower()):
|
||||||
for typ,verb in workouttypes:
|
for typ,verb in workouttypes_ordered.items():
|
||||||
str1 = '^(workout)(.*)({a})'.format(
|
str1 = '^(workout)(.*)({a})'.format(
|
||||||
a = typ.lower()
|
a = typ.lower()
|
||||||
)
|
)
|
||||||
testert = re.compile(str1)
|
testert = re.compile(str1)
|
||||||
if testert.match(line.lower()):
|
if testert.match(line.lower()):
|
||||||
uploadoptions['workouttype'] = typ
|
uploadoptions['workouttype'] = typ
|
||||||
|
break
|
||||||
if testerb.match(line.lower()):
|
if testerb.match(line.lower()):
|
||||||
for typ,verb in boattypes:
|
for typ,verb in boattypes:
|
||||||
str1 = '^(boat)(.*)({a})'.format(
|
str1 = '^(boat)(.*)({a})'.format(
|
||||||
@@ -170,7 +171,8 @@ def gettypeoptions_body2(uploadoptions,body):
|
|||||||
)
|
)
|
||||||
testert = re.compile(str1)
|
testert = re.compile(str1)
|
||||||
if testert.match(line.lower()):
|
if testert.match(line.lower()):
|
||||||
uploadoptions['boattype'] = typ
|
uploadoptions['boattype'] = typ
|
||||||
|
break
|
||||||
|
|
||||||
return uploadoptions
|
return uploadoptions
|
||||||
|
|
||||||
@@ -286,11 +288,13 @@ def getplotoptions(uploadoptions,value):
|
|||||||
|
|
||||||
def gettype(uploadoptions,value,key):
|
def gettype(uploadoptions,value,key):
|
||||||
workouttype = 'rower'
|
workouttype = 'rower'
|
||||||
for typ,verb in workouttypes:
|
for typ,verb in workouttypes_ordered.items():
|
||||||
if value == typ:
|
if value == typ:
|
||||||
workouttype = typ
|
workouttype = typ
|
||||||
|
break
|
||||||
if value == verb:
|
if value == verb:
|
||||||
workouttype = typ
|
workouttype = typ
|
||||||
|
break
|
||||||
|
|
||||||
uploadoptions[key] = workouttype
|
uploadoptions[key] = workouttype
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ def analysis_new(request,userid=0,function='boxplot',teamid=0):
|
|||||||
modalities = options['modalities']
|
modalities = options['modalities']
|
||||||
modality = modalities[0]
|
modality = modalities[0]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
modalities = [m[0] for m in mytypes.workouttypes]
|
modalities = [m[0] for m in mytypes.workouttypes_ordered.items()]
|
||||||
modality = 'all'
|
modality = 'all'
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user