Skip to content
Snippets Groups Projects
Commit 0713094a authored by Piotr Gawron's avatar Piotr Gawron
Browse files

subject view tests use new SubjectType

parent af192ac1
No related branches found
No related tags found
1 merge request!305Resolve "Allow for adding modifying types of subjects"
...@@ -187,7 +187,7 @@ class StudySubjectAddForm(StudySubjectForm): ...@@ -187,7 +187,7 @@ class StudySubjectAddForm(StudySubjectForm):
else: else:
subject_type = self.cleaned_data.get('type', None) subject_type = self.cleaned_data.get('type', None)
if subject_type is not None: if subject_type is not None:
screening_number_prefix = SCREENING_NUMBER_PREFIXES_FOR_TYPE[subject_type] screening_number_prefix = subject_type.screening_number_prefix
if screening_number_prefix is None: if screening_number_prefix is None:
return None return None
prefix_screening_number = screening_number_prefix + "-" prefix_screening_number = screening_number_prefix + "-"
......
...@@ -13,7 +13,8 @@ from web.models.custom_data import CustomStudySubjectField ...@@ -13,7 +13,8 @@ from web.models.custom_data import CustomStudySubjectField
from web.models.custom_data.custom_study_subject_field import get_study_subject_field_id from web.models.custom_data.custom_study_subject_field import get_study_subject_field_id
from web.tests import LoggedInWithWorkerTestCase from web.tests import LoggedInWithWorkerTestCase
from web.tests.functions import create_study_subject, create_visit, create_appointment, get_test_location, \ from web.tests.functions import create_study_subject, create_visit, create_appointment, get_test_location, \
create_language, get_resource_path, get_test_study, format_form_field create_language, get_resource_path, get_test_study, format_form_field, get_patient_subject_type, \
get_control_subject_type
from web.views.notifications import get_today_midnight_date from web.views.notifications import get_today_midnight_date
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -202,7 +203,7 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase): ...@@ -202,7 +203,7 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase):
print(form.errors) print(form.errors)
self.assertTrue(form.is_valid()) self.assertTrue(form.is_valid())
form_data["study_subject-type"] = SUBJECT_TYPE_CHOICES_CONTROL form_data["study_subject-type"] = get_control_subject_type().id
response = self.client.post(reverse('web.views.subject_add', kwargs={'study_id': self.study.id}), response = self.client.post(reverse('web.views.subject_add', kwargs={'study_id': self.study.id}),
data=form_data) data=form_data)
self.assertEqual(response.status_code, 302) self.assertEqual(response.status_code, 302)
...@@ -221,7 +222,7 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase): ...@@ -221,7 +222,7 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase):
form_data = self.create_add_form_data_for_study_subject() form_data = self.create_add_form_data_for_study_subject()
form_data["study_subject-type"] = SUBJECT_TYPE_CHOICES_CONTROL form_data["study_subject-type"] = get_control_subject_type().id
form_data["study_subject-referral_letter"] = SimpleUploadedFile("file.txt", b"file_content") form_data["study_subject-referral_letter"] = SimpleUploadedFile("file.txt", b"file_content")
form = SubjectAddForm(data=form_data, prefix="subject") form = SubjectAddForm(data=form_data, prefix="subject")
...@@ -252,7 +253,7 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase): ...@@ -252,7 +253,7 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase):
form_data["subject-first_name"] = "John" form_data["subject-first_name"] = "John"
form_data["subject-last_name"] = "Doe" form_data["subject-last_name"] = "Doe"
form_data["subject-sex"] = SEX_CHOICES_MALE form_data["subject-sex"] = SEX_CHOICES_MALE
form_data["study_subject-type"] = SUBJECT_TYPE_CHOICES_PATIENT form_data["study_subject-type"] = get_patient_subject_type().id
form_data["study_subject-subject"] = self.study_subject.id form_data["study_subject-subject"] = self.study_subject.id
form_data["study_subject-postponed"] = False form_data["study_subject-postponed"] = False
...@@ -297,7 +298,7 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase): ...@@ -297,7 +298,7 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase):
self.worker.roles.all()[0].permissions.add(Permission.objects.get(codename="add_subject")) self.worker.roles.all()[0].permissions.add(Permission.objects.get(codename="add_subject"))
self.worker.save() self.worker.save()
form_data = self.create_add_form_data_for_study_subject() form_data = self.create_add_form_data_for_study_subject()
form_data["study_subject-type"] = SUBJECT_TYPE_CHOICES_CONTROL form_data["study_subject-type"] = get_control_subject_type().id
form_data["subject-country"] = COUNTRY_OTHER_ID form_data["subject-country"] = COUNTRY_OTHER_ID
response = self.client.post(reverse('web.views.subject_add', kwargs={'study_id': self.study.id}), response = self.client.post(reverse('web.views.subject_add', kwargs={'study_id': self.study.id}),
...@@ -348,7 +349,7 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase): ...@@ -348,7 +349,7 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase):
form_data = self.create_edit_form_data_for_study_subject(self.study_subject) form_data = self.create_edit_form_data_for_study_subject(self.study_subject)
count = Provenance.objects.all().count() count = Provenance.objects.all().count()
form_data["study_subject-type"] = SUBJECT_TYPE_CHOICES_PATIENT form_data["study_subject-type"] = get_patient_subject_type().id
response = self.client.post( response = self.client.post(
reverse('web.views.subject_edit', kwargs={'id': self.study_subject.id}), data=form_data) reverse('web.views.subject_edit', kwargs={'id': self.study_subject.id}), data=form_data)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment