diff --git a/requirements-dev.txt b/requirements-dev.txt index 8bfe3d4fe71b7aa07a14da2e5763ff2ca97750fc..6ccad2f1fd556e568bfafdc52b7d9546c4487ce4 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,4 +1,4 @@ coverage==5.3 -django-debug-toolbar==1.11 +django-debug-toolbar==2.2 mockito==1.2.2 parameterized==0.7.4 diff --git a/requirements.txt b/requirements.txt index 49a543a076f30f5d39b61889939d1ecfedebdedc..968ad6191a62ccde159e022d86c076f477929afe 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,62 +1,62 @@ pycurl==7.43.0.2 -asn1crypto==0.24.0 -Babel==2.6.0 -backports.functools-lru-cache==1.5 -certifi==2018.8.24 -cffi==1.14.2 +asn1crypto==1.4.0 +Babel==2.9.0 +backports.functools-lru-cache==1.6.1 +certifi==2020.11.8 +cffi==1.14.4 chardet==3.0.4 coverage==5.3 -cryptography==2.3.1 +cryptography==3.2.1 cycler==0.10.0 -Django==2.0.13 -django-cleanup==4.0.0 +Django==3.1.3 +django-cleanup==5.1.0 django-common-helpers==0.9.2 -django-cron==0.5.0 -django-excel==0.0.9 +django-cron==0.5.1 +django-excel==0.0.10 django-formtools==2.2 -django-otp==0.9.4 -django-phonenumber-field==1.3.0 +django-otp==1.0.2 +django-phonenumber-field==5.0.0 django-stronghold==0.4.0 -django-two-factor-auth==1.11 -enum34==1.1.6 -Faker==0.9.2 +django-two-factor-auth==1.13 +enum34==1.1.10 +Faker==4.17.1 funcsigs==1.0.2 -gunicorn==19.6.0 -idna==2.7 -ipaddress==1.0.22 -kiwisolver==1.0.1 -lml==0.0.4 +gunicorn==20.0.4 +idna==2.10 +ipaddress==1.0.23 +kiwisolver==1.3.1 +lml==0.1.0 luhn==0.2.0 -lxml==4.5.2 -matplotlib==2.2.3 +lxml==4.6.1 +matplotlib==3.3.3 mockito==1.2.2 -nexmo==2.3.0 -numpy==1.19.2 -pandas==1.1.3 +nexmo==2.5.2 +numpy==1.19.4 +pandas==1.1.4 django-datatables-view==1.19.1 -phonenumberslite==8.9.14 -Pillow==3.4.2 +phonenumberslite==8.12.13 +#Pillow==3.4.2 psycopg2==2.8.6 -pycparser==2.19 -pyexcel==0.6.4 -pyexcel-io==0.5.19 +pycparser==2.20 +pyexcel==0.6.6 +pyexcel-io==0.6.4 pyexcel-webio==0.1.4 -pyexcel-xls==0.5.9 -PyJWT==1.6.4 -pyparsing==2.2.2 -python-dateutil==2.7.3 -python-docx==0.8.6 -pytz==2017.2 -qrcode==4.0.4 -requests==2.19.1 +pyexcel-xls==0.6.1 +PyJWT==1.7.1 +pyparsing==2.4.7 +python-dateutil==2.8.1 +python-docx==0.8.10 +pytz==2020.4 +qrcode==6.1 +requests==2.25.0 six==1.15.0 -sqlparse==0.2.4 -subprocess32==3.5.2 -text-unidecode==1.2 -texttable==1.4.0 -timeout-decorator==0.4.0 -Unidecode==1.0.22 -urllib3==1.23 +sqlparse==0.4.1 +subprocess32==3.5.4 +text-unidecode==1.3 +texttable==1.6.3 +timeout-decorator==0.5.0 +urllib3==1.26.2 whitenoise==5.2.0 -xlrd==1.1.0 +xlrd==1.2.0 xlwt==1.3.0 +setuptools==50.3.2 \ No newline at end of file diff --git a/smash/db_scripts/create_dummy_data.py b/smash/db_scripts/create_dummy_data.py index 42bbd0445208e94260760dca6ed35229ffdc2c83..aef885576c0f122d9f64dab0fa4408b6c2b705ed 100644 --- a/smash/db_scripts/create_dummy_data.py +++ b/smash/db_scripts/create_dummy_data.py @@ -31,7 +31,6 @@ from numpy.random import choice from faker import Faker import platform import tempfile -import unidecode from shutil import copyfile @@ -40,7 +39,7 @@ class smashProvider(BaseProvider): __provider__ = 'smash' __lang__ = 'fr_FR' fake = Faker() - fake.seed(4321) + Faker.seed(4321) specialists = ['Psychiatrist', 'Radiologist', 'Immunologist', 'Anesthesiologist', 'Surgeon', 'Pediatrician', 'Neurologist', 'Medical examiner'] @@ -477,7 +476,7 @@ class smashProvider(BaseProvider): getAlreadyCreatedSmashLanguages = languages[0] if phone_number is None: - phone_number = self.fake.phone_number() + phone_number = self.fake.phone_number()[:20] if social_security_number is None: social_security_number = '' @@ -529,11 +528,11 @@ class smashProvider(BaseProvider): last_name = self.fake.last_name().lower() if username is None: username = '{}_{}'.format(first_name, last_name) - username = unidecode.unidecode(username).lower().replace(' ', '_') + username = username.lower().replace(' ', '_') if email is None: email = '{}.{}@smash.lu'.format(first_name, last_name) - email = unidecode.unidecode(email) + email = email # create user defaults = {'email': email, 'password': password} user, _ = User.objects.update_or_create( @@ -589,7 +588,7 @@ class smashProvider(BaseProvider): unit = self.getSmashUnit() if phone_number is None: - phone_number = self.fake.phone_number() + phone_number = self.fake.phone_number()[:20] if role is None: role = self.getWorkerRole() @@ -608,6 +607,7 @@ class smashProvider(BaseProvider): defaults = {'first_name': first_name, 'last_name': last_name, 'email': email, 'unit': unit, 'specialization': specialization, 'phone_number': phone_number, 'user': user} + worker, _ = Worker.objects.update_or_create(first_name=first_name, last_name=last_name, defaults=defaults) @@ -721,7 +721,7 @@ if __name__ == "__main__": if not os.path.exists(MEDIA_ROOT): os.makedirs(MEDIA_ROOT) fake = Faker() - fake.seed(4321) + Faker.seed(4321) fake.add_provider(smashProvider) fake.createSmashFlyingTeams() fake.createSmashItems() diff --git a/smash/web/tests/forms/test_StudySubjectAddForm.py b/smash/web/tests/forms/test_StudySubjectAddForm.py index 62ea530a82927bf964586ae771b651822e3a5f1e..78cce7aa90f727965d703b68a33a0044c93c6393 100644 --- a/smash/web/tests/forms/test_StudySubjectAddForm.py +++ b/smash/web/tests/forms/test_StudySubjectAddForm.py @@ -27,7 +27,8 @@ class StudySubjectAddFormTests(LoggedInWithWorkerTestCase): 'type': SUBJECT_TYPE_CHOICES_CONTROL, 'default_location': location.id, 'screening_number': "123", - 'subject': self.subject.id + 'subject': self.subject.id, + 'postponed': False } def test_validation(self): diff --git a/smash/web/tests/forms/test_StudySubjectEditForm.py b/smash/web/tests/forms/test_StudySubjectEditForm.py index c00979384c0bb7e128fef206b6fbe1c897ebefcc..670bf37cc5f78d54670f0c934b596cda84eac4d1 100644 --- a/smash/web/tests/forms/test_StudySubjectEditForm.py +++ b/smash/web/tests/forms/test_StudySubjectEditForm.py @@ -26,7 +26,8 @@ class StudySubjectEditFormTests(LoggedInWithWorkerTestCase): 'screening_number': self.study_subject.screening_number, 'nd_number': self.study_subject.nd_number, 'subject': self.study_subject.subject.id, - 'id': self.study_subject.id + 'id': self.study_subject.id, + 'postponed': False } def tearDown(self): diff --git a/smash/web/tests/forms/test_VisitAddForm.py b/smash/web/tests/forms/test_VisitAddForm.py index 62f7311bbd41f3855ceb5a87eef5210e1896088b..8fad6e8f1b74c146a6282d7ced08ab3358ca8463 100644 --- a/smash/web/tests/forms/test_VisitAddForm.py +++ b/smash/web/tests/forms/test_VisitAddForm.py @@ -15,8 +15,8 @@ class VisitAddFormTests(TestCase): self.sample_data = {'datetime_begin': "2017-01-01", 'datetime_end': "2017-02-02", 'subject': self.subject.id, - 'appointment_types': '' - + 'appointment_types': '', + 'post_mail_sent': False } def test_validation(self): diff --git a/smash/web/tests/view/test_subjects.py b/smash/web/tests/view/test_subjects.py index c0fb25330b8b12e4b1fff4cb35f176a1d3ac2a4a..516423687daeebce37554ae137a83f793076cb6f 100644 --- a/smash/web/tests/view/test_subjects.py +++ b/smash/web/tests/view/test_subjects.py @@ -170,6 +170,14 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase): self.worker.save() form_data = self.create_add_form_data_for_study_subject() + form = SubjectAddForm(data=form_data, prefix="subject") + print(form.errors) + self.assertTrue(form.is_valid()) + + form = StudySubjectAddForm(data=form_data, prefix="study_subject", user=self.user, study=self.study) + print(form.errors) + self.assertTrue(form.is_valid()) + form_data["study_subject-type"] = SUBJECT_TYPE_CHOICES_CONTROL response = self.client.post(reverse('web.views.subject_add', kwargs={'study_id': self.study.id}), data=form_data) @@ -191,6 +199,13 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase): form_data["study_subject-type"] = SUBJECT_TYPE_CHOICES_CONTROL form_data["study_subject-referral_letter"] = SimpleUploadedFile("file.txt", b"file_content") + + form = SubjectAddForm(data=form_data, prefix="subject") + self.assertTrue(form.is_valid()) + + form = StudySubjectAddForm(data=form_data, prefix="study_subject", user=self.user, study=self.study) + self.assertTrue(form.is_valid()) + response = self.client.post(reverse('web.views.subject_add', kwargs={'study_id': self.study.id}), data=form_data) self.assertEqual(response.status_code, 302) @@ -215,6 +230,7 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase): form_data["subject-sex"] = SEX_CHOICES_MALE form_data["study_subject-type"] = SUBJECT_TYPE_CHOICES_PATIENT form_data["study_subject-subject"] = self.study_subject.id + form_data["study_subject-postponed"] = False # TODO remove after refactoring form_data["study_subject-country"] = COUNTRY_AFGHANISTAN_ID diff --git a/smash/web/tests/view/test_visit.py b/smash/web/tests/view/test_visit.py index 9600e0da510a810599c3848c98d1196a5ee5c58c..db6c99eeb861bea4d2df12660b9c74d08aa99043 100644 --- a/smash/web/tests/view/test_visit.py +++ b/smash/web/tests/view/test_visit.py @@ -4,7 +4,7 @@ import logging from django.urls import reverse from django.utils import timezone -from web.forms import VisitDetailForm +from web.forms import VisitDetailForm, VisitAddForm from web.models import Visit, MailTemplate from web.models.constants import MAIL_TEMPLATE_CONTEXT_VISIT from web.tests import LoggedInTestCase @@ -82,6 +82,10 @@ class VisitViewTests(LoggedInTestCase): form_data["datetime_begin"] = "2017-01-01" form_data["datetime_end"] = "2017-04-01" form_data["subject"] = subject.id + form_data["post_mail_sent"] = False + + form = VisitAddForm(data=form_data) + self.assertTrue(form.is_valid()) response = self.client.post(reverse('web.views.visit_add', kwargs={'subject_id': subject.id}), data=form_data) self.assertEqual(response.status_code, 302) diff --git a/smash/web/urls.py b/smash/web/urls.py index 2459ef8b7255f00d47b66a6607f4b0dcf138caac..86dc468c0bc2c7b8bbbb0c2e652426977536aab4 100644 --- a/smash/web/urls.py +++ b/smash/web/urls.py @@ -16,7 +16,7 @@ Including another URLconf from django.conf import settings from django.conf.urls import include from django.conf.urls import url -from django.contrib.auth.views import logout +from django.contrib.auth.views import LogoutView from django.views.defaults import page_not_found from web import views @@ -289,7 +289,7 @@ urlpatterns = [ # url(r'^login$', views.auth.login, name='web.views.login'), # url(r'^logout$', views.auth.logout, name='web.views.logout'), - url(r'^logout$', logout, name='logout'), + url(r'^logout$', LogoutView.as_view(), name='logout'), url(r'^$', views.index, name='web.views.index') ] diff --git a/smash/web/widgets/secure_file_widget.py b/smash/web/widgets/secure_file_widget.py index c268ad4a5598e2fdba46611ea09844022a1f4402..4d87384c36e5ad1c0a3ed0ebe2ad024adde8cfaa 100644 --- a/smash/web/widgets/secure_file_widget.py +++ b/smash/web/widgets/secure_file_widget.py @@ -16,11 +16,11 @@ class SecuredFileWidget(forms.FileInput): attrs = {} super(SecuredFileWidget, self).__init__(attrs) - def render(self, name, value, attrs=None): + def render(self, name, value, attrs=None, renderer=None): output = [] if value and hasattr(value, "url"): url = reverse('web.views.uploaded_files') + '?file=' + str(value) out = '<a href="{}">{}</a><br />{} ' output.append(out.format(url, _('Download'), _('Change:'))) - output.append(super(SecuredFileWidget, self).render(name, value, attrs)) + output.append(super(SecuredFileWidget, self).render(name, value, attrs, renderer=renderer)) return mark_safe(''.join(output))