1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-16 15:19:06 +00:00

Improve share-link tests

Tests for correct from header and support testing Reply-To header and rewrite of From.
Support testing shared_link email, too.
This commit is contained in:
Enno Gröper
2016-03-31 08:52:01 +00:00
parent 1ddd527eda
commit b64e882a54
2 changed files with 72 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
from mock import patch
from django.core import mail
from django.core.urlresolvers import reverse
from django.test import override_settings
from seahub.test_utils import BaseTestCase
class SendSharedLinkTest(BaseTestCase):
def setUp(self):
mail.outbox = []
@override_settings(DEFAULT_FROM_EMAIL='from_noreply@seafile.com')
@patch('seahub.share.views.IS_EMAIL_CONFIGURED', True)
def test_can_send(self):
self.login_as(self.user)
resp = self.client.post(reverse('send_shared_link'), {
'email': self.user.email,
'file_shared_link': 'http://xxx',
'file_shared_name': 'xxx',
'file_shared_type': 'd',
'extra_msg': ''
}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
self.assertEqual(200, resp.status_code)
self.assertEqual(len(mail.outbox), 1)
assert '<a href="http://xxx">http://xxx</a>' in mail.outbox[0].body
assert mail.outbox[0].from_email == 'from_noreply@seafile.com'
@patch('seahub.share.views.REPLACE_FROM_EMAIL', True)
@patch('seahub.share.views.ADD_REPLY_TO_HEADER', True)
@patch('seahub.share.views.IS_EMAIL_CONFIGURED', True)
@patch('seahub.utils.IS_EMAIL_CONFIGURED', True)
def test_can_send_from_replyto_rewrite(self):
self.login_as(self.user)
resp = self.client.post(reverse('send_shared_link'), {
'email': self.user.email,
'file_shared_link': 'http://xxx',
'file_shared_name': 'xxx',
'file_shared_type': 'd',
'extra_msg': ''
}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
self.assertEqual(200, resp.status_code)
self.assertEqual(len(mail.outbox), 1)
assert '<a href="http://xxx">http://xxx</a>' in mail.outbox[0].body
assert mail.outbox[0].from_email == self.user.email
assert mail.outbox[0].extra_headers['Reply-to'] == self.user.email

View File

@@ -1,6 +1,7 @@
from mock import patch
from django.core import mail
from django.core.urlresolvers import reverse
from django.test import override_settings
from seahub.test_utils import BaseTestCase
@@ -9,6 +10,7 @@ class SendSharedUploadLinkTest(BaseTestCase):
def setUp(self):
mail.outbox = []
@override_settings(DEFAULT_FROM_EMAIL='from_noreply@seafile.com')
@patch('seahub.share.views.IS_EMAIL_CONFIGURED', True)
def test_can_send(self):
self.login_as(self.user)
@@ -22,3 +24,23 @@ class SendSharedUploadLinkTest(BaseTestCase):
self.assertEqual(200, resp.status_code)
self.assertEqual(len(mail.outbox), 1)
assert '<a href="http://xxx">http://xxx</a>' in mail.outbox[0].body
assert mail.outbox[0].from_email == 'from_noreply@seafile.com'
@patch('seahub.share.views.REPLACE_FROM_EMAIL', True)
@patch('seahub.share.views.ADD_REPLY_TO_HEADER', True)
@patch('seahub.share.views.IS_EMAIL_CONFIGURED', True)
@patch('seahub.utils.IS_EMAIL_CONFIGURED', True)
def test_can_send_from_replyto_rewrite(self):
self.login_as(self.user)
resp = self.client.post(reverse('send_shared_upload_link'), {
'email': self.user.email,
'shared_upload_link': 'http://xxx',
'extra_msg': ''
}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
self.assertEqual(200, resp.status_code)
self.assertEqual(len(mail.outbox), 1)
assert '<a href="http://xxx">http://xxx</a>' in mail.outbox[0].body
assert mail.outbox[0].from_email == self.user.email
assert mail.outbox[0].extra_headers['Reply-to'] == self.user.email