From 2bd254c0ad0508fbba152eba08d283788384f3b4 Mon Sep 17 00:00:00 2001 From: Carlos Vega <carlos.vega@uni.lu> Date: Thu, 19 Nov 2020 14:00:14 +0100 Subject: [PATCH] added view tests for privacy notice --- smash/web/forms/__init__.py | 3 +- smash/web/forms/privacy_notice.py | 2 +- smash/web/tests/view/test_privacy_notice.py | 59 +++++++++++++++++++++ 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 smash/web/tests/view/test_privacy_notice.py diff --git a/smash/web/forms/__init__.py b/smash/web/forms/__init__.py index 698f27b4..ad8a5a40 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 5c015dd2..9394fe36 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 00000000..6639db15 --- /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 -- GitLab