Esempio n. 1
0
    def save(self):
        user = DjbletsRegistrationForm.save(self)

        if user:
            user.first_name = self.cleaned_data['first_name']
            user.last_name = self.cleaned_data['last_name']
            user.save()

        return user
Esempio n. 2
0
    def save(self):
        """Save the form."""
        user = DjbletsRegistrationForm.save(self)

        if user:
            user.first_name = self.cleaned_data["first_name"]
            user.last_name = self.cleaned_data["last_name"]
            user.save()

        return user
Esempio n. 3
0
    def save(self):
        """Save the form."""
        user = DjbletsRegistrationForm.save(self)

        if user:
            user.first_name = self.cleaned_data['first_name']
            user.last_name = self.cleaned_data['last_name']
            user.save()

            self.accept_policies(user)

        return user
Esempio n. 4
0
    def test_save_with_username_taken(self):
        """Testing RegistrationForm.save with username already taken"""
        User.objects.create(username='******')

        form = RegistrationForm(data={
            'username': '******',
            'email': '*****@*****.**',
            'password1': 'password',
            'password2': 'password',
            'first_name': 'Test',
            'last_name': 'User',
        })
        self.assertTrue(form.is_valid())

        user = form.save()

        self.assertIsNone(user)
        self.assertIn('username', form.errors)
        self.assertEqual(form.errors['username'],
                         ['Sorry, this username is taken.'])
Esempio n. 5
0
    def test_save(self):
        """Testing RegistrationForm.save"""
        form = RegistrationForm(data={
            'username': '******',
            'email': '*****@*****.**',
            'password1': 'password',
            'password2': 'password',
            'first_name': 'Test',
            'last_name': 'User',
        })
        self.assertTrue(form.is_valid())

        user = form.save()

        self.assertIsNotNone(user)
        self.assertIsNotNone(user.pk)
        self.assertEqual(user.username, 'test')
        self.assertEqual(user.email, '*****@*****.**')
        self.assertEqual(user.first_name, 'Test')
        self.assertEqual(user.last_name, 'User')
        self.assertTrue(user.check_password('password'))