def get_profile(): logger.info("Got a profile page request: %s" % request) db = AndrewDB() form = ProfileForm() user = current_user user_info = None form.csrf_enabled = False if user.is_customer(): res = db.get_customer_by_id(user.user_id) user_info = Customer(res['first_name'], res['last_name'], user.email, res['phone_number'], res['payment_info']) elif user.is_hotel_admin(): res = db.get_hotel_admin_by_id(user.user_id) if res: user_info = HotelAdmin(res['first_name'], res['last_name'], user.email, res['phone_number']) else: flash("Unable to find a hotel admin entry") logger.info( "Unable to find a hotel admin entry, Redirecting to index page" ) return redirect(url_for('index')) elif user.is_receptionist(): user_info = db.get_receptionist_by_id(user.user_id) user_info['email'] = user.email elif user.is_admin(): db.get_admin_by_id(user.user_id) user_info['email'] = user.email logger.info("Rendering the Profile page") return render_template('profile.html', form=form, user=user_info)
def test_get_admin_by_id(mock_connect): """Get administrator user from database by id""" with allure.step('Get admin by id'): with app.app_context(): db = AndrewDB() expected = {1: 'admin1'} mock_connect().cursor.return_value.fetchone.return_value = expected result = db.get_admin_by_id(1) assert result == expected