def admin(): logger.info("Got an admin panel page request: %s" % request) form = CAdmin() db = AndrewDB() g.role = 'admin' logger.info("Validating the Create admin form") form.csrf_enabled = False if request.method == 'POST' and form.validate_on_submit(): hash_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user_id = db.insert_sys_user_get_id(form.email.data, hash_password) if user_id is None: flash('User with this email already registered') logger.info( "User with this email already registered, Redirecting to admin page" ) return redirect(url_for('admin-panel')) db.insert_admin(str(user_id), form.first_name.data, form.last_name.data, form.telephone.data) flash("Admin was added") logger.info("Admin was added, Redirecting to admin page") return redirect(url_for('admin-panel')) hotels = db.get_all_hotels() users = db.get_all_system_users() db_stat = db.get_db_statistics() admins = db.get_all_admins() g.db.commit() logger.info("Rendering the admin_panel page") return render_template('admin_panel.html', hotels=hotels, users=users, db_stat=db_stat, form=form, admins=admins)
def test_get_db_statistics(mock_connect): """Get IO database performance""" with allure.step('Get db statistics'): with app.app_context(): db = AndrewDB() expected = [{'cache_hit_ratio': 1.01, 'numbackends': 0}] mock_connect().cursor.return_value.fetchall.return_value = expected result = db.get_db_statistics() assert result == expected[0]