Private
Public Access
1
0
This commit is contained in:
Sander Roosendaal
2019-07-12 10:34:51 +02:00
parent 84a08bcd7f
commit 98428e736e
6 changed files with 108 additions and 36 deletions

View File

@@ -5,37 +5,42 @@ from __future__ import unicode_literals
from six import iteritems
import collections
workouttypes = (
('water','Standard Racing Shell'),
('rower','Indoor Rower'),
('skierg','Ski Erg'),
('bike','Bike Erg'),
('dynamic','Dynamic Indoor Rower'),
('slides','Indoor Rower on Slides'),
('paddle','Paddle Adapter'),
('snow','On-snow'),
('coastal','Coastal'),
('c-boat','Dutch C boat'),
('churchboat','Finnish Church boat'),
('Ride','Ride'),
('Bike','Bike'),
('Run','Run'),
('NordicSki','NordicSki'),
('Swim','Swim'),
('Hike','Hike'),
('Walk','Walk'),
('Canoeing','Canoeing'),
('Crossfit','Crossfit'),
('StandUpPaddling','StandUpPaddling'),
('IceSkate','IceSkate'),
('WeightTraining','WeightTraining'),
('InlineSkate','InlineSkate'),
('Kayaking','Kayaking'),
('Workout','Workout'),
('Yoga','Yoga'),
('other','Other'),
workouttypes_ordered = collections.OrderedDict({
'water':'Standard Racing Shell',
'rower':'Indoor Rower',
'skierg':'Ski Erg',
'bikeerg':'Bike Erg',
'dynamic':'Dynamic Indoor Rower',
'slides':'Indoor Rower on Slides',
'paddle':'Paddle Adapter',
'snow':'On-snow',
'coastal':'Coastal',
'c-boat':'Dutch C boat',
'churchboat':'Finnish Church boat',
'Ride':'Ride',
'Bike':'Bike',
'Run':'Run',
'NordicSki':'NordicSki',
'Swim':'Swim',
'Hike':'Hike',
'Walk':'Walk',
'Canoeing':'Canoeing',
'Crossfit':'Crossfit',
'StandUpPaddling':'StandUpPaddling',
'IceSkate':'IceSkate',
'WeightTraining':'WeightTraining',
'InlineSkate':'InlineSkate',
'Kayaking':'Kayaking',
'Workout':'Workout',
'Yoga':'Yoga',
'other':'Other',
}
)
workouttypes = tuple((key, value) for key, value in workouttypes_ordered.items())
stravamapping = collections.OrderedDict({
'water':'Rowing',
'rower':'Rowing',

View File

@@ -67,6 +67,68 @@ workout 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
@override_settings(TESTING=True)

Binary file not shown.

View File

@@ -30,7 +30,7 @@ queue = django_rq.get_queue('default')
queuelow = django_rq.get_queue('low')
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:
from cStringIO import StringIO
@@ -156,13 +156,14 @@ def gettypeoptions_body2(uploadoptions,body):
testerb = re.compile('^(boat)')
for line in body.splitlines():
if tester.match(line.lower()):
for typ,verb in workouttypes:
for typ,verb in workouttypes_ordered.items():
str1 = '^(workout)(.*)({a})'.format(
a = typ.lower()
)
testert = re.compile(str1)
if testert.match(line.lower()):
uploadoptions['workouttype'] = typ
break
if testerb.match(line.lower()):
for typ,verb in boattypes:
str1 = '^(boat)(.*)({a})'.format(
@@ -170,7 +171,8 @@ def gettypeoptions_body2(uploadoptions,body):
)
testert = re.compile(str1)
if testert.match(line.lower()):
uploadoptions['boattype'] = typ
uploadoptions['boattype'] = typ
break
return uploadoptions
@@ -286,11 +288,13 @@ def getplotoptions(uploadoptions,value):
def gettype(uploadoptions,value,key):
workouttype = 'rower'
for typ,verb in workouttypes:
for typ,verb in workouttypes_ordered.items():
if value == typ:
workouttype = typ
break
if value == verb:
workouttype = typ
break
uploadoptions[key] = workouttype

View File

@@ -59,7 +59,7 @@ def analysis_new(request,userid=0,function='boxplot',teamid=0):
modalities = options['modalities']
modality = modalities[0]
except KeyError:
modalities = [m[0] for m in mytypes.workouttypes]
modalities = [m[0] for m in mytypes.workouttypes_ordered.items()]
modality = 'all'