def test_cannot_create_duplicate_email(self):
     # setup initial data or something
     # execute the behaviour you want to test
     # verify the output of the behaviour (sometimes mocks/stubs as well)
     
     """
     If I have a user with email "*****@*****.**"
     And I try to create a new user with the create user form with email "*****@*****.**"
     Then the form should be invalid
     """
     
     test_email = '*****@*****.**'
     UserFactory.create(email=test_email)
     
     from tao.models import TaoUser
     self.assertEqual(1, TaoUser.objects.count())
     user_form = UserCreationForm({'title': 'a',
         'first_name': 'b', 
         'last_name': 'c', 
         'institution': 'd', 
         'email': test_email, 
         'recaptcha_response_field': 'PASSED',
         'username': '******',
         'password1': 'funnyfish',
         'password2': 'funnyfish'}, user=AnonymousUser())
     self.assertFalse(user_form.is_valid())
     self.assertEqual(['That email is already taken.'], user_form.errors['email'])
예제 #2
0
def register(request):
    if hasattr(request,'user') and hasattr(request.user,'account_registration_status'):
        if request.user.account_registration_status != TaoUser.RS_EMPTY:
            return redirect(account_status)
    from tao.forms import UserCreationForm
    if request.method == 'POST':
        form = UserCreationForm(request.POST, user=request.user)
        if form.is_valid():
            form.save()
            
            admin_emails = TaoUser.objects.admin_emails()
            context = Context({
                          'pending_requests_url': request.build_absolute_uri(reverse('access_requests')),
                          'user': form.cleaned_data
                      })
            send_mail("registration", context, "Registration submitted", admin_emails)
            
            messages.info(request, _("You will receive an email when your request has been approved."))
            return redirect(home)
    else:
        form = UserCreationForm(user=request.user)
        
    return render(request, "register.html", {
        'form': form,
        'user': request.user,
    })
 def test_create_user(self):
     user_form = UserCreationForm({'title': 'a',
         'first_name': 'b',
         'last_name': 'c',
         'institution': 'd',
         'email': '*****@*****.**',
         'recaptcha_response_field': 'PASSED',
         'username': '******',
         'password1': '123456',
         'password2': '123456'}, user=AnonymousUser())
     self.assertTrue(user_form.is_valid())