コード例 #1
0
ファイル: forms.py プロジェクト: igoreus/txtr
 def test_registration(self):
     """
     Test that 'RegistrationForm' if data is valid.
     """
     form = RegistrationForm(data={'email': self.user_data['email'],
                                 'first_name': self.user_data['first_name'],
                                 'last_name': self.user_data['last_name'],
                                 'password1': self.user_data['password'],
                                 'password2': self.user_data['password']}
     )
     self.assertTrue(form.is_valid())
     user = form.register(True)
     self.assertTrue(isinstance(user, User))
コード例 #2
0
ファイル: views.py プロジェクト: igoreus/txtr
def registration(request, **kwargs):

    if request.method == "POST":
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = form.register()
            if user:
                login(request, user)
            return HttpResponseRedirect(reverse('home'))
    else:
        form = RegistrationForm()
    context = {
        'form': form,
    }
    context.update(csrf(request))
    return render_to_response("service/registration.html", context, context_instance=RequestContext(request))
コード例 #3
0
ファイル: forms.py プロジェクト: igoreus/txtr
    def test_registration_invalid_data(self):
        """
        Test 'RegistrationForm' for case if data is invalid.
        """
        invalid_data = [
            # wrong email
            {'email': 'foo.example.com',
                      'first_name': self.user_data['first_name'],
                      'last_name': self.user_data['last_name'],
                      'password1': self.user_data['password'],
                      'password2': self.user_data['password'],
            },
            # Wrong password: too small
            {'email': self.user_data['email'],
                      'first_name': self.user_data['first_name'],
                      'last_name': self.user_data['last_name'],
                      'password1': 'foo',
                      'password2': 'foo'
            },
            # Wrong password: without number
            {'email': self.user_data['email'],
                      'first_name': self.user_data['first_name'],
                      'last_name': self.user_data['last_name'],
                      'password1': 'foofoofoo',
                      'password2': 'foofoofoo'
            },
            # Wrong password: mismatched passwords.
            {'email': self.user_data['email'],
                      'first_name': self.user_data['first_name'],
                      'last_name': self.user_data['last_name'],
                      'password1': 'foo123',
                      'password2': 'bar123'
            },
            # Empty first and last name.
            {'email': self.user_data['email'],
                      'first_name': '',
                      'last_name': '',
                      'password1': self.user_data['password'],
                      'password2': self.user_data['password']
             },
        ]

        for data in invalid_data:
            form = RegistrationForm(data=data)
            self.assertFalse(form.is_valid())
コード例 #4
0
ファイル: forms.py プロジェクト: igoreus/txtr
    def test_registration_unique_email(self):
        """
        Test 'RegistrationForm' for case if email is not unique.
        """
        UserProfile.objects.create_user(**self.user_data)

        form = RegistrationForm(data={'email': self.user_data['email'],
                                      'first_name': self.user_data['first_name'],
                                      'last_name': self.user_data['last_name'],
                                      'password1': self.user_data['password'],
                                      'password2': self.user_data['password']}
        )
        self.assertFalse(form.is_valid())
        form = RegistrationForm(data={'email': '*****@*****.**',
                                      'first_name': self.user_data['first_name'],
                                      'last_name': self.user_data['last_name'],
                                      'password1': self.user_data['password'],
                                      'password2': self.user_data['password']}
        )
        self.assertTrue(form.is_valid())