Best Python code snippet using localstack_python
fixtures.py
Source:fixtures.py
...58 cleanup_db,59 ensure_services_started,60 stop_all_services,61 )62 stop_all_services(app_context.app)63 ensure_services_started(["repository", "session_repository"])64 cleanup_db(_db)65 _db.create_all()66 yield _db67 _db.session.remove()68 cleanup_db(_db)69 stop_all_services(app_context.app)70@fixture71def session(db: SQLAlchemy) -> Session:72 return db.session73@fixture74def db_session(db: SQLAlchemy) -> Session:75 return db.session76# @fixture77# def client(app: Flask) -> FlaskClient:78# """Return a Web client, used for testing."""79# return app.test_client()80@fixture81def user(db: SQLAlchemy) -> User:82 from abilian.core.models.subjects import User83 user = User(...
main.py
Source:main.py
...24 #s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)25 #s.connect(("8.8.8.8", 80))26 #return s.getsockname()[0];27 return result.decode("utf-8")28def stop_all_services():29 # os.system("/bin/systemctl stop wazuh-manager")30 os.system("/bin/systemctl stop kibana.service")31 # os.system("/bin/systemctl stop filebeat")32 # os.system("/bin/systemctl stop elasticsearch")33def start_all_services():34 # os.system("/bin/systemctl start wazuh-manager")35 os.system("/bin/systemctl start kibana.service")36 # os.system("/bin/systemctl start filebeat")37 # os.system("/bin/systemctl start elasticsearch")38@app.route("/activate", methods=['GET', 'POST'])39def activate_dashboard():40 if exists('.license.silo'):41 return redirect(url_for('redirect_to_dashboard'))42 stop_all_services()43 if request.method == 'POST':44 license_key = request.form['license_key']45 try:46 result = check_key_validation(license_key)47 if result == -1:48 stop_all_services()49 return render_template("activate.html", error="License key has expired")50 else:51 store_key(license_key)52 return redirect(url_for('redirect_to_dashboard'))53 except ValueError:54 stop_all_services()55 return render_template("activate.html", error="Invalid license key")56 return render_template("activate.html")57@app.route("/redirect")58def redirect_to_dashboard():59 key = read_key()60 if key is None:61 return redirect(url_for('activate_dashboard'))62 else:63 try:64 result = check_key_validation(key)65 if result == -1:66 stop_all_services()67 return redirect(url_for('activate_dashboard'))68 else:69 data = {"ip": get_ip_address(), "duration_left": result}70 start_all_services()71 return render_template("redirect.html", data = data)72 except ValueError:73 return render_template("activate.html", error="Invalid license key")74@app.route("/")75def index():76 if exists('.license.silo'):77 return redirect(url_for('redirect_to_dashboard'))78 else:79 return redirect(url_for('activate_dashboard'))80if __name__ == "__main__":81 stop_all_services()...
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!!