diff --git a/smash/web/forms/__init__.py b/smash/web/forms/__init__.py index 698f27b4f65ea900c87815a3ffa6fb3b6f08697d..ad8a5a40cfff647132da51c5e6463f67b7521e5e 100644 --- a/smash/web/forms/__init__.py +++ b/smash/web/forms/__init__.py @@ -8,10 +8,11 @@ from .appointment_form import AppointmentDetailForm, AppointmentEditForm, Appoin from .study_subject_forms import StudySubjectAddForm, StudySubjectDetailForm, StudySubjectEditForm from .subject_forms import SubjectAddForm, SubjectEditForm, SubjectDetailForm from .voucher_forms import VoucherTypeForm, VoucherTypePriceForm, VoucherForm +from .privacy_notice import PrivacyNoticeForm __all__ = [StudySubjectAddForm, StudySubjectDetailForm, StudySubjectEditForm, WorkerForm, AppointmentDetailForm, AppointmentEditForm, AppointmentAddForm, VisitDetailForm, VisitAddForm, ContactAttemptAddForm, ContactAttemptEditForm, KitRequestForm, StatisticsForm, AvailabilityAddForm, AvailabilityEditForm, HolidayAddForm, SubjectAddForm, SubjectEditForm, SubjectDetailForm, VoucherTypeForm, VoucherTypePriceForm, VoucherForm, StudyEditForm, StudyNotificationParametersEditForm, StudyColumnsEditForm, - StudyRedCapColumnsEditForm] + StudyRedCapColumnsEditForm, PrivacyNoticeForm] diff --git a/smash/web/forms/privacy_notice.py b/smash/web/forms/privacy_notice.py index 5c015dd268a417c0beb802c852968fb39bd73a06..9394fe3687c142c54dbab9ef6d2b0e3c23ccf50e 100644 --- a/smash/web/forms/privacy_notice.py +++ b/smash/web/forms/privacy_notice.py @@ -11,5 +11,5 @@ class PrivacyNoticeForm(ModelForm): fields = '__all__' def clean(self): - cleaned_data = super(PrivacyNoticeForm, self).clean() + cleaned_data = super().clean() return cleaned_data \ No newline at end of file diff --git a/smash/web/tests/view/test_privacy_notice.py b/smash/web/tests/view/test_privacy_notice.py new file mode 100644 index 0000000000000000000000000000000000000000..6639db157aba6ab13e8f169c83a53055e0985a36 --- /dev/null +++ b/smash/web/tests/view/test_privacy_notice.py @@ -0,0 +1,59 @@ +from web.tests.functions import get_resource_path +from web.models import PrivacyNotice +from web.forms import PrivacyNoticeForm +from web.tests import LoggedInTestCase +from django.urls import reverse +from django.core.files.uploadedfile import SimpleUploadedFile + +class PrivacyNoticeTests(LoggedInTestCase): + def test_add_privacy_notice(self): + self.assertEqual(0, PrivacyNotice.objects.count()) + self.login_as_admin() + + form_data = dict( + name='example', + ) + + file_data = dict( + document=SimpleUploadedFile('file.txt', b"file_content") + ) + + form = PrivacyNoticeForm(form_data, file_data) + self.assertTrue(form.is_valid()) + + page = reverse('web.views.privacy_notice_add') + response = self.client.post(page, data={**form_data, **file_data}) + self.assertEqual(response.status_code, 302) + self.assertEqual(1, PrivacyNotice.objects.count()) + + def test_edit_privacy_notice(self): + self.test_add_privacy_notice() + self.assertEqual(1, PrivacyNotice.objects.count()) + pn = PrivacyNotice.objects.all()[0] + form_data = dict( + name='example2', + ) + + file_data = dict( + document=SimpleUploadedFile('file.txt', b"file_content") + ) + + form = PrivacyNoticeForm(form_data, file_data, instance=pn) + self.assertTrue(form.is_valid()) + + page = reverse('web.views.privacy_notice_edit', kwargs={'pk': pn.id}) + response = self.client.post(page, data={**form_data, **file_data}) + print(response) + self.assertEqual(response.status_code, 302) + pn = PrivacyNotice.objects.all()[0] + self.assertEqual(pn.name, 'example2') + + def test_delete_privacy_notice(self): + self.test_add_privacy_notice() + self.assertEqual(1, PrivacyNotice.objects.count()) + pn = PrivacyNotice.objects.all()[0] + page = reverse('web.views.privacy_notice_delete', kwargs={'pk': pn.id}) + response = self.client.post(page) + self.assertEqual(response.status_code, 302) + self.assertEqual(0, PrivacyNotice.objects.count()) + \ No newline at end of file