Private
Public Access
1
0

testing email workout type

This commit is contained in:
Sander Roosendaal
2018-12-16 11:04:14 +01:00
parent 31c04a1aab
commit 8e14eb0e80
3 changed files with 51 additions and 8 deletions

View File

@@ -422,6 +422,8 @@ def createc2workoutdata(w):
workouttype = w.workouttype workouttype = w.workouttype
if workouttype in otwtypes: if workouttype in otwtypes:
workouttype = 'water' workouttype = 'water'
elif workouttype not in rowtypes:
workouttype = 'other'
try: try:
startdatetime = w.startdatetime.isoformat() startdatetime = w.startdatetime.isoformat()

View File

@@ -1037,6 +1037,49 @@ boattype: 2x
out = StringIO() out = StringIO()
call_command('processemail', stdout=out, testing=True) call_command('processemail', stdout=out, testing=True)
self.assertIn('Successfully processed email attachments',out.getvalue()) self.assertIn('Successfully processed email attachments',out.getvalue())
class UploadTests(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()
)
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 = "3x(5min/2min)/r2 \r2",
body = """
workout run
""")
m.save()
a2 = 'media/mailbox_attachments/colin2.csv'
copyfile('rowers/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:
pass
@patch('requests.get', side_effect=mocked_requests)
def test_email_workouttype(self, mock_get):
out = StringIO()
call_command('processemail', stdout=out, testing=True)
w = Workout.objects.get(id=1)
self.assertEqual(w.workouttype,'Run')
class EmailTests(TestCase): class EmailTests(TestCase):
def setUp(self): def setUp(self):
@@ -1060,7 +1103,6 @@ class EmailTests(TestCase):
subject = filename, subject = filename,
body=""" body="""
--- ---
chart: time
workouttype: water workouttype: water
boattype: 4x boattype: 4x
... ...
@@ -1075,7 +1117,6 @@ boattype: 4x
from_header = u.email, from_header = u.email,
subject = "3x(5min/2min)/r2 \r2", subject = "3x(5min/2min)/r2 \r2",
body = """ body = """
chart time
workout water workout water
""") """)
m.save() m.save()

View File

@@ -127,7 +127,7 @@ def gettypeoptions_body2(uploadoptions,body):
if tester.match(line.lower()): if tester.match(line.lower()):
for typ,verb in workouttypes: for typ,verb in workouttypes:
str1 = '^(workout)(.*)({a})'.format( str1 = '^(workout)(.*)({a})'.format(
a = typ a = typ.lower()
) )
testert = re.compile(str1) testert = re.compile(str1)
if testert.match(line.lower()): if testert.match(line.lower()):
@@ -239,11 +239,11 @@ def getplotoptions(uploadoptions,value):
def gettype(uploadoptions,value,key): def gettype(uploadoptions,value,key):
workouttype = 'rower' workouttype = 'rower'
for type,verb in workouttypes: for typ,verb in workouttypes:
if value == type: if value == typ:
workouttype = type workouttype = typ
if value == verb: if value == verb:
workouttype = type workouttype = typ
uploadoptions[key] = workouttype uploadoptions[key] = workouttype
@@ -314,7 +314,7 @@ def upload_options(body):
uploadoptions = getplotoptions_body2(uploadoptions,body) uploadoptions = getplotoptions_body2(uploadoptions,body)
uploadoptions = getsyncoptions_body2(uploadoptions,body) uploadoptions = getsyncoptions_body2(uploadoptions,body)
uploadoptions = getprivateoptions_body2(uploadoptions,body) uploadoptions = getprivateoptions_body2(uploadoptions,body)
typeoptions = gettypeoptions_body2(uploadoptions,body) uploadoptions = gettypeoptions_body2(uploadoptions,body)
uploadoptions = getstravaid(uploadoptions,body) uploadoptions = getstravaid(uploadoptions,body)
uploadoptions = getworkoutsources(uploadoptions,body) uploadoptions = getworkoutsources(uploadoptions,body)
except IOError: except IOError: