本文整理匯總了Python中django.core.mail.outbox方法的典型用法代碼示例。如果您正苦於以下問題:Python mail.outbox方法的具體用法?Python mail.outbox怎麽用?Python mail.outbox使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.core.mail
的用法示例。
在下文中一共展示了mail.outbox方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_admin_add_user_auto_email
# 需要導入模塊: from django.core import mail [as 別名]
# 或者: from django.core.mail import outbox [as 別名]
def test_admin_add_user_auto_email(self):
admin = self._create_admin()
self.client.force_login(admin)
params = dict(
username='testadd',
email='test@testadd.com',
password1='tester',
password2='tester',
)
params.update(self.add_user_inline_params)
params.update(self._additional_params_add())
self.client.post(reverse(f'admin:{self.app_label}_user_add'), params)
queryset = User.objects.filter(username='testadd')
self.assertEqual(queryset.count(), 1)
user = queryset.first()
self.assertEqual(user.emailaddress_set.count(), 1)
emailaddress = user.emailaddress_set.first()
self.assertEqual(emailaddress.email, 'test@testadd.com')
self.assertEqual(len(mail.outbox), 1)
示例2: test_email_weekly_command_digest_day
# 需要導入模塊: from django.core import mail [as 別名]
# 或者: from django.core.mail import outbox [as 別名]
def test_email_weekly_command_digest_day(self):
"""Test that admin can send digest on the weekly digest day."""
setattr(settings, 'DIGEST_WEEKLY_DAY', 0)
previous = timezone.now()
static = previous
# find the next scheduled digest day
while static.weekday() != 0:
static += timezone.timedelta(days=1)
with patch('openach.management.commands.senddigest.timezone.now') as timezone_mock:
timezone_mock.return_value = static
logger.debug('Shifted timezone.now() from weekday %s to %s', previous.weekday(), static.weekday())
create_board(board_title='New Board', days=-1)
call_command('senddigest', 'weekly')
self.assertEqual(len(mail.outbox), 1, 'No weekly digest email sent')
示例3: test_email_weekly_command_other_day
# 需要導入模塊: from django.core import mail [as 別名]
# 或者: from django.core.mail import outbox [as 別名]
def test_email_weekly_command_other_day(self):
"""Test that admin cannot digest email not on weekly digest day unless forced."""
setattr(settings, 'DIGEST_WEEKLY_DAY', 0)
previous = timezone.now()
static = previous
# make sure we're not on a scheduled digest day
while static.weekday() == 0:
static += timezone.timedelta(days=1)
with patch('openach.management.commands.senddigest.timezone.now') as timezone_mock:
timezone_mock.return_value = static
logger.debug('Shifted timezone.now() from weekday %s to %s', previous.weekday(), static.weekday())
create_board(board_title='New Board', days=-1)
call_command('senddigest', 'weekly')
self.assertEqual(len(mail.outbox), 0, 'Weekly digest email sent on wrong day')
call_command('senddigest', 'weekly', '--force')
self.assertEqual(len(mail.outbox), 1, 'Weekly digest email not sent when forced')
示例4: _pre_setup
# 需要導入模塊: from django.core import mail [as 別名]
# 或者: from django.core.mail import outbox [as 別名]
def _pre_setup(self):
"""Disable transaction methods, and clear some globals."""
# Repeat stuff from TransactionTestCase, because I'm not calling its
# _pre_setup, because that would load fixtures again.
cache.cache.clear()
settings.TEMPLATE_DEBUG = settings.DEBUG = False
self.client = self.client_class()
#self._fixture_setup()
self._urlconf_setup()
mail.outbox = []
# Clear site cache in case somebody's mutated Site objects and then
# cached the mutated stuff:
from django.contrib.sites.models import Site
Site.objects.clear_cache()
示例5: setup_test_environment
# 需要導入模塊: from django.core import mail [as 別名]
# 或者: from django.core.mail import outbox [as 別名]
def setup_test_environment():
"""Perform any global pre-test setup. This involves:
- Installing the instrumented test renderer
- Set the email backend to the locmem email backend.
- Setting the active locale to match the LANGUAGE_CODE setting.
"""
Template._original_render = Template._render
Template._render = instrumented_test_render
# Storing previous values in the settings module itself is problematic.
# Store them in arbitrary (but related) modules instead. See #20636.
mail._original_email_backend = settings.EMAIL_BACKEND
settings.EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend'
request._original_allowed_hosts = settings.ALLOWED_HOSTS
settings.ALLOWED_HOSTS = ['*']
mail.outbox = []
deactivate()
示例6: assertEmailSent
# 需要導入模塊: from django.core import mail [as 別名]
# 或者: from django.core.mail import outbox [as 別名]
def assertEmailSent(self, subject_contains='', body_contains='', recipient=None, reset=True, pattern=None):
total = 1
self.assertEqual(len(mail.outbox), total, "Expected %i message in the outbox, but found %i." %
(total, len(mail.outbox)))
email = mail.outbox[-1]
self.assertTrue(subject_contains in email.subject,
"Expected '%s' in the email subject, but found '%s'" %
(subject_contains, email.subject))
self.assertTrue(body_contains in email.body,
"Expected '%s' in the email body, but found '%s'" %
(body_contains, email.body))
if recipient is not None:
if isinstance(recipient, list):
self.assertListEqual(recipient, email.recipients())
else:
self.assertIn(recipient, email.recipients())
body = email.body
self.assertIn('user_id = ', body)
if reset:
mail.outbox = []
return body if not pattern else re.search(pattern, body).group(1)
示例7: test_create_donation
# 需要導入模塊: from django.core import mail [as 別名]
# 或者: from django.core.mail import outbox [as 別名]
def test_create_donation(self):
url = reverse('v1:donation')
data = {
'name': 'Komplizierter Vörnämü-ßßß 馬大為',
'iban': 'DE89370400440532013000',
'bic': 'BYLADEM1SWU',
'amount': 123.45,
'message': 'hi there, thank you. Also, some random chars: ™ • ½ ¼ ¾ ⅓ ⅔ † ‡ µ ¢ £ € « » ♤ ♧ ♥ ♢ ¿ ',
'email': 'email@example.com',
}
response = self.client.post(url, data)
self.assertTrue(mail.outbox)
email_internal = str(mail.outbox[0].message())
direct_debit = str(mail.outbox[0].attachments[0][1])
self.assertStatus(response, status.HTTP_201_CREATED)
self.assertEqual(len(mail.outbox), 2)
self.assertEqual(response.data['iban'], data['iban'])
self.assertTrue('Komplizierter Vornamu' in direct_debit)
self.assertTrue(data['iban'] in email_internal)
示例8: test_create_domains
# 需要導入模塊: from django.core import mail [as 別名]
# 或者: from django.core.mail import outbox [as 別名]
def test_create_domains(self):
self.owner.limit_domains = 100
self.owner.save()
for name in [
'0.8.0.0.0.1.c.a.2.4.6.0.c.e.e.d.4.4.0.1.a.0.1.0.8.f.4.0.1.0.a.2.ip6.arpa',
'very.long.domain.name.' + self.random_domain_name(),
self.random_domain_name(),
]:
with self.assertPdnsRequests(self.requests_desec_domain_creation(name)):
response = self.client.post(self.reverse('v1:domain-list'), {'name': name})
self.assertStatus(response, status.HTTP_201_CREATED)
self.assertTrue(all(field in response.data for field in
['created', 'published', 'name', 'keys', 'minimum_ttl', 'touched']))
self.assertEqual(len(mail.outbox), 0)
self.assertTrue(isinstance(response.data['keys'], list))
with self.assertPdnsRequests(self.request_pdns_zone_retrieve_crypto_keys(name)):
self.assertStatus(
self.client.get(self.reverse('v1:domain-detail', name=name), {'name': name}),
status.HTTP_200_OK
)
response = self.client.get_rr_sets(name, type='NS', subname='')
self.assertStatus(response, status.HTTP_200_OK)
self.assertContainsRRSets(response.data, [dict(subname='', records=settings.DEFAULT_NS, type='NS')])
示例9: test_create_domain_name_validation
# 需要導入模塊: from django.core import mail [as 別名]
# 或者: from django.core.mail import outbox [as 別名]
def test_create_domain_name_validation(self):
for name in [
'with space.dedyn.io',
'another space.de',
' spaceatthebeginning.com',
'percentage%sign.com',
'%percentagesign.dedyn.io',
'slash/desec.io',
'/slashatthebeginning.dedyn.io',
'\\backslashatthebeginning.dedyn.io',
'backslash\\inthemiddle.at',
'@atsign.com',
'at@sign.com',
'UPPER.case',
'case.UPPER',
]:
response = self.client.post(self.reverse('v1:domain-list'), {'name': name})
self.assertStatus(response, status.HTTP_400_BAD_REQUEST)
self.assertEqual(len(mail.outbox), 0)
示例10: test_registration
# 需要導入模塊: from django.core import mail [as 別名]
# 或者: from django.core.mail import outbox [as 別名]
def test_registration(self):
"""
Test the registration process: registration creates a new
inactive account and a new profile with activation key,
populates the correct account data and sends an activation
email.
"""
new_user = self.backend.register(_mock_request(),
username='bob',
email='bob@example.com',
password1='secret')
# Details of the returned user must match what went in.
self.assertEqual(new_user.username, 'bob')
self.failUnless(new_user.check_password('secret'))
self.assertEqual(new_user.email, 'bob@example.com')
# New user must not be active.
self.failIf(new_user.is_active)
# A registration profile was created, and an activation email
# was sent.
self.assertEqual(RegistrationProfile.objects.count(), 1)
self.assertEqual(len(mail.outbox), 1)
示例11: test_registration_no_sites
# 需要導入模塊: from django.core import mail [as 別名]
# 或者: from django.core.mail import outbox [as 別名]
def test_registration_no_sites(self):
"""
Test that registration still functions properly when
``django.contrib.sites`` is not installed; the fallback will
be a ``RequestSite`` instance.
"""
Site._meta.installed = False
new_user = self.backend.register(_mock_request(),
username='bob',
email='bob@example.com',
password1='secret')
self.assertEqual(new_user.username, 'bob')
self.failUnless(new_user.check_password('secret'))
self.assertEqual(new_user.email, 'bob@example.com')
self.failIf(new_user.is_active)
self.assertEqual(RegistrationProfile.objects.count(), 1)
self.assertEqual(len(mail.outbox), 1)
Site.meta.installed = True
示例12: test_email_send_action
# 需要導入模塊: from django.core import mail [as 別名]
# 或者: from django.core.mail import outbox [as 別名]
def test_email_send_action(self):
"""
Test re-sending of activation emails via admin action.
"""
admin_class = RegistrationAdmin(RegistrationProfile, admin.site)
alice = self.backend.register(_mock_request(),
username='alice',
email='alice@example.com',
password1='swordfish')
admin_class.resend_activation_email(_mock_request(),
RegistrationProfile.objects.all())
self.assertEqual(len(mail.outbox), 2) # One on registering, one more on the resend.
RegistrationProfile.objects.filter(user=alice).update(activation_key=RegistrationProfile.ACTIVATED)
admin_class.resend_activation_email(_mock_request(),
RegistrationProfile.objects.all())
self.assertEqual(len(mail.outbox), 2) # No additional email because the account has activated.
示例13: test_email_send_action_no_sites
# 需要導入模塊: from django.core import mail [as 別名]
# 或者: from django.core.mail import outbox [as 別名]
def test_email_send_action_no_sites(self):
"""
Test re-sending of activation emails via admin action when
``django.contrib.sites`` is not installed; the fallback will
be a ``RequestSite`` instance.
"""
Site._meta.installed = False
admin_class = RegistrationAdmin(RegistrationProfile, admin.site)
alice = self.backend.register(_mock_request(),
username='alice',
email='alice@example.com',
password1='swordfish')
admin_class.resend_activation_email(_mock_request(),
RegistrationProfile.objects.all())
self.assertEqual(len(mail.outbox), 2) # One on registering, one more on the resend.
RegistrationProfile.objects.filter(user=alice).update(activation_key=RegistrationProfile.ACTIVATED)
admin_class.resend_activation_email(_mock_request(),
RegistrationProfile.objects.all())
self.assertEqual(len(mail.outbox), 2) # No additional email because the account has activated.
Site._meta.installed = True
示例14: test_registration_view_failure
# 需要導入模塊: from django.core import mail [as 別名]
# 或者: from django.core.mail import outbox [as 別名]
def test_registration_view_failure(self):
"""
A ``POST`` to the ``register`` view with invalid data does not
create a user, and displays appropriate error messages.
"""
# with translation.override('en'):
response = self.client.post(reverse('registration_register'),
data={'username': 'bob',
'email': 'bobe@example.com',
'password1': 'foo',
'password2': 'bar'})
self.assertEqual(response.status_code, 200)
self.failIf(response.context['form'].is_valid())
self.assertFormError(response, 'form', field=None,
errors=u"Два поля с паролями не совпадают.")
self.assertEqual(len(mail.outbox), 0)
示例15: test_newcomer_becomes_editor
# 需要導入模塊: from django.core import mail [as 別名]
# 或者: from django.core.mail import outbox [as 別名]
def test_newcomer_becomes_editor(self):
editor = UserFactory()
newcomer = UserFactory()
group = GroupFactory(members=[editor], newcomers=[newcomer])
two_days_ago = timezone.now() - relativedelta(days=2)
GroupMembership.objects.filter(group=group).update(created_at=two_days_ago)
mail.outbox = []
membership = GroupMembership.objects.get(user=newcomer, group=group)
Trust.objects.create(membership=membership, given_by=editor)
self.assertTrue(group.is_editor(newcomer))
self.assertEqual(len(mail.outbox), 1)
self.assertIn('You gained editing permissions', mail.outbox[0].subject)
self.assertEqual(History.objects.filter(typus=HistoryTypus.MEMBER_BECAME_EDITOR).count(), 1)