def test_mark_positive_user_precondition(self): """ It tests that a new user is not positive """ # 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, marked=True) assert positive is None delete_positive_with_user_id(user.id) del_user_on_db(user.id)
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_user_by_phone(self): """ It tests that health authority can mark a customer as covid-19 positive using only the customer's phone number """ user = create_user_on_db() assert user is not None positive = positive_with_user_id(user.id) assert positive is None message = HealthyServices.mark_positive("", user.phone) assert len(message) is 0 delete_positive_with_user_id(user.id) del_user_on_db(user.id)
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_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_unmark_positive_ok(self): """ It tests that health authority can mark a customer as healed using customer's email and 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.email, user.phone) assert len(message) is 0 message = HealthyServices.unmark_positive(user.email, 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)