def test_appointment_cancelled_by_practitioner_unbooked(self):
     user = User.objects.create_user(username='******',
                                     password='******',
                                     first_name="Robert",
                                     last_name="Greener",
                                     email="*****@*****.**")
     user.save()
     practitioner = Practitioner(user=user,
                                 mobile="+447476605233",
                                 bio="ABC",
                                 address_line_1="XXX",
                                 address_line_2="XXXXX",
                                 is_approved=True)
     practitioner.save()
     appointment = Appointment(practitioner=practitioner,
                               patient=None,
                               start_date_and_time=datetime(year=2018,
                                                            month=4,
                                                            day=17,
                                                            hour=15,
                                                            minute=10),
                               length=timedelta(hours=1))
     appointment.save()
     appointment_cancelled_by_practitioner(appointment)
     self.assertEqual(len(mail.outbox), 1)
예제 #2
0
 def test__str__(self):
     u = User(first_name="John", last_name="Smith")
     u.save()
     practitioner = Practitioner(user=u,
                                 address_line_1="My home",
                                 postcode="EC12 1CV",
                                 mobile="+447577293232",
                                 bio="Hello")
     practitioner.save()
     self.assertEqual(str(practitioner), 'John Smith')
예제 #3
0
 def test_edit_fields(self):
     user = User.objects.create_user(username='******',
                                     password='******',
                                     first_name='John',
                                     last_name='Smith'
                                     )
     practitioner = Practitioner(user=user,
                                 address_line_1='19 Langham Gardens',
                                 address_line_2='Ealing',
                                 postcode='W13 8PZ',
                                 mobile='+447476565333',
                                 bio='text'
                                 )
     practitioner.save()
     practitioner = PractitionerForm(instance=user.practitioner, data={
         'first_name': 'John',
         'last_name': 'Smith',
         'email': '*****@*****.**',
         'mobile': '+447075593323',
         'address_line_1': '39 buckingham Avenue',
         'address_line_2': 'Ealing',
         'postcode': 'UB6 7RD',
         'bio': 'more text'
     })
     practitioner.save()
     self.assertTrue(practitioner.is_valid())
     self.assertEqual(str(user.practitioner.mobile), '+447075593323')
     self.assertEqual(str(user.practitioner.address_line_1), '39 buckingham Avenue')
     self.assertEqual(str(user.practitioner.postcode), 'UB6 7RD')
     self.assertEqual(str(user.practitioner.bio), 'more text')
예제 #4
0
    def test_mark_approved(self):
        u = User(first_name="John", last_name="Smith")
        u.save()
        practitioner = Practitioner(user=u,
                                    address_line_1="My home",
                                    postcode="EC12 1CV",
                                    mobile="+447577293232",
                                    bio="Hello")
        practitioner.save()
        PractitionerAdmin.mark_approved(None, None, Practitioner.objects.all())
        self.assertEqual(len(Practitioner.objects.filter(is_approved=False)),
                         0)

        self.assertEqual(len(Practitioner.objects.filter(is_approved=True)), 1)
 def form_valid(self, form):
     user = form.save(commit=False)
     user.username = user.email
     user.save()
     practitioner = Practitioner(
         user=user,
         address_line_1=form.cleaned_data['address_line_1'],
         address_line_2=form.cleaned_data['address_line_2'],
         postcode=form.cleaned_data['postcode'],
         mobile=form.cleaned_data['mobile'],
         bio=form.cleaned_data['bio'])
     practitioner.save()
     send_practitioner_confirm_email(practitioner,
                                     get_current_site(self.request))
     return super().form_valid(form)
 def test_send_practitioner_email_confirmed(self):
     user = User.objects.create_user(username='******',
                                     password='******',
                                     first_name="Robert",
                                     last_name="Greener",
                                     email="*****@*****.**")
     user.save()
     practitioner = Practitioner(user=user,
                                 mobile="+44848482732",
                                 bio="ABC",
                                 address_line_1="XXX",
                                 address_line_2="XXXXX",
                                 is_approved=True)
     practitioner.save()
     send_practitioner_email_confirmed(practitioner)
     self.assertEqual(len(mail.outbox), 1)
    def test_multiple_appointments_booked(self):
        user = User.objects.create_user(username='******',
                                        password='******',
                                        first_name="Robert",
                                        last_name="Greener",
                                        email="*****@*****.**")
        user.save()
        practitioner = Practitioner(user=user,
                                    mobile="+447476605233",
                                    bio="ABC",
                                    address_line_1="XXX",
                                    address_line_2="XXXXX",
                                    is_approved=True)
        practitioner.save()

        user2 = User.objects.create_user(username='******',
                                         password='******',
                                         first_name="Woof",
                                         last_name="Meow",
                                         email="*****@*****.**")
        user2.save()
        patient = Patient(user=user2,
                          gender='M',
                          mobile="+447476605233",
                          date_of_birth=date(year=1995, month=1, day=1))
        patient.save()
        appointment1 = Appointment(practitioner=practitioner,
                                   patient=patient,
                                   start_date_and_time=datetime(year=2018,
                                                                month=4,
                                                                day=17,
                                                                hour=15,
                                                                minute=10),
                                   length=timedelta(hours=1))
        appointment1.save()
        appointment2 = Appointment(practitioner=practitioner,
                                   patient=patient,
                                   start_date_and_time=datetime(year=2018,
                                                                month=4,
                                                                day=19,
                                                                hour=15,
                                                                minute=10),
                                   length=timedelta(hours=1))
        appointment2.save()
        multiple_appointments_booked((appointment1, appointment2))
        self.assertEqual(len(mail.outbox), 4)
예제 #8
0
 def test_when_practitioner_exists_and_valid(self):
     user = User.objects.create_user(username='******',
                                     password='******'
                                     )
     practitioner = Practitioner(user=user,
                                 mobile="+44848482732",
                                 email_confirmed=True,
                                 bio="ABC",
                                 address_line_1="XXX",
                                 address_line_2="XXXXX",
                                 is_approved=True
                                 )
     practitioner.save()
     form = PractitionerLoginForm(data={
         'username': '******',
         'password': '******'
     })
     self.assertTrue(form.is_valid())
예제 #9
0
 def test_get_user_first_name(self):
     user = User(first_name="John", last_name="Smith")
     user.save()
     practitioner = Practitioner(user=user,
                                 address_line_1="My home",
                                 postcode="EC12 1CV",
                                 mobile="+447577293232",
                                 bio="Hello")
     self.assertEqual(PractitionerAdmin.get_user_first_name(practitioner),
                      'John')
    def test_send_practitioner_reminders(self):
        user = User.objects.create_user(username='******',
                                        password='******',
                                        first_name="Robert",
                                        last_name="Greener",
                                        email="*****@*****.**"
                                        )
        user.save()
        practitioner = Practitioner(user=user,
                                    mobile="+447476605233",
                                    bio="ABC",
                                    address_line_1="XXX",
                                    address_line_2="XXXXX",
                                    is_approved=True
                                    )
        practitioner.save()

        user2 = User.objects.create_user(username='******',
                                         password='******',
                                         first_name="Woof",
                                         last_name="Meow",
                                         email="*****@*****.**"
                                         )
        user2.save()
        patient = Patient(user=user2,
                          gender='M',
                          mobile="+447476605233",
                          date_of_birth=date(year=1995, month=1, day=1))
        patient.save()
        appointment1 = Appointment(practitioner=practitioner,
                                   patient=patient,
                                   start_date_and_time=timezone.now(),
                                   length=timedelta(hours=1))
        appointment1.save()

        appointment2 = Appointment(practitioner=practitioner,
                                   patient=patient,
                                   start_date_and_time=timezone.now(),
                                   length=timedelta(minutes=30))
        appointment2.save()

        send_practitioner_appointment_reminders()
예제 #11
0
    def test__str__(self):
        u = User(first_name="John", last_name="Smith")
        u.save()
        practitioner = Practitioner(user=u,
                                    address_line_1="My home",
                                    postcode="EC12 1CV",
                                    mobile="+447577293232",
                                    bio="Hello")
        practitioner.save()

        appointment = Appointment(practitioner=practitioner,
                                  start_date_and_time=datetime(year=2018,
                                                               month=3,
                                                               day=2,
                                                               hour=15,
                                                               minute=16),
                                  length=timedelta(hours=1))
        appointment.save()
        self.assertEqual(str(appointment),
                         'John Smith - 2018-03-02 15:16:00 for 1:00:00')
    def test_when_valid_practitioner(self):
        user = User.objects.create_user(username='******',
                                        password='******'
                                        )
        user.save()
        practitioner = Practitioner(user=user,
                                    mobile="+447476605233",
                                    bio="ABC",
                                    address_line_1="XXX",
                                    address_line_2="XXXXX",
                                    is_approved=False
                                    )
        practitioner.save()

        uidb64 = urlsafe_base64_encode(force_bytes(practitioner.user.id))
        token = account_activation_token.make_token(practitioner.user)
        request = self.factory.get('/activate/{0}/{1}'.format(uidb64, token))
        middleware = SessionMiddleware()
        middleware.process_request(request)
        request.session.save()
        request.user = AnonymousUser()
        response = activate(request, uidb64, token)
        self.assertEqual(request.user, user)
        practitioner.refresh_from_db()
        self.assertTrue(practitioner.email_confirmed)
    def test_send_patient_practitioner_has_cancelled(self):
        user = User.objects.create_user(username='******',
                                        password='******',
                                        first_name="Robert",
                                        last_name="Greener",
                                        email="*****@*****.**")
        user.save()
        practitioner = Practitioner(user=user,
                                    mobile="+44848482732",
                                    bio="ABC",
                                    address_line_1="XXX",
                                    address_line_2="XXXXX",
                                    is_approved=True)
        practitioner.save()

        user2 = User.objects.create_user(username='******',
                                         password='******',
                                         first_name="Woof",
                                         last_name="Meow",
                                         email="*****@*****.**")
        user2.save()
        patient = Patient(user=user2,
                          gender='M',
                          mobile="+447476666555",
                          date_of_birth=date(year=1995, month=1, day=1))
        patient.save()
        appointment = Appointment(practitioner=practitioner,
                                  patient=patient,
                                  start_date_and_time=datetime(year=2018,
                                                               month=4,
                                                               day=17,
                                                               hour=15,
                                                               minute=10),
                                  length=timedelta(hours=1))
        appointment.save()
        send_patient_practitioner_has_cancelled(appointment)
        send_patient_practitioner_has_cancelled(appointment, "Hello")
        self.assertEqual(len(mail.outbox), 2)
예제 #14
0
    def test_is_live_when_too_early(self):
        u = User(first_name="John", last_name="Smith")
        u.save()
        patient = Patient(user=u,
                          gender='M',
                          mobile="+447476666555",
                          date_of_birth=date(year=1995, month=1, day=1))

        patient.save()

        practitioner = Practitioner(user=u,
                                    address_line_1="My home",
                                    postcode="EC12 1CV",
                                    mobile="+447577293232",
                                    bio="Hello")
        practitioner.save()

        appointment = Appointment(practitioner=practitioner,
                                  patient=patient,
                                  start_date_and_time=timezone.now() +
                                  timedelta(minutes=10),
                                  length=timedelta(hours=1))
        appointment.save()
        self.assertFalse(appointment.is_live())
예제 #15
0
 def test_edit_email(self):
     user = User.objects.create_user(username='******',
                                     password='******',
                                     first_name='John',
                                     last_name='Smith'
                                     )
     practitioner = Practitioner(user=user,
                                 address_line_1='19 Langham Gardens',
                                 address_line_2='ealing',
                                 postcode='W13 8PZ',
                                 mobile='+447476565333',
                                 bio='text',
                                 is_approved=True
                                 )
     practitioner.save()
     practitioner = PractitionerUserForm(instance=user, data={
         'first_name': 'John',
         'last_name': 'Smith',
         'email': '*****@*****.**',
     })
     practitioner.save()
     self.assertTrue(practitioner.is_valid())
     self.assertEqual(str(user.email), '*****@*****.**')