def test_valid_buyer_registration_form(self): """ test a valid buyer registration form """ post_dict = { 'password': '******', 'username': '******', 'email': '*****@*****.**', 'first_name': 'test', 'last_name': 'user' } form = CustomerRegistration(post_dict) self.assertTrue(form.is_valid())
def test_invalid_buyer_registration_form_dupe_email(self): """ test an invalid buyer registration form caused by a duplicate email """ user = fixtures.create_user( username='******', password='******', email='*****@*****.**', first_name='test', last_name='user' ) post_dict = { 'password': '******', 'username': '******', 'email': '*****@*****.**', 'first_name': 'test', 'last_name': 'user' } form = CustomerRegistration(post_dict) self.assertFalse(form.is_valid()) self.assertIn('This email is already registered.', form.errors['email'])
def test_invalid_buyer_registration_form_dupe_username(self): """ test an invalid buyer registration form caused by a duplicate username """ user = fixtures.create_user( username='******', password='******', email='*****@*****.**', first_name='test', last_name='user' ) post_dict = { 'password': '******', 'username': '******', 'email': '*****@*****.**', 'first_name': 'test', 'last_name': 'user' } form = CustomerRegistration(post_dict) self.assertFalse(form.is_valid()) self.assertIn('User with this Username already exists.', form.errors['username'])
def artlover_form(request): if request.method == 'POST': user_form = CustomerRegistration(data=request.POST) if user_form.is_valid(): user = user_form.save(commit=False) user.type = 'customer' user.is_artist = False user.is_active = False user.set_password(user.password) user.save() #TODO: find a way to properly handle this #catching when there isn't a secret answer try: secret_question = ast.literal_eval(user_form['secret_question'].value()) secret_answer_val = user_form['secret_answer'].value() secret_answer = SecurityAnswer() secret_answer.user_id = user.id secret_answer.security_questions_id = secret_question.get('id') secret_answer.answer = secret_answer_val secret_answer.save() except Exception as e: pass email_message = "Your Liwi account was created, activate it by clicking the link. localhost:8000/registration/activate/%s" % (user.id) msg = EmailMultiAlternatives('Activate User', email_message , '*****@*****.**', [user.email]) html_email = "<a href='http://ec2-54-213-188-46.us-west-2.compute.amazonaws.com/registration/activate/%s'>Activate</a>" % (user.id) msg.attach_alternative(html_email, "text/html") resp = msg.send() messages.add_message(request, messages.SUCCESS, 'Account created, an email was sent to your email with instructions to activate your account.') return HttpResponseRedirect('/login/') else: template = loader.get_template('registration/buyer_form.html') context = RequestContext(request, {'user_form': user_form}) return HttpResponse(template.render(context)) else: user_form = CustomerRegistration(initial={'is_artist':False}) template = loader.get_template('registration/buyer_form.html') context = RequestContext(request, {'user_form': user_form}) return HttpResponse(template.render(context))