def test_form_valid(self): form = FeedbackForm() self.mock.StubOutWithMock(form, 'send_email') form.send_email() self.mock.ReplayAll() self.view.form_valid(form) self.mock.VerifyAll()
def test_send_email(self): form = FeedbackForm(data={"email": "*****@*****.**", "body": "test email"}) if form.is_valid(): form.send_email() else: self.assertFail() self.assertEqual(len(mail.outbox), 1)
def test_send_email(self): form = FeedbackForm(data={ 'email': '*****@*****.**', 'body': 'test email' }) if form.is_valid(): form.send_email() else: self.assertFail() self.assertEqual(len(mail.outbox), 1)
def contact(request): if request.method == 'POST': form = FeedbackForm(request.POST) if(form.is_valid()): print(request.POST['name']) print(request.POST['message']) message = 'Thank you for you feedback.' else: message = 'Sorry, something went wrong.' return render_to_response('contact/contact.html', {'success': message}, context_instance=RequestContext(request)) else: return render_to_response('contact/contact.html', {'form': FeedbackForm()}, context_instance=RequestContext(request))
def feedback(request): if(request.method == "POST"): form = FeedbackForm(request.POST) if(form.is_valid()): send_mail('[GoDjango Feedback Form]', request.POST['body'], request.POST['email'], ['*****@*****.**'], fail_silently=False) message = "Thank you for the email" else: message = "Please be sure to use an email address and have a message in the body." else: message = "" return render_to_response('contact/feedback.html', { 'form':FeedbackForm(), 'message':message }, context_instance=RequestContext(request))
def feedback(request): if (request.method == "POST"): form = FeedbackForm(request.POST) if (form.is_valid()): send_mail('[GoDjango Feedback Form]', request.POST['body'], request.POST['email'], ['*****@*****.**'], fail_silently=False) message = "Thank you for the email" else: message = "Please be sure to use an email address and have a message in the body." else: message = "" return render_to_response('contact/feedback.html', { 'form': FeedbackForm(), 'message': message }, context_instance=RequestContext(request))
def feedback(request): if request.method == "POST": form = FeedbackForm(request.POST) if form.is_valid(): send_mail( "[GoDjango Feedback Form]", request.POST["body"], request.POST["email"], ["*****@*****.**"], fail_silently=False, ) message = "Thank you for the email" else: message = "Please be sure to use an email address and have a message in the body." else: message = "" return render_to_response( "contact/feedback.html", {"form": FeedbackForm(), "message": message}, context_instance=RequestContext(request) )