Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- e
- from django.core.urlresolvers import reverse
- from .models import GreenspaceUser, Patient, Therapist, Clinic
- from .forms import (ModifyProfilePatientForm,
- ModifyProfileTherapistForm,
- ModifyProfileClinicForm,
- SecurityQuestionUpdateForm,
- CompleteProfileClinicForm,
- CompleteProfileTherapistForm,
- CompleteProfilePatientForm,
- CompleteProfilePatientWithTherapistForm)
- PATIENT_EMAIL = "patient@grnspace.co"
- PATIENT_FIRST_NAME = "Elon"
- PATIENT_LAST_NAME = "Musk"
- PATIENT_PASSWORD = "password"
- PATIENT_SECRET_ANSWER = "some answer"
- THERAPIST_EMAIL = "therapist@grnspace.co"
- THERAPIST_FIRST_NAME = "Steve"
- THERAPIST_LAST_NAME = "Jobs"
- THERAPIST_PASSWORD = "password"
- THERAPIST_SECRET_ANSWER = "some answer"
- CLINIC_EMAIL = "clinic@grnspace.co"
- CLINIC_FIRST_NAME = "Better"
- CLINIC_LAST_NAME = "Clinic"
- CLINIC_PASSWORD = "password"
- CLINIC_SECRET_ANSWER = "some answer"
- class TestViews(TestCase):
- def setUp(self):
- # Set up patient and therapist user accounts
- patient_user = GreenspaceUser.objects.create_user(
- PATIENT_EMAIL, PATIENT_FIRST_NAME, PATIENT_LAST_NAME, PATIENT_PASSWORD,
- user_type = GreenspaceUser.USER_TYPE_PATIENT)
- self._patient = Patient.objects.create(user=patient_user, secret_answer=PATIENT_SECRET_ANSWER)
- therapist_user = GreenspaceUser.objects.create_user(
- THERAPIST_EMAIL, THERAPIST_FIRST_NAME, THERAPIST_LAST_NAME, THERAPIST_PASSWORD,
- user_type = GreenspaceUser.USER_TYPE_THERAPIST)
- self._therapist = Therapist.objects.create(user=therapist_user, secret_answer=THERAPIST_SECRET_ANSWER)
- clinic_user = GreenspaceUser.objects.create_user(
- CLINIC_EMAIL, CLINIC_FIRST_NAME, CLINIC_LAST_NAME, CLINIC_PASSWORD,
- user_type = GreenspaceUser.USER_TYPE_CLINIC)
- self._clinic = Clinic.objects.create(user=clinic_user, secret_answer=CLINIC_SECRET_ANSWER)
- self._patient.therapist = self._therapist
- self._patient.save()
- self._therapist.clinic = self._clinic
- self._therapist.save()
- def tearDown(self):
- self.client.logout()
- # Method used to store a variable number of patients and therapists inside a clinic
- def addToClinic(self, amount):
- for i in range(amount):
- NEXT_THERAPIST_EMAIL = str(i) + "therapist@grnspace.co" # concatenate to avoid duplicates
- NEXT_THERAPIST_FIRST_NAME = chr(i + ord('A')) + "Richard" # concatenate for ordering when paginated
- NEXT_THERAPIST_LAST_NAME = chr(i + ord('A')) + "Hendricks" # concatenate for ordering when paginated
- NEXT_THERAPIST_PASSWORD = "password"
- NEXT_THERAPIST_SECRET_ANSWER = "some answer"
- NEXT_PATIENT_EMAIL = str(i) + "patient@grnspace.co"
- NEXT_PATIENT_FIRST_NAME = chr(i + ord('A')) + "Erlich"
- NEXT_PATIENT_LAST_NAME = chr(i + ord('A')) + "Bachmann"
- NEXT_PATIENT_PASSWORD = "password"
- NEXT_PATIENT_SECRET_ANSWER = "some answer"
- next_therapist_user = GreenspaceUser.objects.create_user(
- NEXT_THERAPIST_EMAIL, NEXT_THERAPIST_FIRST_NAME, NEXT_THERAPIST_LAST_NAME, NEXT_THERAPIST_PASSWORD,
- user_type = GreenspaceUser.USER_TYPE_THERAPIST)
- self.next_therapist = Therapist.objects.create(user=next_therapist_user, secret_answer=NEXT_THERAPIST_SECRET_ANSWER)
- next_patient_user = GreenspaceUser.objects.create_user(
- NEXT_PATIENT_EMAIL, NEXT_PATIENT_FIRST_NAME, NEXT_PATIENT_LAST_NAME, NEXT_PATIENT_PASSWORD,
- user_type = GreenspaceUser.USER_TYPE_PATIENT)
- self.next_patient = Patient.objects.create(user=next_patient_user, secret_answer=NEXT_PATIENT_SECRET_ANSWER)
- self.next_patient.therapist = self.next_therapist
- self.next_patient.save()
- self.next_therapist.clinic = self._clinic
- self.next_therapist.save()
- def test_profile_detail_view_no_auth(self):
- response = self.client.get(reverse("profile"))
- self.assertEqual(response.status_code, 302)
- self.assertRedirects(response, '/login/?next=/accounts/profile/')
- def test_profile_detail_view_patient_incomplete_profile(self):
- self.client.force_login(self._patient.user)
- response = self.client.get(reverse("profile"))
- self.assertEqual(response.status_code, 302)
- self.assertRedirects(response, '/complete_profile/', target_status_code=302)
- def test_profile_detail_view_patient(self):
- self._patient.profile_completed = True
- self._patient.save()
- self.client.force_login(self._patient.user)
- response = self.client.get(reverse("profile"))
- self.assertEqual(response.status_code, 200)
- self.assertTemplateUsed(template_name='profile/detail_patient.html')
- self.assertEqual(response.context['profile'], self._patient)
- def test_profile_detail_view_therapist_incomplete_profile(self):
- self.client.force_login(self._therapist.user)
- response = self.client.get(reverse("profile"))
- self.assertEqual(response.status_code, 302)
- self.assertRedirects(response, '/complete_profile/', target_status_code=302)
- def test_profile_detail_view_therapist(self):
- self._therapist.profile_completed = True
- self._therapist.save()
- self.client.force_login(self._therapist.user)
- response = self.client.get(reverse("profile"))
- self.assertEqual(response.status_code, 200)
- self.assertTemplateUsed(template_name='profile/detail_therapist.html')
- self.assertEqual(response.context['profile'], self._therapist)
- def test_profile_detail_view_clinic_incomplete_profile(self):
- self.client.force_login(self._clinic.user)
- response = self.client.get(reverse("profile"))
- self.assertEqual(response.status_code, 302)
- self.assertRedirects(response, '/complete_profile/', target_status_code=302)
- def test_profile_detail_view_clinic(self):
- self._clinic.profile_completed = True
- self._clinic.save()
- self.client.force_login(self._clinic.user)
- response = self.client.get(reverse("profile"))
- self.assertEqual(response.status_code, 200)
- self.assertTemplateUsed(template_name='profile/detail_clinic.html')
- self.assertEqual(response.context['profile'], self._clinic)
- def test_modify_profile_patient_view_no_auth(self):
- response = self.client.get(reverse("modify_profile_patient"))
- self.assertEqual(response.status_code, 302)
- self.assertRedirects(response, '/login/?next=/accounts/modify_profile/')
- def test_modify_profile_patient_view(self):
- self._patient.profile_completed = True
- self._patient.save()
- self.client.force_login(self._patient.user)
- response = self.client.get(reverse("modify_profile_patient"))
- # GET request
- self.assertEqual(response.status_code, 200)
- self.assertTemplateUsed(template_name='profile/modify.html')
- self.assertIsInstance(response.context["form"], ModifyProfilePatientForm)
- # POST request with no data
- response = self.client.post(reverse("modify_profile_patient"), {})
- self.assertEqual(response.status_code, 200)
- self.assertContains(response, "This field is required.")
- # POST request with data
- response = self.client.post(reverse("modify_profile_patient"),
- {
- "phone": "416-123-4567",
- "year_of_birth": "1980",
- "gender": "F",
- "profession": "Manufacturing",
- "mobile_phone": "1-416-123-4567",
- "sms_pref": "True"
- })
- self.assertEqual(response.status_code, 302)
- self.assertRedirects(response, '/accounts/profile/')
- def test_modify_profile_therapist_view(self):
- self._therapist.profile_completed = True
- self._therapist.save()
- self.client.force_login(self._therapist.user)
- # GET request
- response = self.client.get(reverse("modify_profile_therapist"))
- self.assertEqual(response.status_code, 200)
- self.assertTemplateUsed(template_name='profile/modify.html')
- self.assertIsInstance(response.context["form"], ModifyProfileTherapistForm)
- self.assertContains(response, "Name to show patients")
- # POST request with no data
- response = self.client.post(reverse("modify_profile_therapist"), {})
- self.assertEqual(response.status_code, 200)
- self.assertContains(response, "This field is required.")
- # POST request with data
- response = self.client.post(reverse("modify_profile_therapist"),
- {
- "display_name": "Display Name",
- "phone": "416-123-4567",
- "address_line_1": "123 Yonge St",
- "address_line_2": "Unit 111",
- "address_city": "Toronto",
- "address_province": "ON",
- "therapist_type": "PSYCHIATRIST",
- "province_of_registration": "ON",
- "regulatory_body":"abc",
- "registration_number": "666",
- })
- self.assertEqual(response.status_code, 302)
- self.assertRedirects(response, '/accounts/profile/')
- def test_modify_profile_clinic_view(self):
- self._clinic.profile_completed = True
- self._clinic.save()
- self.client.force_login(self._clinic.user)
- # GET request
- response = self.client.get(reverse("modify_profile_clinic"))
- self.assertEqual(response.status_code, 200)
- self.assertTemplateUsed(template_name='profile/modify.html')
- self.assertIsInstance(response.context["form"], ModifyProfileClinicForm)
- self.assertContains(response, "Clinic name")
- # POST request with no data
- response = self.client.post(reverse("modify_profile_clinic"), {})
- self.assertEqual(response.status_code, 200)
- self.assertContains(response, "This field is required.")
- # POST request with data
- response = self.client.post(reverse("modify_profile_clinic"),
- {
- "display_name": "Display Name",
- "phone": "416-123-4567",
- "address_line_1": "123 Yonge St",
- "address_line_2": "Unit 111",
- "address_city": "Toronto",
- "address_province": "ON",
- "therapist_type_other": "Other type"
- })
- self.assertEqual(response.status_code, 302)
- self.assertRedirects(response, '/accounts/profile/')
- def test_change_security_question_view_no_auth(self):
- response = self.client.get(reverse("security_question_change"))
- self.assertEqual(response.status_code, 302)
- self.assertRedirects(response, '/login/?next=/accounts/security_question_change/')
- def test_change_security_question_view_patient(self):
- self._patient.profile_completed = True
- self._patient.save()
- self.client.force_login(self._patient.user)
- # GET request
- response = self.client.get(reverse("security_question_change"))
- self.assertEqual(response.status_code, 200)
- self.assertTemplateUsed(template_name='profile/modify_security_question.html')
- self.assertIsInstance(response.context["form"], SecurityQuestionUpdateForm)
- self.assertContains(response, "Change your security question")
- # POST request with no data
- response = self.client.post(reverse("security_question_change"), {})
- self.assertEqual(response.status_code, 200)
- self.assertContains(response, "This field is required.")
- # POST request with data
- response = self.client.post(reverse("security_question_change"),
- {
- "answer": PATIENT_SECRET_ANSWER,
- "new_security_question": "COUSIN",
- "new_answer1": "New answer",
- "new_answer2": "New answer",
- })
- self.assertEqual(response.status_code, 302)
- self.assertRedirects(response, '/accounts/profile/')
- def test_change_security_question_view_therapist(self):
- self._therapist.profile_completed = True
- self._therapist.save()
- self.client.force_login(self._therapist.user)
- # GET request
- response = self.client.get(reverse("security_question_change"))
- self.assertEqual(response.status_code, 200)
- self.assertTemplateUsed(template_name='profile/modify_security_question.html')
- self.assertIsInstance(response.context["form"], SecurityQuestionUpdateForm)
- self.assertContains(response, "Change your security question")
- # POST request with no data
- response = self.client.post(reverse("security_question_change"), {})
- self.assertEqual(response.status_code, 200)
- self.assertContains(response, "This field is required.")
- # POST request with data
- response = self.client.post(reverse("security_question_change"),
- {
- "answer": THERAPIST_SECRET_ANSWER,
- "new_security_question": "COUSIN",
- "new_answer1": "New answer",
- "new_answer2": "New answer",
- })
- self.assertEqual(response.status_code, 302)
- self.assertRedirects(response, '/accounts/profile/')
- def test_change_security_question_view_clinic(self):
- self._clinic.profile_completed = True
- self._clinic.save()
- self.client.force_login(self._clinic.user)
- # GET request
- response = self.client.get(reverse("security_question_change"))
- self.assertEqual(response.status_code, 200)
- self.assertTemplateUsed(template_name='profile/modify_security_question.html')
- self.assertIsInstance(response.context["form"], SecurityQuestionUpdateForm)
- self.assertContains(response, "Change your security question")
- # POST request with no data
- response = self.client.post(reverse("security_question_change"), {})
- self.assertEqual(response.status_code, 200)
- self.assertContains(response, "This field is required.")
- # POST request with data
- response = self.client.post(reverse("security_question_change"),
- {
- "answer": CLINIC_SECRET_ANSWER,
- "new_security_question": "COUSIN",
- "new_answer1": "New answer",
- "new_answer2": "New answer",
- })
- self.assertEqual(response.status_code, 302)
- self.assertRedirects(response, '/accounts/profile/')
- def test_complete_profile_patient_view_no_auth(self):
- response = self.client.get(reverse("profile_completion_patient"))
- self.assertEqual(response.status_code, 302)
- self.assertRedirects(response, '/login/?next=/accounts/complete_my_profile/')
- def test_complete_profile_patient_view(self):
- self.client.force_login(self._patient.user)
- # GET request
- response = self.client.get(reverse("profile_completion_patient"))
- self.assertEqual(response.status_code, 200)
- self.assertTemplateUsed(template_name='profile/complete_patient_without_therapist.html')
- self.assertIsInstance(response.context["form"], CompleteProfilePatientForm)
- self.assertContains(response, "Complete your registration")
- # POST request with no data
- response = self.client.post(reverse("profile_completion_patient"), {})
- self.assertEqual(response.status_code, 200)
- self.assertContains(response, "This field is required.")
- # POST request with data
- response = self.client.post(reverse("profile_completion_patient"),
- {
- "gender": "F",
- "profession": "Manufacturing",
- "phone": "416-123-4567",
- "therapist_name": "Doctor Doc",
- "therapist_phone": "416-537-5592",
- "diagnosed_in_past_bool": "F",
- "diagnosed_before_year_bool": "F",
- "therapy_in_past_bool": "F",
- "therapy_in_past_utility": "F",
- "secret_question": "MOTHER",
- "secret_answer": "abcde",
- })
- self.assertEqual(response.status_code, 302)
- self.assertRedirects(response, '/after_login/', target_status_code=302)
- def test_complete_profile_patient_with_therapist_view_no_auth(self):
- response = self.client.get(reverse("profile_completion_patient_with_therapist"))
- self.assertEqual(response.status_code, 302)
- self.assertRedirects(response, '/login/?next=/accounts/complete_profile/')
- def test_complete_profile_patient_with_therapist_view(self):
- self.client.force_login(self._patient.user)
- # GET request
- response = self.client.get(reverse("profile_completion_patient_with_therapist"))
- self.assertEqual(response.status_code, 200)
- self.assertTemplateUsed(template_name='profile/complete_patient.html')
- self.assertIsInstance(response.context["form"], CompleteProfilePatientWithTherapistForm)
- self.assertContains(response, "Complete your registration")
- # POST request with no data
- response = self.client.post(reverse("profile_completion_patient_with_therapist"), {})
- self.assertEqual(response.status_code, 200)
- self.assertContains(response, "This field is required.")
- response = self.client.post(reverse("profile_completion_patient_with_therapist"),
- {
- "gender": "F",
- "profession": "Manufacturing",
- "phone": "416-123-4567",
- "diagnosed_in_past_bool": "F",
- "diagnosed_before_year_bool": "F",
- "therapy_in_past_bool": "F",
- "therapy_in_past_utility": "F",
- "secret_question": "MOTHER",
- "secret_answer": "abcde",
- })
- self.assertEqual(response.status_code, 302)
- self.assertRedirects(response, '/after_login/', target_status_code=302)
- def test_complete_profile_therapist_view_no_auth(self):
- response = self.client.get(reverse("profile_completion_therapist"))
- self.assertEqual(response.status_code, 302)
- self.assertRedirects(response, '/login/?next=/accounts/complete_therapist_profile/')
- def test_complete_profile_therapist_view(self):
- self.client.force_login(self._therapist.user)
- # GET request
- response = self.client.get(reverse("profile_completion_therapist"))
- self.assertEqual(response.status_code, 200)
- self.assertTemplateUsed(template_name='profile/complete_therapist.html')
- self.assertIsInstance(response.context["form"], CompleteProfileTherapistForm)
- self.assertContains(response, "Complete your registration")
- # POST request with no data
- response = self.client.post(reverse("profile_completion_therapist"), {})
- self.assertEqual(response.status_code, 200)
- self.assertContains(response, "This field is required.")
- # POST request with data
- response = self.client.post(reverse("profile_completion_therapist"),
- {
- "display_name": "Therapist name",
- "phone": "1416-123-4567",
- "address_line_1": "Address",
- "address_line_2": "Address",
- "address_city": "Toronto",
- "address_province": "ON",
- "therapist_type": "SOCIAL_WORKER",
- "province_of_registration": "ON",
- "regulatory_body":"abc",
- "registration_number": "666",
- "secret_question": "MOTHER",
- "secret_answer": "abcde",
- })
- self.assertEqual(response.status_code, 302)
- self.assertRedirects(response, '/after_login/', target_status_code=302)
- def test_complete_profile_clinic_view_no_auth(self):
- response = self.client.get(reverse("profile_completion_clinic"))
- self.assertEqual(response.status_code, 302)
- self.assertRedirects(response, '/login/?next=/accounts/complete_clinic_profile/')
- def test_complete_profile_clinic_view(self):
- self.client.force_login(self._clinic.user)
- # GET request
- response = self.client.get(reverse("profile_completion_clinic"))
- self.assertEqual(response.status_code, 200)
- self.assertTemplateUsed(template_name='profile/complete.html')
- self.assertIsInstance(response.context["form"], CompleteProfileClinicForm)
- self.assertContains(response, "Complete your registration")
- # POST request with no data
- response = self.client.post(reverse("profile_completion_clinic"), {})
- self.assertEqual(response.status_code, 200)
- self.assertContains(response, "This field is required.")
- # POST request with data
- response = self.client.post(reverse("profile_completion_clinic"),
- {
- "display_name": "Clinic name",
- "phone": "1416-123-4567",
- "address_line_1": "Address",
- "address_line_2": "Address",
- "address_city": "Toronto",
- "address_province": "ON",
- "therapist_type_other": "Other type",
- "secret_question": "MOTHER",
- "secret_answer": "abcde",
- })
- self.assertEqual(response.status_code, 302)
- self.assertRedirects(response, '/after_login/', target_status_code=302)
- def test_therapist_list_clinic_view(self):
- self.client.force_login(self._clinic.user)
- self.addToClinic(3)
- # GET request
- response = self.client.get(reverse("therapist_list", kwargs={"pk": self._clinic.pk}))
- import pdb; pdb.set_trace()
- self.assertEqual(response.status_code, 302) #deal with this code
- self.assertTemplateUsed(template_name='profile/therapist_list.html')
- self.assertContains(response, "Therapists")
- # GET request with random search
- response = self.client.get(reverse("therapist_list", {"q":"qwerty"}, kwargs={"pk": self._clinic.pk}))
- self.assertEqual(response.status_code, 200)
- self.assertContains(response, "0 therapists found matching qwerty")
- # GET request with valid search
- response = self.client.get(reverse("therapist_list", {"q":"Jobs"}, kwargs={"pk": self._clinic.pk}))
- self.assertEqual(response.status_code, 200)
- self.assertContains(response, "1 therapist found matching Jobs")
- def test_master_patient_list_clinic_view(self):
- self.client.force_login(self._clinic.user)
- # GET request
- response = self.client.get(reverse("master_patient_list", kwargs={"pk": self._clinic.pk}))
- self.assertEqual(response.status_code, 302) #deal with this code
- self.assertTemplateUsed(template_name='profile/master_patient_list.html')
- self.assertContains(response, "Patients")
- # GET request with random search
- response = self.client.get(reverse("master_patient_list", {"q":"qwerty"}, kwargs={"pk": self._clinic.pk}))
- self.assertEqual(response.status_code, 200)
- self.assertContains(response, "0 patients found matching qwerty")
- # GET request with valid search
- response = self.client.get(reverse("master_patient_list", {"q":"Elon"}, kwargs={"pk": self._clinic.pk}))
- self.assertEqual(response.status_code, 200)
- self.assertContains(response, "1 patient found matching Elon")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement