Beispiel #1
0
def register(request):
    if request.method == 'POST':
        #data = request.POST.copy()  # so we can manipulate data
        form = RegisterForm(request.POST or None)
        if form.is_valid():
            form.save()
            messages.success(request, _("Welcome ! You may login now."))
            return HttpResponseRedirect(reverse('user-register-done'))
    else:
        form = RegisterForm()
    return render_to_response('register.html', {'form': form}, context_instance=RequestContext(request))
Beispiel #2
0
class ValidRegisterFormTest(FormTest):

    def setUp(self):
        super(ValidRegisterFormTest, self).setUp()
        self.form = RegisterForm(self.data)
        self.form.full_clean()
        self.new_user = self.form.save()

    def test_form_must_be_valid(self):
        self.assertTrue(self.form.is_valid())

    def test_user_created(self):
        user = User.objects.get(email=self.data['email'])
        self.assertEqual(user.email, self.data['email'])

    def test_user_cant_register_email_twice(self):
        self.form = RegisterForm(self.data)
        self.form.full_clean()
        self.assertTrue('email' in self.form.errors.keys())

    def test_user_cant_register_password_mismatch(self):
        self.data['password1'] = '321'
        self.data['password2'] = '123'
        self.form = RegisterForm(self.data)
        self.form.full_clean()
        self.assertTrue('password2' in self.form.errors.keys())

    def test_user_can_authenticated(self):
        backend = EmailBackend()
        user = backend.authenticate(self.data['email'], self.data['password1'])
        self.assertEqual(user.email, self.data['email'])