def test_search_contacts_user_with_booking(self): """ Searching for list of contacts of a covid-19 positive customer with bookings """ owner = create_user_on_db(787436) assert owner is not None restaurant = create_restaurants_on_db("Pepperwood", user_id=owner.id) assert restaurant is not None customer1 = create_user_on_db(787437) assert customer1 is not None date_booking_1 = (get_today_midnight() - timedelta(days=datetime.today().weekday()) + timedelta(hours=13)) books1 = create_random_booking(1, restaurant.id, customer1, date_booking_1, "*****@*****.**") assert len(books1) == 1 # a new user that books in the same restaurant of the previous one customer2 = create_user_on_db(787438) assert customer2 is not None date_booking_2 = (get_today_midnight() - timedelta(days=datetime.today().weekday()) + timedelta(hours=13)) books2 = create_random_booking(1, restaurant.id, customer2, date_booking_2, "*****@*****.**") assert len(books2) == 1 # an user become covid19 positive positive = positive_with_user_id(customer1.id) assert positive is None message = HealthyServices.mark_positive(user_phone=customer1.phone) assert len(message) == 0 q_already_positive = (db.session.query(Positive).filter_by( user_id=customer1.id, marked=True).first()) assert q_already_positive is not None contacts = HealthyServices.search_contacts(customer1.id) assert len(contacts) == 1 message = HealthyServices.unmark_positive("", customer1.phone) assert len(message) == 0 del_user_on_db(customer1.id) del_user_on_db(customer2.id) del_restaurant_on_db(restaurant.id)
def search_contacts(): form = SearchUserForm() if request.method == "POST": if form.validate_on_submit(): if form.email.data == "" and form.phone.data == "": return render_template( "search_contacts.html", _test="search_contacts_no_data", form=form, message="Insert an email or a phone number".format( form.email.data), ) # filtering by email if form.email.data != "": q_user = db.session.query(User).filter_by( email=form.email.data) else: q_user = db.session.query(User).filter_by( phone=form.phone.data) if q_user.first() is None: return render_template( "search_contacts.html", _test="search_contact_not_registered", form=form, message="The user is not registered".format( form.email.data), ) q_already_positive = (db.session.query(Positive).filter_by( user_id=q_user.first().id, marked=True).first()) if q_already_positive is None: return render_template( "search_contacts.html", _test="search_contacts_no_positive", form=form, message="The user is not a covid-19 positive".format( form.email.data), ) contacts = HealthyServices.search_contacts(q_user.first().id) return render_template("list_contacts.html", _test="list_page", contacts=contacts) return render_template("/search_contacts.html", form=form)
def test_search_contacts_user_with_booking_only_one_user(self): """ Searching for list of contacts of a covid-19 positive customer with bookings """ user = get_user_with_email("*****@*****.**") positive = positive_with_user_id(user.id) assert positive is None message = HealthyServices.mark_positive("", user.phone) assert len(message) == 0 contacts = HealthyServices.search_contacts(user.id) assert len(contacts) == 0 message = HealthyServices.unmark_positive("", user.phone) assert len(message) == 0 delete_was_positive_with_user_id(user.id)
def test_search_contacts_user_with_no_booking(self): """ Searching for list of contacts of a covid-19 positive customer with no bookings """ user = create_user_on_db() assert user is not None assert user.role_id is 3 positive = positive_with_user_id(user.id) assert positive is None message = HealthyServices.mark_positive("", user.phone) assert len(message) is 0 contacts = HealthyServices.search_contacts(user.id) assert len(contacts) is 0 message = HealthyServices.unmark_positive("", user.phone) assert len(message) is 0 delete_was_positive_with_user_id(user.id) del_user_on_db(user.id)