Skip to content
Snippets Groups Projects
Commit 2bd254c0 authored by Carlos Vega's avatar Carlos Vega
Browse files

added view tests for privacy notice

parent da924aba
No related branches found
No related tags found
1 merge request!276Resolve "privacy notice and usage terms"
...@@ -8,10 +8,11 @@ from .appointment_form import AppointmentDetailForm, AppointmentEditForm, Appoin ...@@ -8,10 +8,11 @@ from .appointment_form import AppointmentDetailForm, AppointmentEditForm, Appoin
from .study_subject_forms import StudySubjectAddForm, StudySubjectDetailForm, StudySubjectEditForm from .study_subject_forms import StudySubjectAddForm, StudySubjectDetailForm, StudySubjectEditForm
from .subject_forms import SubjectAddForm, SubjectEditForm, SubjectDetailForm from .subject_forms import SubjectAddForm, SubjectEditForm, SubjectDetailForm
from .voucher_forms import VoucherTypeForm, VoucherTypePriceForm, VoucherForm from .voucher_forms import VoucherTypeForm, VoucherTypePriceForm, VoucherForm
from .privacy_notice import PrivacyNoticeForm
__all__ = [StudySubjectAddForm, StudySubjectDetailForm, StudySubjectEditForm, WorkerForm, __all__ = [StudySubjectAddForm, StudySubjectDetailForm, StudySubjectEditForm, WorkerForm,
AppointmentDetailForm, AppointmentEditForm, AppointmentAddForm, VisitDetailForm, VisitAddForm, AppointmentDetailForm, AppointmentEditForm, AppointmentAddForm, VisitDetailForm, VisitAddForm,
ContactAttemptAddForm, ContactAttemptEditForm, KitRequestForm, StatisticsForm, AvailabilityAddForm, ContactAttemptAddForm, ContactAttemptEditForm, KitRequestForm, StatisticsForm, AvailabilityAddForm,
AvailabilityEditForm, HolidayAddForm, SubjectAddForm, SubjectEditForm, SubjectDetailForm, VoucherTypeForm, AvailabilityEditForm, HolidayAddForm, SubjectAddForm, SubjectEditForm, SubjectDetailForm, VoucherTypeForm,
VoucherTypePriceForm, VoucherForm, StudyEditForm, StudyNotificationParametersEditForm, StudyColumnsEditForm, VoucherTypePriceForm, VoucherForm, StudyEditForm, StudyNotificationParametersEditForm, StudyColumnsEditForm,
StudyRedCapColumnsEditForm] StudyRedCapColumnsEditForm, PrivacyNoticeForm]
...@@ -11,5 +11,5 @@ class PrivacyNoticeForm(ModelForm): ...@@ -11,5 +11,5 @@ class PrivacyNoticeForm(ModelForm):
fields = '__all__' fields = '__all__'
def clean(self): def clean(self):
cleaned_data = super(PrivacyNoticeForm, self).clean() cleaned_data = super().clean()
return cleaned_data return cleaned_data
\ No newline at end of file
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
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