def test_mark_positive(test_app): app, test_client = test_app # create a health authority and an user for testing temp_ha_dict = dict(email='*****@*****.**', phone='3333333333', firstname='Ha', lastname='Ha', password='******', dateofbirth='05/10/2000', role='ha') 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 # --- UNIT TESTS --- with app.app_context(): # mark a wrong user user that doesn't exist getuser = db.session.query(User).filter( User.email == '*****@*****.**').first() assert getuser is None # get the user to be marked as positive getuser = db.session.query(User).filter( User.email == temp_user_example_dict['email']).first() assert getuser is not None new_quarantine = Quarantine() new_quarantine.user_id = getuser.id today = datetime.date.today() new_quarantine.start_date = today new_quarantine.end_date = today + datetime.timedelta(days=14) new_quarantine.in_observation = True db.session.add(new_quarantine) db.session.commit() getquarantine = db.session.query(Quarantine).filter( Quarantine.user_id == getuser.id).first() assert getquarantine is not None assert getquarantine.start_date == today assert getquarantine.end_date == today + datetime.timedelta(days=14) assert getquarantine.in_observation == True # change in_observation state, so the user can use the app again getquarantine.in_observation = False db.session.commit() getquarantinenewstatus = db.session.query(Quarantine).filter( Quarantine.user_id == getuser.id).first() assert getquarantinenewstatus.in_observation == False
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_component_edit_restaurant(test_app): app, test_client = test_app fields = { 'phone': '345', 'dishes-0-dish_name': 'pizza', 'dishes-0-price': 4, 'dishes-0-ingredients': 'pomodoro' } unc_fields = { 'phone': '', 'dishes-0-dish_name': 'pizza', 'dishes-0-price': 4, 'dishes-0-ingredients': 'pomodoro' } assert test_client.get('/edit_restaurant_informations', follow_redirects=True).status_code == 403 insert_ha(db, app) assert user_login_EP(test_client, email='*****@*****.**', password='******').status_code == 200 assert test_client.get('/edit_restaurant_informations', follow_redirects=True).status_code == 403 assert test_client.get('/logout', follow_redirects=True).status_code == 200 assert create_user_EP(test_client, email='*****@*****.**', password='******', role='owner').status_code == 200 # --- COMPONENTS TESTS --- #---------------------------------------------------------- building the starting conditions # log the user assert user_login_EP(test_client, email='*****@*****.**', password='******').status_code == 200 # create a restaurant by the logged user correct_restaurant = { 'name': 'Trial01-EP', 'lat': 22, 'lon': 22, 'phone': '3346734121', 'cuisine_type': [Restaurant.CUISINE_TYPES(1)], 'prec_measures': 'leggeX', 'avg_time_of_stay': 30, 'tables-0-table_name': 'yellow', 'tables-0-capacity': 5, 'dishes-0-dish_name': 'pizza', 'dishes-0-price': 4, 'dishes-0-ingredients': 'pomodoro', 'workingdays-0-day': WorkingDay.WEEK_DAYS(1), 'workingdays-0-work_shifts': "('12:00','15:00'),('19:00','23:00')" } # try owner with no restaurants assert test_client.get('/edit_restaurant_informations', follow_redirects=True).status_code == 403 assert create_restaurant_EP(test_client, correct_restaurant).status_code == 200 with app.app_context(): user = db.session.query(User).filter( User.email == '*****@*****.**').first() assert user is not None restaurant = db.session.query(Restaurant).filter_by( owner_id=user.id).first() assert restaurant is not None # try owner get with success assert test_client.get('/edit_restaurant_informations', follow_redirects=True).status_code == 200 # get with success assert test_client.get('/edit_restaurant_informations/' + str(restaurant.id), follow_redirects=True).status_code == 200 # try with wrong id assert test_client.post('/edit_restaurant_informations/' + str(10), data=fields, follow_redirects=True).status_code == 404 # post with invalid form assert test_client.post('/edit_restaurant_informations/' + str(restaurant.id), data=unc_fields, follow_redirects=True).status_code == 400 # post with success assert test_client.post('/edit_restaurant_informations/' + str(restaurant.id), data=fields, follow_redirects=True).status_code == 200 # try to post with ha assert test_client.get('/logout', follow_redirects=True).status_code == 200 assert user_login_EP(test_client, email='*****@*****.**', password='******').status_code == 200 assert test_client.post('/edit_restaurant_informations/' + str(restaurant.id), data=fields, follow_redirects=True).status_code == 403 assert test_client.get('/logout', follow_redirects=True).status_code == 200 # try without logged user assert test_client.post('/edit_restaurant_informations/' + str(restaurant.id), data=fields, follow_redirects=True).status_code == 403
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_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 create_app(): app = Flask(__name__) app.config['WTF_CSRF_SECRET_KEY'] = 'A SECRET KEY' app.config['SECRET_KEY'] = 'ANOTHER ONE' #app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://*****:*****@postgres:5432/postgres' app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URI'] app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False # Flask-Mail configuration app.config['MAIL_SERVER'] = 'smtp.googlemail.com' app.config['MAIL_PORT'] = 587 app.config['MAIL_USE_TLS'] = True app.config['MAIL_USERNAME'] = '******' app.config['MAIL_PASSWORD'] = '******' app.config['MAIL_DEFAULT_SENDER'] = '*****@*****.**' for bp in blueprints: app.register_blueprint(bp) bp.app = app db.init_app(app) login_manager.init_app(app) try: db.create_all(app=app) except Exception as e: print(e) # TODO THIS SECTION MUST BE REMOVED, ONLY FOR DEMO # already tested EndPoints are used to create examples app.config['WTF_CSRF_ENABLED'] = False with app.app_context(): q = db.session.query(User).filter(User.email == '*****@*****.**') adm = q.first() if adm is None: try: # create a first admin user # test for a user defined in database.db example = User() example.email = '*****@*****.**' example.phone = '3333333333' example.firstname = 'Admin' example.lastname = 'Admin' example.set_password('admin') example.dateofbirth = datetime.date(2020, 10, 5) example.role = 'admin' example.is_admin = True db.session.add(example) db.session.commit() test_client = app.test_client() insert_ha(db, app) for user in customers_example: create_user_EP(test_client,**user) for user in restaurant_owner_example: create_user_EP(test_client,**user) 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) except Exception as e: print(e) app.config['WTF_CSRF_ENABLED'] = True return app
def test_component_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 # access to patient information is forbidden for customers user_login_EP(test_client, temp_user_example_dict['email'], temp_user_example_dict['password']) result = test_client.get('/patient_informations', follow_redirects=True) assert result.status_code == 403 test_client.get('/logout', follow_redirects=True) # access to health authority is allowed user_login_EP(test_client, "*****@*****.**", "ha") result = test_client.get('/patient_informations', follow_redirects=True) assert result.status_code == 200 # wrong email must return patient not found result = test_client.post('/patient_informations', data=dict(email="*****@*****.**"), follow_redirects=True) assert result.status_code == 404 # try to mark the health authority itself result = test_client.post('/patient_informations', data=dict(email="*****@*****.**"), follow_redirects=True) assert result.status_code == 403 # correct email must returns the patient informations result = test_client.post('/patient_informations', data=dict(email=temp_user_example_dict['email']), follow_redirects=True) assert result.status_code == 200 # patient 1 is marked as positive assert mark_patient_as_positive( test_client, customers_example[0]['email']).status_code == 555 #result = test_client.post('/patient_informations?email=userexample1%40test.com', data=dict(mark_positive_button='mark_positive'), follow_redirects=True) #assert result.status_code == 555 # patient 2 is marked as positive assert mark_patient_as_positive( test_client, customers_example[1]['email']).status_code == 555 # a patient already marked will return a different html result = test_client.post('/patient_informations', data=dict(email=temp_user_example_dict['email']), follow_redirects=True) assert result.status_code == 200 # go to the previous page when patient is already marked as positive result = test_client.get( '/patient_informations?email=userexample1%40test.com', data=dict(go_back_button='go_back'), follow_redirects=True) assert result.status_code == 200
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_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