def test_component_home(test_app): app, test_client = test_app assert test_client.get('/', follow_redirects=True).status_code == 200 # normal user assert create_user_EP(test_client).status_code == 200 assert user_login_EP(test_client).status_code == 200 assert test_client.get('/', follow_redirects=True).status_code == 200 # admin assert test_client.get('/logout', follow_redirects=True) #assert create_user_EP(test_client, email='*****@*****.**', password='******',role='admin').status_code == 200 insert_admin(db, app) assert user_login_EP(test_client, '*****@*****.**', 'admin').status_code == 200 assert test_client.get('/', follow_redirects=True).status_code == 200 # owner assert test_client.get('/logout', follow_redirects=True).status_code == 200 assert create_user_EP(test_client, email='*****@*****.**', password='******', role='owner').status_code == 200 assert user_login_EP(test_client, '*****@*****.**', 'owner').status_code == 200 assert test_client.get('/', follow_redirects=True).status_code == 200 assert create_restaurant_EP(test_client).status_code == 200 assert test_client.get('/', follow_redirects=True).status_code == 200 # ha -- to test the whole home I have to make reservations and mark positives assert test_client.get('/logout', follow_redirects=True) insert_ha(db, app) temp_user_example_dict = customers_example[1] assert create_user_EP(test_client, **temp_user_example_dict).status_code == 200 # create a owner and login temp_owner_example_dict = restaurant_owner_example[0] assert create_user_EP(test_client, **temp_owner_example_dict).status_code == 200 assert user_login_EP( test_client, temp_owner_example_dict['email'], temp_owner_example_dict['password']).status_code == 200 # create a restaurant temp_restaurant_example = restaurant_h24_example assert create_restaurant_EP(test_client, temp_restaurant_example).status_code == 200 restaurant = None with app.app_context(): restaurant = db.session.query(Restaurant).filter( Restaurant.name == temp_restaurant_example['name']).first() assert restaurant is not None # login user user_logout_EP(test_client) assert user_login_EP(test_client, temp_user_example_dict['email'], temp_user_example_dict['password']).status_code == 200 # make a reservation 1 date = datetime.datetime.now() - timedelta(days=2) timestamp = date.strftime("%d/%m/%Y") assert restaurant_reservation_EP(test_client, restaurant.id, timestamp, '20:00', '2').status_code == 200 reservation_date_str = timestamp + ' 20:00' assert restaurant_reservation_POST_EP(test_client, str(restaurant.id), '1', reservation_date_str, '2', { 'guest1': '*****@*****.**' }).status_code == 666 # make a reservation 2 date = datetime.datetime.now() - timedelta(days=1) timestamp = date.strftime("%d/%m/%Y") assert restaurant_reservation_EP(test_client, restaurant.id, timestamp, '20:00', '3').status_code == 200 reservation_date_str = timestamp + ' 20:00' assert restaurant_reservation_POST_EP( test_client, str(restaurant.id), '1', reservation_date_str, '3', { 'guest1': '*****@*****.**', 'guest2': customers_example[0]['email'] }).status_code == 666 # make a reservation 3 date = datetime.datetime.now() - timedelta(days=4) timestamp = date.strftime("%d/%m/%Y") assert restaurant_reservation_EP(test_client, restaurant.id, timestamp, '20:00', '3').status_code == 200 reservation_date_str = timestamp + ' 20:00' assert restaurant_reservation_POST_EP( test_client, str(restaurant.id), '1', reservation_date_str, '3', { 'guest1': '*****@*****.**', 'guest2': customers_example[0]['email'] }).status_code == 666 # a fake notification with user_id not associated with a real user with app.app_context(): new_notification = Notification() new_notification.user_id = 20 new_notification.message = 'message ' + timestamp + ' blabla' new_notification.email = '*****@*****.**' new_notification.pending = True new_notification.type_ = Notification.TYPE(1) new_notification.date = datetime.date.today() db.session.add(new_notification) db.session.commit() # confirm the guests with app.app_context(): seats = db.session.query(Seat).all() for s in seats: s.confirmed = True db.session.commit() # login ha user_logout_EP(test_client) assert user_login_EP(test_client, "*****@*****.**", "ha").status_code == 200 # mark positive assert mark_patient_as_positive( test_client, temp_user_example_dict['email']).status_code == 555 # test home ha assert test_client.get('/', follow_redirects=True).status_code == 200
def test_delete_user(test_app): app, test_client = test_app # unregister without a previous log-in assert test_client.delete('/delete_user', follow_redirects=True).status_code == 401 # unregister HA insert_ha(db, app) assert user_login_EP(test_client, '*****@*****.**', 'ha').status_code == 200 assert test_client.delete('/delete_user', follow_redirects=True).status_code == 403 assert user_logout_EP(test_client).status_code == 200 # unregister a user without reservations with app.app_context(): assert create_user_EP(test_client, email='*****@*****.**', password='******', role='customer').status_code == 200 assert user_login_EP(test_client, '*****@*****.**', 'passw').status_code == 200 assert test_client.delete('/delete_user', follow_redirects=True).status_code == 200 del_inactive_users() # check customer absence in the db assert db.session.query(User).filter( User.email == '*****@*****.**').first() == None assert user_logout_EP(test_client).status_code == 200 assert user_logout_EP(test_client).status_code == 401 assert user_login_EP(test_client, '*****@*****.**', 'passw').status_code == 401 # register a owner assert create_user_EP(test_client, email='*****@*****.**', password='******', role='owner').status_code == 200 # register a restaurant assert user_login_EP(test_client, '*****@*****.**', 'passw').status_code == 200 assert create_restaurant_EP(test_client, correct_restaurant).status_code == 200 assert user_logout_EP(test_client).status_code == 200 # register two guests assert create_user_EP(test_client, email='*****@*****.**', password='******', role='customer').status_code == 200 assert create_user_EP(test_client, email='*****@*****.**', password='******', role='customer').status_code == 200 # unregister a user with only future reservations with app.app_context(): assert create_user_EP(test_client, email='*****@*****.**', password='******', role='customer').status_code == 200 assert user_login_EP(test_client, '*****@*****.**', 'passw').status_code == 200 # register a reservation with 2 guests # check all them present in the db #user_test = db.session.query(User).filter(User.email == '*****@*****.**').first() #owner_test = db.session.query(User).filter(User.email == '*****@*****.**').first() #restaurant_test = db.session.query(Restaurant).filter(Restaurant.owner_id == owner_test.id).first() # look for a table in a correct date and time assert restaurant_reservation_EP( test_client, restaurant_id='1', #restaurant_test.id, date=correct_reservation['date'], time=correct_reservation['time'], guests=correct_reservation['guests'] + 1).status_code == 200 # placing a reservation reservation_date_str = correct_reservation[ 'date'] + " " + correct_reservation['time'] reservation_datetime = datetime.datetime.strptime( reservation_date_str, "%d/%m/%Y %H:%M") guests_email_dict = dict() for i in range(correct_reservation['guests']): key = 'guest' + str(i + 1) guests_email_dict[key] = correct_email[i] assert restaurant_reservation_POST_EP( test_client, restaurant_id='1', table_id_reservation=1, #8, date=reservation_date_str, guests=correct_reservation['guests'] + 1, data=guests_email_dict).status_code == 666 # checking via db if reservation has been added reservation_test = db.session.query(Reservation).filter( Reservation.restaurant_id == '1', Reservation.table_id == 1, #8, Reservation.date == reservation_datetime).first() assert reservation_test != None # unregister the customer, also all its future reservations assert test_client.delete('/delete_user', follow_redirects=True).status_code == 200 del_inactive_users() # check the changes in db us = db.session.query(User).filter( User.email == '*****@*****.**').first() assert us == None assert user_logout_EP(test_client).status_code == 200 assert user_logout_EP(test_client).status_code == 401 assert user_login_EP(test_client, '*****@*****.**', 'passw').status_code == 401 # unregister a user with a computed reservation but are not passed 14 days from this last with app.app_context(): assert create_user_EP(test_client, email='*****@*****.**', password='******', role='customer').status_code == 200 assert user_login_EP(test_client, '*****@*****.**', 'passw').status_code == 200 #user_test = db.session.query(User).filter(User.email == '*****@*****.**').first() # look for a table in a correct date and time startdate = datetime.date.today() enddate = startdate + datetime.timedelta( days=-1) # placing for yesterday assert restaurant_reservation_EP( test_client, restaurant_id='1', #restaurant_test.id, date=enddate, time=correct_reservation['time'], guests=correct_reservation['guests'] + 1).status_code == 200 # placing a reservation reservation_date_str = str( enddate.strftime("%d/%m/%Y")) + " " + correct_reservation['time'] reservation_datetime = datetime.datetime.strptime( reservation_date_str, "%d/%m/%Y %H:%M") guests_email_dict = dict() for i in range(correct_reservation['guests']): key = 'guest' + str(i + 1) guests_email_dict[key] = correct_email[i] assert restaurant_reservation_POST_EP( test_client, restaurant_id='1', table_id_reservation=2, #8, date=reservation_date_str, guests=correct_reservation['guests'] + 1, data=guests_email_dict).status_code == 666 # checking via db if reservation has been added reservation_test = db.session.query(Reservation).filter( Reservation.restaurant_id == '1', Reservation.table_id == 2, #8, Reservation.date == reservation_datetime).first() assert reservation_test != None # unregister the customer, also all its future reservations #assert user_test.id == 1 assert test_client.delete('/delete_user', follow_redirects=True).status_code == 200 del_inactive_users() # check the changes in db not happened since are not passed the days us = db.session.query(User).filter( User.email == '*****@*****.**').first() assert us != None assert user_logout_EP(test_client).status_code == 200 assert user_logout_EP(test_client).status_code == 401 assert user_login_EP(test_client, '*****@*****.**', 'passw').status_code == 401 # unregister a user with a computed reservation but are passed exactly 14 days from this last # we don't care for those happened more than 14 days ago with app.app_context(): assert create_user_EP(test_client, email='*****@*****.**', password='******', role='customer').status_code == 200 assert user_login_EP(test_client, '*****@*****.**', 'passw').status_code == 200 #user_test = db.session.query(User).filter(User.email == '*****@*****.**').first() # look for a table in a correct date and time startdate = datetime.date.today() enddate = startdate - datetime.timedelta( days=15) # placing for 14 days ago assert restaurant_reservation_EP( test_client, restaurant_id='1', #restaurant_test.id, date=enddate, time=correct_reservation['time'], guests=correct_reservation['guests'] + 1).status_code == 200 # placing a reservation reservation_date_str = str( enddate.strftime("%d/%m/%Y")) + " " + correct_reservation['time'] reservation_datetime = datetime.datetime.strptime( reservation_date_str, "%d/%m/%Y %H:%M") guests_email_dict = dict() for i in range(correct_reservation['guests']): key = 'guest' + str(i + 1) guests_email_dict[key] = correct_email[i] assert restaurant_reservation_POST_EP( test_client, restaurant_id='1', table_id_reservation=2, #8, date=reservation_date_str, guests=correct_reservation['guests'] + 1, data=guests_email_dict).status_code == 666 # checking via db if reservation has been added reservation_test = db.session.query(Reservation).filter( Reservation.restaurant_id == '1', Reservation.table_id == 2, #8, Reservation.date == reservation_datetime).first() assert reservation_test != None # unregister the customer, also all its reservations assert test_client.delete('/delete_user', follow_redirects=True).status_code == 200 del_inactive_users() # check the changes in db happened since now are passed excatly the days us = db.session.query(User).filter( User.email == '*****@*****.**').first() assert us == None assert user_logout_EP(test_client).status_code == 200 assert user_logout_EP(test_client).status_code == 401 assert user_login_EP(test_client, '*****@*****.**', 'passw').status_code == 401 # unregister a positive user with app.app_context(): assert create_user_EP(test_client, email='*****@*****.**', password='******', role='customer').status_code == 200 #assert user_login_EP(test_client, '*****@*****.**', 'passw').status_code == 200 #assert user_logout_EP(test_client).status_code == 200 # HA mark as positive the previous customer assert user_login_EP(test_client, '*****@*****.**', 'ha').status_code == 200 assert test_client.get('/patient_informations', follow_redirects=True).status_code == 200 assert test_client.post( '/patient_informations', data=dict(email="*****@*****.**"), follow_redirects=True).status_code == 200 assert mark_patient_as_positive( test_client, '*****@*****.**').status_code == 555 # check quarantine presence in the db #user_test = db.session.query(User).filter(User.email == '*****@*****.**').first() #assert db.session.query(Quarantine).filter(Quarantine.user_id == user_test.id).first() != None assert user_logout_EP(test_client).status_code == 200 # unregister a positive customer assert user_login_EP(test_client, '*****@*****.**', 'passw').status_code == 200 assert test_client.delete('/delete_user', follow_redirects=True).status_code == 200 del_inactive_users() #check quarantine and user presence in the db user_test = db.session.query(User).filter( User.email == '*****@*****.**').first() assert user_test.is_active == False user_quar = db.session.query(Quarantine).filter( Quarantine.user_id == user_test.id).first() assert user_quar.in_observation == True assert user_logout_EP(test_client).status_code == 200 assert user_logout_EP(test_client).status_code == 401 assert user_login_EP(test_client, '*****@*****.**', 'passw').status_code == 401 # unregister a owner user with app.app_context(): # check the presence of its restaurant and itself in the db owner_test = db.session.query(User).filter( User.email == '*****@*****.**').first() assert owner_test != None restaurant_test = db.session.query(Restaurant).filter( Restaurant.owner_id == owner_test.id).first() assert restaurant_test != None assert user_login_EP(test_client, '*****@*****.**', 'passw').status_code == 200 assert test_client.delete('/delete_user', follow_redirects=True).status_code == 200 del_inactive_users() # check the absence of its restaurant and itself in the db restaurant_test = db.session.query(Restaurant).filter( Restaurant.owner_id == owner_test.id).first() assert restaurant_test == None owner_test = db.session.query(User).filter( User.email == '*****@*****.**').first() assert owner_test == None assert user_logout_EP(test_client).status_code == 200 assert user_logout_EP(test_client).status_code == 401 assert user_login_EP(test_client, '*****@*****.**', 'passw').status_code == 401
def test_contact_tracing_health_authority(test_app): app, test_client = test_app # create a health authority and an user for testing temp_user_example_dict = customers_example[0] #assert create_user_EP(test_client, **temp_ha_dict).status_code == 200 insert_ha(db, app) assert create_user_EP(test_client, **temp_user_example_dict).status_code == 200 temp_user_example_dict = customers_example[1] assert create_user_EP(test_client, **temp_user_example_dict).status_code == 200 # create a owner and login temp_owner_example_dict = restaurant_owner_example[0] assert create_user_EP(test_client, **temp_owner_example_dict).status_code == 200 assert user_login_EP( test_client, temp_owner_example_dict['email'], temp_owner_example_dict['password']).status_code == 200 # create a restaurant temp_restaurant_example = restaurant_h24_example assert create_restaurant_EP(test_client, temp_restaurant_example).status_code == 200 restaurant = None with app.app_context(): restaurant = db.session.query(Restaurant).filter( Restaurant.name == temp_restaurant_example['name']).first() assert restaurant is not None # login user user_logout_EP(test_client) assert user_login_EP(test_client, temp_user_example_dict['email'], temp_user_example_dict['password']).status_code == 200 # make reservation 1 date = datetime.datetime.now() - timedelta(days=2) timestamp = date.strftime("%d/%m/%Y") assert restaurant_reservation_EP(test_client, restaurant.id, timestamp, '20:00', '2').status_code == 200 reservation_date_str = timestamp + ' 20:00' assert restaurant_reservation_POST_EP(test_client, str(restaurant.id), '1', reservation_date_str, '2', { 'guest1': '*****@*****.**' }).status_code == 666 # confirm the guests with app.app_context(): seats = db.session.query(Seat).all() for s in seats: s.confirmed = True db.session.commit() # make reservation 2 date = datetime.datetime.now() + timedelta(days=2) timestamp = date.strftime("%d/%m/%Y") assert restaurant_reservation_EP(test_client, restaurant.id, timestamp, '20:00', '2').status_code == 200 reservation_date_str = timestamp + ' 20:00' assert restaurant_reservation_POST_EP(test_client, str(restaurant.id), '1', reservation_date_str, '2', { 'guest1': '*****@*****.**' }).status_code == 666 # login ha user_logout_EP(test_client) assert user_login_EP(test_client, "*****@*****.**", "ha").status_code == 200 # mark positive assert mark_patient_as_positive( test_client, temp_user_example_dict['email']).status_code == 555 # test notification with app.app_context(): notifications = db.session.query(Notification).all() for n in notifications: print(n.message) assert len(notifications) == 3
def test_users_reservation(test_app): app, test_client = test_app # create customers for user in customers_example: create_user_EP(test_client, **user) # create restaurant owners for ro in restaurant_owner_example: create_user_EP(test_client, **ro) for usr_idx, restaurant in enumerate(restaurant_example): user_login_EP(test_client, restaurant_owner_example[usr_idx]['email'], restaurant_owner_example[usr_idx]['password']) create_restaurant_EP(test_client, restaurant) user_logout_EP(test_client) restaurant_id = ['1', '2', '3', '4'] reservation_date_str_dict = [ reservation_dates_example[1] + " " + reservation_times_example[0], reservation_dates_example[7] + " " + reservation_times_example[3] ] guests_email_dict = dict() for i in range(reservation_guests_number_example[1]): key = 'guest' + str(i + 1) guests_email_dict[key] = reservation_guests_email_example[i] # log as customer 1 user_login_EP(test_client, customers_example[0]['email'], customers_example[0]['password']) # Customer1 reservation 1 in the past assert restaurant_reservation_POST_EP(test_client, restaurant_id[0], 1, reservation_date_str_dict[0], reservation_guests_number_example[1], guests_email_dict).status_code == 666 # Customer1 reservation 2 in the future assert restaurant_reservation_POST_EP(test_client, restaurant_id[0], 1, reservation_date_str_dict[1], reservation_guests_number_example[1], guests_email_dict).status_code == 666 assert test_client.get('/users/reservation_list', follow_redirects=True).status_code == 200 assert test_client.get('/users/editreservation/1', follow_redirects=True).status_code == 200 guests_email_dict['guest-0-email'] = "*****@*****.**" assert test_client.post('/users/editreservation/1', data=guests_email_dict, follow_redirects=True).status_code == 222 # failure, there is no possibility to delete a past reservation assert test_client.get('/users/deletereservation/1', follow_redirects=True).status_code == 403 # failure, the reservation id with this user doesn't exist assert test_client.get('/users/editreservation/100', follow_redirects=True).status_code == 404 # failure, there is no possibility to delete a past reservation assert test_client.get('/users/deletereservation/2', follow_redirects=True).status_code == 200 insert_ha(db, app) assert user_logout_EP(test_client).status_code == 200 assert user_login_EP(test_client, '*****@*****.**', 'ha').status_code == 200 assert test_client.get('/users/reservation_list', follow_redirects=True).status_code == 403 assert test_client.get('/users/editreservation/1', follow_redirects=True).status_code == 403 assert test_client.get('/users/deletereservation/1', follow_redirects=True).status_code == 403
def test_component_reviews(test_app): app, test_client = test_app assert create_user_EP(test_client, **restaurant_owner_example[0]).status_code == 200 assert user_login_EP( test_client, restaurant_owner_example[0]['email'], restaurant_owner_example[0]['password']).status_code == 200 assert create_restaurant_EP(test_client).status_code == 200 review = dict(rating=4, comment='Good quality restaurant', date=datetime.date.today()) uncorrect_review = dict(rating=10, comment='Good quality restaurant', date=datetime.date.today()) with app.app_context(): # get a restaurant restaurant = db.session.query(Restaurant).filter_by( name=restaurant_example[0]['name']).first() #get a user, the owner user = db.session.query(User).filter_by( email=restaurant_owner_example[0]['email']).first() # try to get as a owner (555) assert test_client.get('/restaurants/reviews/' + str(restaurant.id), follow_redirects=True).status_code == 555 # try to review a place when i'm a owner (403) assert create_review_EP(test_client, review, restaurant.id).status_code == 403 # logout with the owner (200) assert test_client.get('/logout', follow_redirects=True).status_code == 200 # create a customer assert create_user_EP(test_client, **customers_example[0]).status_code == 200 # login with the customer (200) assert user_login_EP(test_client, customers_example[0]['email'], customers_example[0]['password']).status_code == 200 # try to get as a customer without a reservation (555) assert test_client.get('/restaurants/reviews/' + str(restaurant.id)).status_code == 555 assert create_review_EP(test_client, review, restaurant.id).status_code == 403 # create a reservation in the future (200) assert restaurant_reservation_EP( test_client, restaurant.id, '10/10/2030', reservation_times_example[0], reservation_guests_number_example[0]).status_code == 200 reservation_date_str = '10/10/2030' + " " + reservation_times_example[14] assert restaurant_reservation_POST_EP( test_client, str(restaurant.id), '8', reservation_date_str, '1', customers_example[0]['email']).status_code == 666 # try to review when i'm not been there yet assert test_client.get('/restaurants/reviews/' + str(restaurant.id)).status_code == 555 # create a reservation in the past(200) assert restaurant_reservation_EP( test_client, restaurant.id, '10/10/2020', reservation_times_example[0], reservation_guests_number_example[0]).status_code == 200 reservation_date_str = '10/10/2020' + " " + reservation_times_example[14] assert restaurant_reservation_POST_EP( test_client, str(restaurant.id), '8', reservation_date_str, '1', customers_example[0]['email']).status_code == 666 # try to send an invalid form (400) assert create_review_EP(test_client, uncorrect_review, restaurant.id).status_code == 400 # try to get as a customer who has a reservation (200) assert test_client.get('/restaurants/reviews/' + str(restaurant.id), follow_redirects=True).status_code == 200 assert create_review_EP(test_client, review, restaurant.id).status_code == 200 assert test_client.get('/restaurants/like/' + str(restaurant.id)).status_code == 200 assert test_client.get('/restaurants/like/' + str(restaurant.id)).status_code == 200 assert test_client.get('/restaurants', follow_redirects=True).status_code == 200 # try to double review the same restaurant (403) assert create_review_EP(test_client, review, restaurant.id).status_code == 403 # logout assert test_client.get('/logout', follow_redirects=True).status_code == 200 insert_ha(db, app) # login as health authority assert user_login_EP(test_client, "*****@*****.**", "ha").status_code == 200 # try to get as health authority (555) assert test_client.get('/restaurants/reviews/' + str(restaurant.id)).status_code == 403 assert test_client.get('/restaurants/' + str(restaurant.id)).status_code == 403 assert test_client.get('/restaurants/' + str(restaurant.id) + '/reservation').status_code == 403 assert test_client.get('/restaurants/like/' + str(restaurant.id)).status_code == 403 # try to post as health authority (403) assert create_review_EP(test_client, review, restaurant.id).status_code == 403