Example #1
0
    def test_edit_email(self):
        user = User.objects.create_user(username='******',
                                        password='******',
                                        first_name='John',
                                        last_name='Smith')
        patient = Patient(user=user,
                          date_of_birth=date(year=1995, month=2, day=20),
                          gender='M',
                          mobile='+447476565333')
        patient.save()

        patient = PatientUserForm(instance=user,
                                  data={
                                      'first_name':
                                      'John',
                                      'last_name':
                                      'Smith',
                                      'gender':
                                      'M',
                                      'date_of_birth':
                                      date(year=1995, month=2, day=20),
                                      'email':
                                      '*****@*****.**',
                                      'mobile':
                                      '+447476565333',
                                  })
        patient.save()
        self.assertTrue(patient.is_valid())
        self.assertEqual(str(user.email), '*****@*****.**')
Example #2
0
 def test__str__(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()
     self.assertEqual(str(patient), 'John Smith')
    def setUp(self):
        # Create two users
        test_user_1 = User.objects.create_user(username='******',
                                               email="*****@*****.**")
        test_user_1.set_password('12345')
        test_user_1.save()

        test_pat_1 = Patient(user=test_user_1,
                             email_confirmed=True,
                             gender='M',
                             mobile="+447476666555",
                             date_of_birth=date(year=1995, month=1, day=1))
        test_pat_1.save()

        test_user_2 = User.objects.create_user(username='******',
                                               email="*****@*****.**")
        test_user_2.set_password('12345')
        test_user_2.save()

        test_pat_2 = Patient(user=test_user_2,
                             email_confirmed=False,
                             gender='M',
                             mobile="+447476666555",
                             date_of_birth=date(year=1995, month=1, day=1))
        test_pat_2.save()

        # create 2 test practitioners
        test_user_3 = User.objects.create_user(username='******',
                                               email="*****@*****.**")
        test_user_3.set_password('12345')

        test_user_3.save()

        test_prac_1 = Practitioner(user=test_user_3,
                                   email_confirmed=True,
                                   address_line_1="My home",
                                   postcode="EC12 1CV",
                                   mobile="+447577293232",
                                   bio="Hello")
        test_prac_1.save()

        test_user_4 = User.objects.create_user(username='******',
                                               email="*****@*****.**")
        test_user_4.set_password('12345')

        test_user_4.save()

        test_prac_2 = Practitioner(user=test_user_4,
                                   email_confirmed=False,
                                   address_line_1="My home",
                                   postcode="EC12 1CV",
                                   mobile="+447577293232",
                                   bio="Hello")
        test_prac_2.save()
 def form_valid(self, form):
     user = form.save(commit=False)
     user.username = user.email
     user.save()
     patient = Patient(user=user,
                       date_of_birth=form.cleaned_data['date_of_birth'],
                       gender=form.cleaned_data['gender'],
                       mobile=form.cleaned_data['mobile']
                       )
     patient.save()
     send_patient_confirm_email(patient, get_current_site(self.request))
     return super().form_valid(form)
 def test_send_email_confirmed(self):
     user = User.objects.create_user(username='******',
                                     password='******',
                                     first_name="Woof",
                                     last_name="Meow",
                                     email="*****@*****.**")
     user.save()
     patient = Patient(user=user,
                       gender='M',
                       mobile="+447476666555",
                       date_of_birth=date(year=1995, month=1, day=1))
     patient.save()
     send_patient_email_confirmed(patient)
     self.assertEqual(len(mail.outbox), 1)
Example #6
0
 def test_when_patient_valid_and_valid_butemail_not_confirmed(self):
     user = User.objects.create_user(username='******',
                                     password='******')
     patient = Patient(user=user,
                       date_of_birth=date(year=1995, month=2, day=20),
                       gender='M',
                       mobile='+447476565333',
                       email_confirmed=False)
     patient.save()
     form = PatientLoginForm(data={
         'username': '******',
         'password': '******'
     })
     self.assertFalse(form.is_valid())
    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)
    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()
    def test_when_valid_patient(self):
        user = User.objects.create_user(username='******',
                                        password='******'
                                        )
        user.save()
        patient = Patient(user=user,
                          gender='M',
                          mobile="+447476666555",
                          date_of_birth=date(year=1995, month=1, day=1))
        patient.save()

        uidb64 = urlsafe_base64_encode(force_bytes(patient.user.id))
        token = account_activation_token.make_token(patient.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)
        patient.refresh_from_db()
        self.assertTrue(patient.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)
Example #11
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())