adds testing of email
This commit is contained in:
@@ -17,6 +17,7 @@ import os
|
||||
from rowers.tasks import handle_makeplot
|
||||
from rowers.utils import serialize_list,deserialize_list
|
||||
from rowers.c2stuff import C2NoTokenError
|
||||
from shutil import copyfile
|
||||
|
||||
from minimocktest import MockTestCase
|
||||
import pandas as pd
|
||||
@@ -323,6 +324,40 @@ class NewUserRegistrationTest(TestCase):
|
||||
expected_url='/rowers/register/thankyou/',
|
||||
status_code=302,target_status_code=200)
|
||||
|
||||
from django_mailbox.models import Mailbox,MessageAttachment,Message
|
||||
|
||||
class EmailTests(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)
|
||||
nu = datetime.datetime.now()
|
||||
workoutsbox = Mailbox.objects.create(name='workouts')
|
||||
workoutsbox.save()
|
||||
|
||||
for filename in os.listdir('rowers/testdata/emails'):
|
||||
m = Message(mailbox=workoutsbox,
|
||||
from_header = u.email,
|
||||
subject = filename)
|
||||
m.save()
|
||||
a2 = 'media/mailbox_attachments/'+filename
|
||||
copyfile('rowers/testdata/emails/'+filename,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):
|
||||
os.remove(path)
|
||||
|
||||
def test_emailprocessing(self):
|
||||
out = StringIO()
|
||||
call_command('processemail', stdout=out,testing=True)
|
||||
self.assertIn('Successfully processed email attachments',out.getvalue())
|
||||
|
||||
|
||||
class WorkoutTests(TestCase):
|
||||
def setUp(self):
|
||||
|
||||
Reference in New Issue
Block a user