本文整理汇总了Python中patchwork.models.EmailConfirmation类的典型用法代码示例。如果您正苦于以下问题:Python EmailConfirmation类的具体用法?Python EmailConfirmation怎么用?Python EmailConfirmation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EmailConfirmation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: OptoutTest
class OptoutTest(TestCase):
view = 'patchwork.views.mail.optout'
url = reverse(view)
def setUp(self):
self.email = u'[email protected]'
self.conf = EmailConfirmation(type = 'optout', email = self.email)
self.conf.save()
def testOptoutValidHash(self):
url = reverse('patchwork.views.confirm',
kwargs = {'key': self.conf.key})
response = self.client.get(url)
self.assertEquals(response.status_code, 200)
self.assertTemplateUsed(response, 'patchwork/optout.html')
self.assertTrue(self.email in response.content)
# check that we've got an optout in the list
self.assertEquals(EmailOptout.objects.count(), 1)
self.assertEquals(EmailOptout.objects.all()[0].email, self.email)
# check that the confirmation is now inactive
self.assertFalse(EmailConfirmation.objects.get(
pk = self.conf.pk).active)
示例2: link
def link(request):
context = {}
if request.method == 'POST':
form = EmailForm(request.POST)
if form.is_valid():
conf = EmailConfirmation(type='userperson',
user=request.user,
email=form.cleaned_data['email'])
conf.save()
context['confirmation'] = conf
try:
send_mail('Patchwork email address confirmation',
render_to_string('patchwork/user-link.mail',
context, request=request),
settings.DEFAULT_FROM_EMAIL,
[form.cleaned_data['email']])
except smtplib.SMTPException:
context['confirmation'] = None
context['error'] = ('An error occurred during confirmation. '
'Please try again later')
else:
form = EmailForm()
context['linkform'] = form
return render(request, 'patchwork/user-link.html', context)
示例3: UserPersonConfirmTest
class UserPersonConfirmTest(TestCase):
def setUp(self):
EmailConfirmation.objects.all().delete()
Person.objects.all().delete()
self.user = TestUser()
self.client.login(username = self.user.username,
password = self.user.password)
self.conf = EmailConfirmation(type = 'userperson',
email = self.user.secondary_email,
user = self.user.user)
self.conf.save()
def testUserPersonConfirm(self):
self.assertEquals(Person.objects.count(), 0)
response = self.client.get(_confirmation_url(self.conf))
self.assertEquals(response.status_code, 200)
# check that the Person object has been created and linked
self.assertEquals(Person.objects.count(), 1)
person = Person.objects.get(email = self.user.secondary_email)
self.assertEquals(person.email, self.user.secondary_email)
self.assertEquals(person.user, self.user.user)
# check that the confirmation has been marked as inactive. We
# need to reload the confirmation to check this.
conf = EmailConfirmation.objects.get(pk = self.conf.pk)
self.assertEquals(conf.active, False)
示例4: test_patch_submitter_expiry
def test_patch_submitter_expiry(self):
# someone submits a patch...
patch = create_patch()
submitter = patch.submitter
# ... then starts registration...
date = ((datetime.datetime.utcnow() - EmailConfirmation.validity) -
datetime.timedelta(hours=1))
user = create_user(link_person=False, email=submitter.email)
user.is_active = False
user.date_joined = user.last_login = date
user.save()
conf = EmailConfirmation(type='registration', user=user,
email=user.email)
conf.date = date
conf.save()
# ... which expires
expire_notifications()
# we should see no matching user
self.assertFalse(User.objects.filter(email=patch.submitter.email)
.exists())
# but the patch and person should still be present
self.assertTrue(Person.objects.filter(pk=submitter.pk).exists())
self.assertTrue(Patch.objects.filter(pk=patch.pk).exists())
# and there should be no user associated with the person
self.assertEqual(Person.objects.get(pk=submitter.pk).user, None)
示例5: register
def register(self, date):
user = create_user()
user.is_active = False
user.date_joined = user.last_login = date
user.save()
conf = EmailConfirmation(type="registration", user=user, email=user.email)
conf.date = date
conf.save()
return (user, conf)
示例6: testUnlinkNonPost
def testUnlinkNonPost(self):
user = TestUser()
self.client.login(username=user.username,
password=user.password)
conf = EmailConfirmation(type='userperson',
email=user.secondary_email,
user=user.user)
conf.save()
self.client.get(_confirmation_url(conf))
person = Person.objects.get(email=user.secondary_email)
response = self.client.get(self.form_url.format(pid=str(person.id)))
self.assertRedirects(response, self.done_url)
person = Person.objects.get(email=user.secondary_email)
self.assertEquals(person.user, user.user)
示例7: setUp
def setUp(self):
EmailConfirmation.objects.all().delete()
Person.objects.all().delete()
self.user = TestUser()
self.conf = EmailConfirmation(type = 'userperson',
email = self.user.secondary_email,
user = self.user.user)
self.conf.save()
示例8: setUp
def setUp(self):
self.user = create_user()
self.secondary_email = _generate_secondary_email(self.user)
self.conf = EmailConfirmation(type='userperson',
email=self.secondary_email,
user=self.user)
self.conf.save()
示例9: testPatchSubmitterExpiry
def testPatchSubmitterExpiry(self):
defaults.project.save()
defaults.patch_author_person.save()
# someone submits a patch...
patch = Patch(project=defaults.project,
msgid='[email protected]', name='test patch',
submitter=defaults.patch_author_person,
content=defaults.patch)
patch.save()
# ... then starts registration...
date = ((datetime.datetime.now() - EmailConfirmation.validity) -
datetime.timedelta(hours=1))
userid = 'test-user'
user = User.objects.create_user(
userid,
defaults.patch_author_person.email, userid)
user.is_active = False
user.date_joined = user.last_login = date
user.save()
self.assertEqual(user.email, patch.submitter.email)
conf = EmailConfirmation(type='registration', user=user,
email=user.email)
conf.date = date
conf.save()
# ... which expires
do_expiry()
# we should see no matching user
self.assertFalse(User.objects.filter(email=patch.submitter.email)
.exists())
# but the patch and person should still be present
self.assertTrue(Person.objects.filter(
pk=defaults.patch_author_person.pk).exists())
self.assertTrue(Patch.objects.filter(pk=patch.pk).exists())
# and there should be no user associated with the person
self.assertEqual(Person.objects.get(
pk=defaults.patch_author_person.pk).user, None)
示例10: testUnlinkAnotherUser
def testUnlinkAnotherUser(self):
user = TestUser()
self.client.login(username=user.username,
password=user.password)
other_user = TestUser('testuser_other', '[email protected]',
'[email protected]')
conf = EmailConfirmation(type='userperson',
email=other_user.email,
user=other_user.user)
conf.save()
self.client.get(_confirmation_url(conf))
person = Person.objects.get(email=other_user.email)
response = self.client.post(self.form_url.format(pid=str(person.id)))
self.assertRedirects(response, self.done_url)
person = Person.objects.get(email=other_user.email)
self.assertEquals(person.user, None)
示例11: setUp
def setUp(self):
EmailConfirmation.objects.all().delete()
Person.objects.all().delete()
self.user = TestUser()
self.client.login(username = self.user.username,
password = self.user.password)
self.conf = EmailConfirmation(type = 'userperson',
email = self.user.secondary_email,
user = self.user.user)
self.conf.save()
示例12: register
def register(request):
context = PatchworkRequestContext(request)
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
data = form.cleaned_data
# create inactive user
user = auth.models.User.objects.create_user(data['username'],
data['email'],
data['password'])
user.is_active = False
user.first_name = data.get('first_name', '')
user.last_name = data.get('last_name', '')
user.save()
# create confirmation
conf = EmailConfirmation(type='registration', user=user,
email=user.email)
conf.save()
# send email
mail_ctx = {'site': Site.objects.get_current(),
'confirmation': conf}
subject = render_to_string(
'patchwork/activation_email_subject.txt',
mail_ctx).replace('\n', ' ').strip()
message = render_to_string('patchwork/activation_email.txt',
mail_ctx)
send_mail(subject, message, settings.DEFAULT_FROM_EMAIL,
[conf.email])
# setting 'confirmation' in the template indicates success
context['confirmation'] = conf
else:
form = RegistrationForm()
return render_to_response('patchwork/registration_form.html',
{'form': form},
context_instance=context)
示例13: optinout
def optinout(request, action, description):
context = PatchworkRequestContext(request)
mail_template = 'patchwork/%s-request.mail' % action
html_template = 'patchwork/%s-request.html' % action
if request.method != 'POST':
return HttpResponseRedirect(reverse(settings))
form = OptinoutRequestForm(data=request.POST)
if not form.is_valid():
context['error'] = ('There was an error in the %s form. ' +
'Please review the form and re-submit.') % \
description
context['form'] = form
return render_to_response(html_template, context)
email = form.cleaned_data['email']
if action == 'optin' and \
EmailOptout.objects.filter(email=email).count() == 0:
context['error'] = ('The email address %s is not on the ' +
'patchwork opt-out list, so you don\'t ' +
'need to opt back in') % email
context['form'] = form
return render_to_response(html_template, context)
conf = EmailConfirmation(type=action, email=email)
conf.save()
context['confirmation'] = conf
mail = render_to_string(mail_template, context)
try:
send_mail('Patchwork %s confirmation' % description, mail,
conf_settings.DEFAULT_FROM_EMAIL, [email])
context['email'] = mail
context['email_sent'] = True
except Exception:
context['error'] = ('An error occurred during confirmation . '
'Please try again later.')
context['admins'] = conf_settings.ADMINS
return render_to_response(html_template, context)
示例14: InvalidConfirmationTest
class InvalidConfirmationTest(TestCase):
def setUp(self):
EmailConfirmation.objects.all().delete()
Person.objects.all().delete()
self.user = TestUser()
self.conf = EmailConfirmation(type = 'userperson',
email = self.user.secondary_email,
user = self.user.user)
self.conf.save()
def testInactiveConfirmation(self):
self.conf.active = False
self.conf.save()
response = self.client.get(_confirmation_url(self.conf))
self.assertEquals(response.status_code, 200)
self.assertTemplateUsed(response, 'patchwork/confirm-error.html')
self.assertEqual(response.context['error'], 'inactive')
self.assertEqual(response.context['conf'], self.conf)
def testExpiredConfirmation(self):
self.conf.date -= self.conf.validity
self.conf.save()
response = self.client.get(_confirmation_url(self.conf))
self.assertEquals(response.status_code, 200)
self.assertTemplateUsed(response, 'patchwork/confirm-error.html')
self.assertEqual(response.context['error'], 'expired')
self.assertEqual(response.context['conf'], self.conf)
示例15: InvalidConfirmationTest
class InvalidConfirmationTest(TestCase):
def setUp(self):
self.user = create_user()
self.secondary_email = _generate_secondary_email(self.user)
self.conf = EmailConfirmation(type='userperson',
email=self.secondary_email,
user=self.user)
self.conf.save()
def test_inactive_confirmation(self):
self.conf.active = False
self.conf.save()
response = self.client.get(_confirmation_url(self.conf))
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'patchwork/confirm-error.html')
self.assertEqual(response.context['error'], 'inactive')
self.assertEqual(response.context['conf'], self.conf)
def test_expired_confirmation(self):
self.conf.date -= self.conf.validity
self.conf.save()
response = self.client.get(_confirmation_url(self.conf))
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'patchwork/confirm-error.html')
self.assertEqual(response.context['error'], 'expired')
self.assertEqual(response.context['conf'], self.conf)