testing email workout type
This commit is contained in:
@@ -422,6 +422,8 @@ def createc2workoutdata(w):
|
||||
workouttype = w.workouttype
|
||||
if workouttype in otwtypes:
|
||||
workouttype = 'water'
|
||||
elif workouttype not in rowtypes:
|
||||
workouttype = 'other'
|
||||
|
||||
try:
|
||||
startdatetime = w.startdatetime.isoformat()
|
||||
|
||||
@@ -1037,6 +1037,49 @@ boattype: 2x
|
||||
out = StringIO()
|
||||
call_command('processemail', stdout=out, testing=True)
|
||||
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):
|
||||
def setUp(self):
|
||||
@@ -1060,7 +1103,6 @@ class EmailTests(TestCase):
|
||||
subject = filename,
|
||||
body="""
|
||||
---
|
||||
chart: time
|
||||
workouttype: water
|
||||
boattype: 4x
|
||||
...
|
||||
@@ -1075,7 +1117,6 @@ boattype: 4x
|
||||
from_header = u.email,
|
||||
subject = "3x(5min/2min)/r2 \r2",
|
||||
body = """
|
||||
chart time
|
||||
workout water
|
||||
""")
|
||||
m.save()
|
||||
|
||||
@@ -127,7 +127,7 @@ def gettypeoptions_body2(uploadoptions,body):
|
||||
if tester.match(line.lower()):
|
||||
for typ,verb in workouttypes:
|
||||
str1 = '^(workout)(.*)({a})'.format(
|
||||
a = typ
|
||||
a = typ.lower()
|
||||
)
|
||||
testert = re.compile(str1)
|
||||
if testert.match(line.lower()):
|
||||
@@ -239,11 +239,11 @@ def getplotoptions(uploadoptions,value):
|
||||
|
||||
def gettype(uploadoptions,value,key):
|
||||
workouttype = 'rower'
|
||||
for type,verb in workouttypes:
|
||||
if value == type:
|
||||
workouttype = type
|
||||
for typ,verb in workouttypes:
|
||||
if value == typ:
|
||||
workouttype = typ
|
||||
if value == verb:
|
||||
workouttype = type
|
||||
workouttype = typ
|
||||
|
||||
uploadoptions[key] = workouttype
|
||||
|
||||
@@ -314,7 +314,7 @@ def upload_options(body):
|
||||
uploadoptions = getplotoptions_body2(uploadoptions,body)
|
||||
uploadoptions = getsyncoptions_body2(uploadoptions,body)
|
||||
uploadoptions = getprivateoptions_body2(uploadoptions,body)
|
||||
typeoptions = gettypeoptions_body2(uploadoptions,body)
|
||||
uploadoptions = gettypeoptions_body2(uploadoptions,body)
|
||||
uploadoptions = getstravaid(uploadoptions,body)
|
||||
uploadoptions = getworkoutsources(uploadoptions,body)
|
||||
except IOError:
|
||||
|
||||
Reference in New Issue
Block a user