def test_booking_existing_patient(self): self.create_provider_and_enable_booking() # book once from public profile date_string = testutil.next_monday_date_string() time_string = '10' self.book_from_public_profile(date_string, time_string) self.patient_confirms_latest_booking(date_string, time_string, logged_in=True) self.logout_patient() messages = self.mail_stub.get_sent_messages(to=self._TEST_PATIENT_EMAIL) patient_email_count = len(messages) self.assertEqual(patient_email_count, 1) # book again from public profile date_string = testutil.next_monday_date_string() time_string = '11' self.book_from_public_profile(date_string, time_string) # did we receive another email? messages = self.mail_stub.get_sent_messages(to=self._TEST_PATIENT_EMAIL) patient_email_count = len(messages) self.assertEqual(patient_email_count, 2) provider_messages = self.mail_stub.get_sent_messages(to=self._TEST_PROVIDER_EMAIL) provider_email_count = len(provider_messages) self.assertEqual(provider_email_count, 2)
def test_booking_removed_from_public_profile_availability(self): ''' if someone forces the URL to book something outside available schedule ''' self.create_complete_provider_profile() self.logout_provider() self.login_as_admin() # enable booking response = self.testapp.get('/admin/provider/feature/booking_enabled/' + self._TEST_PROVIDER_VANITY_URL) response.mustcontain("Show booking=True") self.logout_admin() # check it appears as available on public profile and booking page response = self.testapp.get('/' + self._TEST_PROVIDER_VANITY_URL) # book an appointment for next monday at 10am next_monday = testutil.next_weekday_date_string(0) self.book_from_public_profile(next_monday, 10, self._TEST_PATIENT_EMAIL, self._TEST_PATIENT_TELEPHONE) self.patient_confirms_latest_booking(next_monday, 10, logged_in=True) self.logout_patient() # check schedule on public profile response = self.testapp.get('/' + self._TEST_PROVIDER_VANITY_URL) response.mustcontain(no=testutil.next_monday_date_string()+"/10/0") response.mustcontain(no="button-"+testutil.next_monday_date_string()+"-10-0") # check the book response = self.testapp.get('/' + self._TEST_PROVIDER_VANITY_URL + '/book') response.mustcontain(no=testutil.next_monday_date_string()+"/10/0") response.mustcontain(no="button-"+testutil.next_monday_date_string()+"-10-0")
def test_booking_existing_patient(self): self.create_provider_and_enable_booking() # book once from public profile date_string = testutil.next_monday_date_string() time_string = '10' self.book_from_public_profile(date_string, time_string) self.patient_confirms_latest_booking(date_string, time_string, logged_in=True) self.logout_patient() messages = self.mail_stub.get_sent_messages( to=self._TEST_PATIENT_EMAIL) patient_email_count = len(messages) self.assertEqual(patient_email_count, 1) # book again from public profile date_string = testutil.next_monday_date_string() time_string = '11' self.book_from_public_profile(date_string, time_string) # did we receive another email? messages = self.mail_stub.get_sent_messages( to=self._TEST_PATIENT_EMAIL) patient_email_count = len(messages) self.assertEqual(patient_email_count, 2) provider_messages = self.mail_stub.get_sent_messages( to=self._TEST_PROVIDER_EMAIL) provider_email_count = len(provider_messages) self.assertEqual(provider_email_count, 2)
def test_public_profile_book_no_password_returning_patient(self): self.create_provider_and_enable_booking() # book once from public profile date_string = testutil.next_monday_date_string() time_string = '10' self.book_from_public_profile(date_string, time_string) # provider should not see the booking yet, check provider bookings list, should be empty as booking is not confirmed self.login_as_provider() provider_bookings = self.testapp.get('/provider/bookings/' + self._TEST_PROVIDER_VANITY_URL) provider_bookings.mustcontain('Vous n’avez aucun rendez-vous prévu') # no email sent to provider (patient is not confirmed) messages = self.mail_stub.get_sent_messages( to=self._TEST_PROVIDER_EMAIL) self.assertEqual(0, len(messages)) self.logout_provider() self.patient_confirms_latest_booking(date_string, time_string, new_user=False) # book second time from public profile date_string = testutil.next_monday_date_string() time_string = '11' self.book_from_public_profile(date_string, time_string) self.patient_confirms_latest_booking(date_string, time_string, new_user=False)
def test_booking_45min_mid_schedule(self): ''' Test a booking for 45 minutes ''' self.create_complete_provider_profile() self.logout_provider() self.login_as_admin() # enable booking response = self.testapp.get('/admin/provider/feature/booking_enabled/' + self._TEST_PROVIDER_VANITY_URL) response.mustcontain("Show booking=True") # Monday 9-12 should be available, let's visit public profile and check response = self.testapp.get('/' + self._TEST_PROVIDER_VANITY_URL + '/book') response.mustcontain("Monday") response.mustcontain("9:00") self.logout_admin() # book once from public profile date_string = testutil.next_monday_date_string() time_string = '10' self.book_from_public_profile(date_string, time_string) # patient confirms self.patient_confirms_latest_booking(date_string, time_string) # Check that Schedule now show 10:45 as available public_profile = self.testapp.get('/' + self._TEST_PROVIDER_VANITY_URL) schedule_page = public_profile.click(linkid='book_button') schedule_page.mustcontain("9:00") schedule_page.mustcontain("10:45") schedule_page.mustcontain("11:00")
def test_booking_45min_mid_schedule(self): ''' Test a booking for 45 minutes ''' self.create_complete_provider_profile() self.logout_provider() self.login_as_admin() # enable booking response = self.testapp.get( '/admin/provider/feature/booking_enabled/' + self._TEST_PROVIDER_VANITY_URL) response.mustcontain("Show booking=True") # Monday 9-12 should be available, let's visit public profile and check response = self.testapp.get('/' + self._TEST_PROVIDER_VANITY_URL + '/book') response.mustcontain("Monday") response.mustcontain("9:00") self.logout_admin() # book once from public profile date_string = testutil.next_monday_date_string() time_string = '10' self.book_from_public_profile(date_string, time_string) # patient confirms self.patient_confirms_latest_booking(date_string, time_string) # Check that Schedule now show 10:45 as available public_profile = self.testapp.get('/' + self._TEST_PROVIDER_VANITY_URL) schedule_page = public_profile.click(linkid='book_button') schedule_page.mustcontain("9:00") schedule_page.mustcontain("10:45") schedule_page.mustcontain("11:00")
def test_booking_as_a_provider_logged_in(self): ''' Book an appointment as a provider ''' self.create_complete_provider_profile() self.logout_provider() self.login_as_admin() # enable booking response = self.testapp.get( '/admin/provider/feature/booking_enabled/' + self._TEST_PROVIDER_VANITY_URL) response.mustcontain("Show booking=True") self.logout_admin() # book an appointment for next monday at 10am with yourself (as returning patient, because already a user) self.login_as_provider() next_monday = testutil.next_weekday_date_string(0) # Book an appointment with yourself self.book_from_public_profile(next_monday, 10, self._TEST_PROVIDER_EMAIL, self._TEST_PROVIDER_TELEPHONE) # check schedule on public profile response = self.testapp.get('/' + self._TEST_PROVIDER_VANITY_URL) response.mustcontain(no=testutil.next_monday_date_string() + "/10/0") response.mustcontain(no="button-" + testutil.next_monday_date_string() + "-10-0") # check the book response = self.testapp.get('/' + self._TEST_PROVIDER_VANITY_URL + '/book') response.mustcontain(no=testutil.next_monday_date_string() + "/10/0") response.mustcontain(no="button-" + testutil.next_monday_date_string() + "-10-0") # check emails messages = self.mail_stub.get_sent_messages( to=self._TEST_PROVIDER_EMAIL) provider_email_count = len(messages) # 2 - one for the patient side and one for the provider side self.assertEqual(provider_email_count, 2) for m in messages: self.assertEqual(self._TEST_PROVIDER_EMAIL, m.to) self.assertNotIn('None', m.body.payload)
def test_booking_removed_from_public_profile_availability(self): ''' if someone forces the URL to book something outside available schedule ''' self.create_complete_provider_profile() self.logout_provider() self.login_as_admin() # enable booking response = self.testapp.get( '/admin/provider/feature/booking_enabled/' + self._TEST_PROVIDER_VANITY_URL) response.mustcontain("Show booking=True") self.logout_admin() # check it appears as available on public profile and booking page response = self.testapp.get('/' + self._TEST_PROVIDER_VANITY_URL) # book an appointment for next monday at 10am next_monday = testutil.next_weekday_date_string(0) self.book_from_public_profile(next_monday, 10, self._TEST_PATIENT_EMAIL, self._TEST_PATIENT_TELEPHONE) self.patient_confirms_latest_booking(next_monday, 10, logged_in=True) self.logout_patient() # check schedule on public profile response = self.testapp.get('/' + self._TEST_PROVIDER_VANITY_URL) response.mustcontain(no=testutil.next_monday_date_string() + "/10/0") response.mustcontain(no="button-" + testutil.next_monday_date_string() + "-10-0") # check the book response = self.testapp.get('/' + self._TEST_PROVIDER_VANITY_URL + '/book') response.mustcontain(no=testutil.next_monday_date_string() + "/10/0") response.mustcontain(no="button-" + testutil.next_monday_date_string() + "-10-0")
def test_public_profile_book_no_password_returning_patient(self): self.create_provider_and_enable_booking() # book once from public profile date_string = testutil.next_monday_date_string() time_string = '10' self.book_from_public_profile(date_string, time_string) # provider should not see the booking yet, check provider bookings list, should be empty as booking is not confirmed self.login_as_provider() provider_bookings = self.testapp.get('/provider/bookings/' + self._TEST_PROVIDER_VANITY_URL) provider_bookings.mustcontain('Vous n’avez aucun rendez-vous prévu') # no email sent to provider (patient is not confirmed) messages = self.mail_stub.get_sent_messages(to=self._TEST_PROVIDER_EMAIL) self.assertEqual(0, len(messages)) self.logout_provider() self.patient_confirms_latest_booking(date_string, time_string, new_user=False) # book second time from public profile date_string = testutil.next_monday_date_string() time_string = '11' self.book_from_public_profile(date_string, time_string) self.patient_confirms_latest_booking(date_string, time_string, new_user=False)
def test_booking_as_a_provider_logged_in(self): ''' Book an appointment as a provider ''' self.create_complete_provider_profile() self.logout_provider() self.login_as_admin() # enable booking response = self.testapp.get('/admin/provider/feature/booking_enabled/' + self._TEST_PROVIDER_VANITY_URL) response.mustcontain("Show booking=True") self.logout_admin() # book an appointment for next monday at 10am with yourself (as returning patient, because already a user) self.login_as_provider() next_monday = testutil.next_weekday_date_string(0) # Book an appointment with yourself self.book_from_public_profile(next_monday, 10, self._TEST_PROVIDER_EMAIL, self._TEST_PROVIDER_TELEPHONE) # check schedule on public profile response = self.testapp.get('/' + self._TEST_PROVIDER_VANITY_URL) response.mustcontain(no=testutil.next_monday_date_string()+"/10/0") response.mustcontain(no="button-"+testutil.next_monday_date_string()+"-10-0") # check the book response = self.testapp.get('/' + self._TEST_PROVIDER_VANITY_URL + '/book') response.mustcontain(no=testutil.next_monday_date_string()+"/10/0") response.mustcontain(no="button-"+testutil.next_monday_date_string()+"-10-0") # check emails messages = self.mail_stub.get_sent_messages(to=self._TEST_PROVIDER_EMAIL) provider_email_count = len(messages) # 2 - one for the patient side and one for the provider side self.assertEqual(provider_email_count, 2) for m in messages: self.assertEqual(self._TEST_PROVIDER_EMAIL, m.to) self.assertNotIn('None', m.body.payload)
def check_appointment_email_to_provider(self, date_string, time_string, provider_email=_TEST_PROVIDER_EMAIL): # Check email to provider messages = self.mail_stub.get_sent_messages(to=provider_email) provider_mail_count = len(messages) # get last email sent provider_mail = messages[provider_mail_count - 1] self.assertEquals(provider_mail.subject, 'Veosan - New Appointment with Pat Patient') self.assertIn('You have a new appointment!', provider_mail.body.payload) # check status change in all lists (provider, patient and admin dashboards) self.login_as_provider() provider_bookings = self.testapp.get('/provider/bookings/' + self._TEST_PROVIDER_VANITY_URL) provider_bookings.mustcontain('Pat Patient') # check datetime booking_datetime = datetime.strptime(testutil.next_monday_date_string() + " " + str(time_string), '%Y-%m-%d %H') french_datetime_string = format_datetime(booking_datetime, "EEEE 'le' d MMMM yyyy", locale='fr_CA') + " à " + format_datetime(booking_datetime, "H:mm", locale='fr_CA') provider_bookings.mustcontain(french_datetime_string) self.logout_provider()
def patient_confirms_latest_booking(self, date_string, time_string, new_user=True, logged_in=False): # check email to patient booking_datetime = datetime.strptime(testutil.next_monday_date_string() + " " + str(time_string), '%Y-%m-%d %H') french_datetime_string = format_datetime(booking_datetime, "EEEE 'le' d MMMM yyyy", locale='fr_CA') + " à " + format_datetime(booking_datetime, "H:mm", locale='fr_CA') english_datetime_string = format_datetime(booking_datetime, "EEEE d MMMM yyyy", locale='en') + " at " + format_datetime(booking_datetime, "H:mm", locale='en') booking_datetime = datetime.strptime(testutil.next_monday_date_string(), '%Y-%m-%d') booking_datetime_string = format_date(booking_datetime, format="d MMM yyyy", locale='fr_CA') booking_time = datetime.strptime(str(time_string), '%H') booking_time_string = format_time(booking_time, format="short", locale='fr') logging.info('French date time of booking: %s' % french_datetime_string) # check that confirmation emails was sent to patient messages = self.mail_stub.get_sent_messages(to=self._TEST_PATIENT_EMAIL) patient_email_count = len(messages) # get last email sent m = messages[patient_email_count - 1] self.assertEqual(self._TEST_PATIENT_EMAIL, m.to) # activate account messages = self.mail_stub.get_sent_messages(to=self._TEST_PATIENT_EMAIL) self.assertEquals(m.subject, 'Veosan Appointment - Osteopath') user = db.get_user_from_email(self._TEST_PATIENT_EMAIL) # check email content self.assertIn('Hi', m.body.payload) self.assertIn('Thank you', m.body.payload) self.assertIn(english_datetime_string, m.body.payload) self.assertNotIn('None', m.body.payload) patient = db.get_patient_from_user(user) bookings = db.get_bookings_for_patient(patient) booking = bookings[0] if new_user: self.assertTrue('/login/booking/%s' % booking.key.urlsafe() in m.body.payload) response = self.testapp.get('/') is_french = 'Déconnexion' in response is_english = 'Logout' in response user_logged_in = False if is_english: user_logged_in = 'Logout' in response elif is_french: user_logged_in = 'Déconnexion' in response # click the link response = self.testapp.get('/login/booking/%s' % booking.key.urlsafe()) # is user logged in? if not user_logged_in: if is_english: response.mustcontain("Login to Veosan") elif is_french: response.mustcontain("Connexion à Veosan") login_form = response.forms['login_form'] login_form['password'] = self._TEST_PATIENT_PASSWORD response = login_form.submit().follow() else: response = response.follow() response.mustcontain("Upcoming Appointments") response.mustcontain('Fantastic Fox') #response.mustcontain(booking_time_string) response.mustcontain(english_datetime_string) # patient email in navbar response.mustcontain(self._TEST_PATIENT_EMAIL) response.mustcontain('Logout')