def other(): """ Render other enquiry page """ form = MiscForm() if form.validate_on_submit(): inquiry = form.create_inquiry() notify_shop_about_inquiry(inquiry) flash("Danke. Wir haben Ihre Anfrage erhalten!", "success") return redirect(url_for(".home")) return render_template('shop/other.html', other_inquiry_form=form)
def test_create_enquiry_existing_customer(self, app, sample_customer: Customer): form = MiscForm( first_name=sample_customer.first_name, last_name=sample_customer.last_name, email=sample_customer.email, problem_description="A" * 100 ) enquiry: MiscInquiry = form.create_inquiry() assert enquiry assert isinstance(enquiry.customer, Customer) assert enquiry.customer == sample_customer assert enquiry.description == "A" * 100 assert MiscInquiry.query.count() == 1
def test_create_enquiry_non_existing_customer(self, app, db): form = MiscForm( first_name="leon", last_name="richter", email="*****@*****.**", problem_description="A" * 30 ) assert MiscInquiry.query.count() == 0 enquiry: MiscInquiry = form.create_inquiry() assert enquiry assert isinstance(enquiry.customer, Customer) assert enquiry.customer.first_name == "leon" assert enquiry.customer.last_name == "richter" assert enquiry.description == "A" * 30 assert MiscInquiry.query.count() == 1
def test_customer_submits_twice(self, app, sample_customer): form = MiscForm( first_name=sample_customer.first_name, last_name=sample_customer.last_name, email=sample_customer.email, problem_description="A" * 30 ) form.create_inquiry() form.create_inquiry() form.create_inquiry() assert MiscInquiry.query.count() == 3 assert Customer.query.count() == 1
def test_form_text(self, app): form = MiscForm(first_name="Leon", last_name="Morten") assert not form.validate() form.problem_description.data = "Text 123" assert not form.validate() assert "Die Beschreibung muss zwischen 30 und 5000 Zeichen lang sein" in form.problem_description.errors form.problem_description.data = "A" * 31 assert not form.validate() assert not form.problem_description.errors form.email.data = "12" assert not form.validate() form.email.data = "*****@*****.**" assert form.validate()
def test_form_requires_lat_name(self, app): form = MiscForm() assert not form.validate() assert REQUIRED_TEXT in form.last_name.errors