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 test_mark_positive_nan_proprieties(self): """ It tests that health authority, to mark someone as covid-19 positive, have to insert an email or a phone number """ message = HealthyServices.mark_positive("", "") assert message == "Insert an email or a phone number"
def test_unmark_positive_nan_proprieties(self): """ It tests that health authority cannot mark a customer as healed without insert neither customer's email nor customer's phone number """ message = HealthyServices.mark_positive("", "") assert message == "Insert an email or a phone number"
def test_unmark_user_not_in_app(self): """ It tests that health authority cannot mark a customer as healed if the customer is not registered as customer """ message = HealthyServices.unmark_positive("*****@*****.**", "") assert message == "The customer is not registered"
def test_mark_positive_user_not_exist(self): """ It tests that health authority can't mark as covid-19 positive someone that is not registered as customer """ message = HealthyServices.mark_positive( user_email="*****@*****.**", user_phone="1234555") assert message == "The customer is not registered"
def test_mark_positive_already_covid(self): """ It tests that a customer can't be marked as covid-19 positive if he is already covid-19 positive """ 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.email, user.phone) assert len(message) is 0 message = HealthyServices.mark_positive(user.email, user.phone) assert message == "User with email {} already Covid-19 positive".format( user.email) delete_positive_with_user_id(user.id) del_user_on_db(user.id)
def test_mark_positive_user_by_phone(self): """ It tests that health authority can mark a customer as healed using only customer's phone number """ 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 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)
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)
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_mark_positive_user_by_email(self): """ It tests that health authority can mark a customer as covid-19 positive using only the customer's email """ user = create_user_on_db() assert user is not None assert user.role_id is 3 assert user is not None positive = positive_with_user_id(user.id) assert positive is None message = HealthyServices.mark_positive(user.email, "") assert len(message) is 0 delete_positive_with_user_id(user.id) del_user_on_db(user.id)
def test_mark_positive_ok(self): """ It tests that a user is correctly marked as covid-19 positive by health authority """ # an operator 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.email, user.phone) assert len(message) is 0 delete_positive_with_user_id(user.id) del_user_on_db(user.id)
def test_unmark_user_not_positive(self): """ It tests that health authority cannot mark a customer as healed if the customer is not covid-19 positive """ user = create_user_on_db() assert user is not None assert user.role_id is 3 message = HealthyServices.unmark_positive(user.email, user.phone) assert message == "User with email {} is not Covid-19 positive".format( user.email) delete_positive_with_user_id(user.id) del_user_on_db(user.id)
def unmark_positive(): form = SearchUserForm() if request.method == "POST": if form.validate_on_submit(): email = form.email.data phone = form.phone.data message = HealthyServices.unmark_positive(email, phone) if message == "": return redirect("/") return render_template( "unmark_positive.html", _test="unmark_positive_page", form=form, message=message, ) return render_template("unmark_positive.html", form=form)