コード例 #1
0
class OptoutTest(TestCase):
    view = 'patchwork.views.mail.optout'
    url = reverse(view)

    def setUp(self):
        self.email = u'*****@*****.**'
        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
0
ファイル: test_user.py プロジェクト: lsandoval/patchwork
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)
コード例 #3
0
    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)
コード例 #4
0
ファイル: user.py プロジェクト: wangxi11/patchwork
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

            subject = render_to_string('patchwork/mails/user-link-subject.txt')
            message = render_to_string('patchwork/mails/user-link.txt',
                                       context, request=request)
            try:
                send_mail(subject,
                          message,
                          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)
コード例 #5
0
def link(request):
    context = PatchworkRequestContext(request)

    if request.method == 'POST':
        form = UserPersonLinkForm(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),
                    settings.DEFAULT_FROM_EMAIL, [form.cleaned_data['email']])
            except Exception:
                context['confirmation'] = None
                context['error'] = 'An error occurred during confirmation. ' + \
                                   'Please try again later'
    else:
        form = UserPersonLinkForm()
    context['linkform'] = form

    return render_to_response('patchwork/user-link.html', context)
コード例 #6
0
ファイル: test_user.py プロジェクト: asdil12/patchwork
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.assertEqual(Person.objects.count(), 0)
        response = self.client.get(_confirmation_url(self.conf))
        self.assertEqual(response.status_code, 200)

        # check that the Person object has been created and linked
        self.assertEqual(Person.objects.count(), 1)
        person = Person.objects.get(email=self.user.secondary_email)
        self.assertEqual(person.email, self.user.secondary_email)
        self.assertEqual(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.assertEqual(conf.active, False)
コード例 #7
0
ファイル: test_expiry.py プロジェクト: daxtens/patchwork
    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)
コード例 #8
0
ファイル: user.py プロジェクト: getpatchwork/patchwork
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)
コード例 #9
0
ファイル: test_confirm.py プロジェクト: nwnk/patchwork
 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()
コード例 #10
0
    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()
コード例 #11
0
ファイル: test_user.py プロジェクト: asdil12/patchwork
 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
0
ファイル: test_expiry.py プロジェクト: getpatchwork/patchwork
    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)
コード例 #13
0
    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)
コード例 #14
0
ファイル: test_user.py プロジェクト: wangxi11/patchwork
    def setUp(self):
        self.user = create_user(link_person=False)
        self.password = User.objects.make_random_password()
        self.user.set_password(self.password)
        self.user.save()

        self.client.login(username=self.user.username, password=self.password)

        self.secondary_email = _generate_secondary_email(self.user)
        self.conf = EmailConfirmation(type='userperson',
                                      email=self.secondary_email,
                                      user=self.user)
        self.conf.save()
コード例 #15
0
def register(request):
    context = {}

    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()

            context['confirmation'] = conf

            # send email
            subject = render_to_string(
                'patchwork/mails/activation-subject.txt'
            )
            message = render_to_string(
                'patchwork/mails/activation.txt',
                {'site': Site.objects.get_current(), 'confirmation': conf},
            )

            try:
                send_mail(
                    subject, message, settings.DEFAULT_FROM_EMAIL, [conf.email]
                )
            except smtplib.SMTPException:
                context['confirmation'] = None
                context['error'] = (
                    'An error occurred during registration. '
                    'Please try again later'
                )
    else:
        form = RegistrationForm()

    context['form'] = form

    return render(request, 'patchwork/registration.html', context)
コード例 #16
0
ファイル: test_user.py プロジェクト: asdil12/patchwork
    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.assertEqual(person.user, user.user)
コード例 #17
0
ファイル: test_user.py プロジェクト: lsandoval/patchwork
    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)
コード例 #18
0
ファイル: test_confirm.py プロジェクト: alialnu/patchwork
    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()
コード例 #19
0
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)
コード例 #20
0
    def testPatchSubmitterExpiry(self):
        defaults.project.save()
        defaults.patch_author_person.save()

        # someone submits a patch...
        patch = Patch(project=defaults.project,
                      msgid='*****@*****.**',
                      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)
コード例 #21
0
ファイル: test_user.py プロジェクト: asdil12/patchwork
    def testUnlinkAnotherUser(self):
        user = TestUser()
        self.client.login(username=user.username, password=user.password)

        other_user = TestUser('testuser_other', '*****@*****.**',
                              '*****@*****.**')
        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.assertEqual(person.user, None)
コード例 #22
0
ファイル: test_user.py プロジェクト: lsandoval/patchwork
 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()
コード例 #23
0
ファイル: user.py プロジェクト: anderco/patchwork
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)
コード例 #24
0
ファイル: test_expiry.py プロジェクト: anderco/patchwork
    def testPatchSubmitterExpiry(self):
        defaults.project.save()
        defaults.patch_author_person.save()

        # someone submits a patch...
        patch = Patch(project=defaults.project,
                      msgid='*****@*****.**', 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)
コード例 #25
0
ファイル: test_user.py プロジェクト: lsandoval/patchwork
    def testUnlinkAnotherUser(self):
        user = TestUser()
        self.client.login(username=user.username,
                          password=user.password)

        other_user = TestUser('testuser_other', '*****@*****.**',
                              '*****@*****.**')
        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)
コード例 #26
0
ファイル: mail.py プロジェクト: wangxi11/patchwork
def _optinout(request, action):
    context = {}
    mail_template = 'patchwork/mails/%s-request.txt' % action
    mail_subject_template = 'patchwork/mails/%s-request-subject.txt' % action
    html_template = 'patchwork/%s-request.html' % action

    if request.method != 'POST':
        return HttpResponseRedirect(reverse(settings))

    form = EmailForm(data=request.POST)
    if not form.is_valid():
        context['error'] = ('There was an error in the form. Please review '
                            'and re-submit.')
        context['form'] = form
        return render(request, 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(request, html_template, context)

    conf = EmailConfirmation(type=action, email=email)
    conf.save()

    context['confirmation'] = conf

    subject = render_to_string(mail_subject_template)
    message = render_to_string(mail_template, context, request=request)

    try:
        send_mail(subject, message, conf_settings.DEFAULT_FROM_EMAIL, [email])
    except smtplib.SMTPException:
        context['confirmation'] = None
        context['error'] = ('An error occurred during confirmation . '
                            'Please try again later.')
        context['admins'] = conf_settings.ADMINS

    return render(request, html_template, context)
コード例 #27
0
class OptoutTest(TestCase):
    def setUp(self):
        self.email = u'*****@*****.**'
        self.conf = EmailConfirmation(type='optout', email=self.email)
        self.conf.save()

    def test_valid_hash(self):
        url = reverse('confirm', kwargs={'key': self.conf.key})
        response = self.client.get(url)

        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'patchwork/optout.html')
        self.assertContains(response, self.email)

        # check that we've got an optout in the list
        self.assertEqual(EmailOptout.objects.count(), 1)
        self.assertEqual(EmailOptout.objects.all()[0].email, self.email)

        # check that the confirmation is now inactive
        self.assertFalse(EmailConfirmation.objects.get(pk=self.conf.pk).active)
コード例 #28
0
def optinout(request, action, description):
    context = {'site': Site.objects.get_current()}

    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(request, 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(request, 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(request, html_template, context)
コード例 #29
0
ファイル: mail.py プロジェクト: anderco/patchwork
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)
コード例 #30
0
class OptinTest(TestCase):
    def setUp(self):
        self.email = u'*****@*****.**'
        self.optout = EmailOptout(email=self.email)
        self.optout.save()
        self.conf = EmailConfirmation(type='optin', email=self.email)
        self.conf.save()

    def testOptinValidHash(self):
        url = reverse('confirm', kwargs={'key': self.conf.key})
        response = self.client.get(url)

        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'patchwork/optin.html')
        self.assertContains(response, self.email)

        # check that there's no optout remaining
        self.assertEqual(EmailOptout.objects.count(), 0)

        # check that the confirmation is now inactive
        self.assertFalse(EmailConfirmation.objects.get(pk=self.conf.pk).active)
コード例 #31
0
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)
コード例 #32
0
ファイル: test_confirm.py プロジェクト: nwnk/patchwork
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)
コード例 #33
0
ファイル: test_confirm.py プロジェクト: alialnu/patchwork
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)
コード例 #34
0
class OptinTest(TestCase):

    def setUp(self):
        self.email = u'*****@*****.**'
        self.optout = EmailOptout(email=self.email)
        self.optout.save()
        self.conf = EmailConfirmation(type='optin', email=self.email)
        self.conf.save()

    def test_valid_hash(self):
        response = self.client.get(
            reverse('confirm', kwargs={'key': self.conf.key}))

        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'patchwork/optin.html')
        self.assertContains(response, self.email)

        # check that there's no optout remaining
        self.assertEqual(EmailOptout.objects.count(), 0)

        # check that the confirmation is now inactive
        self.assertFalse(EmailConfirmation.objects.get(
            pk=self.conf.pk).active)
コード例 #35
0
ファイル: test_user.py プロジェクト: nickglobal/patchwork
    def setUp(self):
        self.user = create_user(link_person=False)
        self.password = User.objects.make_random_password()
        self.user.set_password(self.password)
        self.user.save()

        self.client.login(username=self.user.username,
                          password=self.password)

        self.secondary_email = _generate_secondary_email(self.user)
        self.conf = EmailConfirmation(type='userperson',
                                      email=self.secondary_email,
                                      user=self.user)
        self.conf.save()
コード例 #36
0
 def setUp(self):
     self.email = u'*****@*****.**'
     self.optout = EmailOptout(email = self.email)
     self.optout.save()
     self.conf = EmailConfirmation(type = 'optin', email = self.email)
     self.conf.save()
コード例 #37
0
 def setUp(self):
     self.url = reverse('patchwork.views.mail.optout')
     self.email = u'*****@*****.**'
     self.conf = EmailConfirmation(type = 'optout', email = self.email)
     self.conf.save()
コード例 #38
0
 def _create_confirmation(self, email):
     conf = EmailConfirmation(type='userperson',
                              email=email,
                              user=self.user)
     conf.save()
     self.client.get(_confirmation_url(conf))
コード例 #39
0
ファイル: test_user.py プロジェクト: nickglobal/patchwork
 def _create_confirmation(self, email):
     conf = EmailConfirmation(type='userperson',
                              email=email,
                              user=self.user)
     conf.save()
     self.client.get(_confirmation_url(conf))