Best Python code snippet using gabbi_python
test_views.py
Source:test_views.py
...46 """47 c = Client()48 response = c.get('/welcome/check/aws', follow=True)49 self.assertIn('expression', response.content.decode('utf-8'))50 def test_ssl_url(self):51 """52 Tests ``ssl`` url.53 """54 c = Client()55 response = c.get('/welcome/check/ssl', follow=True)56 self.assertIn('expression', response.content.decode('utf-8'))57 def test_s3_url(self):58 """59 Tests ``s3`` url.60 """61 c = Client()62 response = c.get('/welcome/check/s3', follow=True)63 self.assertIn('expression', response.content.decode('utf-8'))64 def test_smtp_url(self):...
route.py
Source:route.py
1import smtplib, glob, json2from email.message import EmailMessage3from flask import (Blueprint, render_template, session,4 flash, redirect, request, url_for)5contact = Blueprint('contact', __name__)6@contact.route("/contact",methods=["GET","POST"])7def contact_page():8 if request.method == "POST":9 10 # get data from fields11 sending_addr = 'info@techpoint.systems' # the request form address12 email_from = request.form['email'] # the person writing the email13 subject = request.form['subject']14 message = request.form['message'].strip()15 msg = EmailMessage()16 # subject17 msg['subject'] = subject18 # sending address19 msg['From'] = f'Request from Contact Form <{sending_addr}>'20 msg['To'] = 'james.mukuya@gmail.com'21 # message body22 23 msg.set_content(f"""Sender: <{email_from}>24 25Message:{message}26""")27 28 # get credentials from file29 credentials = get_auth()30 with smtplib.SMTP_SSL(credentials[0], 465) as smtp:31 smtp.login(credentials[1], credentials[2])32 smtp.send_message(msg)33 flash("Thank you for contacting Living Peak Group.\34 Your message has been sent","success")35 return redirect(url_for('contact.contact_page'))36 return render_template('contact/contact.html', title='Contact')37# get the credentials from secure file38def get_auth():39 for files in glob.iglob('**/*.json', recursive=True):40 with open(files) as f:41 data = json.load(f)42 url = data.get('test_SSL_URL')43 user_name = data.get('test_email_user')44 user_pass = data.get('test_email_pass')...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!