paperwork: Add basic tests for CertifiersReport and CertificationCountReport

This commit is contained in:
Adam Goldsmith 2024-02-16 12:47:24 -05:00
parent d59318e2a5
commit 9568a32b00

View File

@ -7,7 +7,14 @@ from hypothesis import given
from hypothesis import strategies as st from hypothesis import strategies as st
from hypothesis.extra.django import TestCase, from_model from hypothesis.extra.django import TestCase, from_model
from paperwork.models import InstructorOrVendor, Waiver from paperwork.models import (
Certification,
CertificationDefinition,
CertificationVersion,
Department,
InstructorOrVendor,
Waiver,
)
class PermissionRequiredViewTestCaseMixin: class PermissionRequiredViewTestCaseMixin:
@ -68,3 +75,56 @@ class InstructorOrVendorReportTestCase(PermissionRequiredViewTestCaseMixin, Test
self.client.force_login(self.user_with_permission) self.client.force_login(self.user_with_permission)
response = self.client.get(self.path) response = self.client.get(self.path)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
@st.composite
def random_certifications(draw):
departments = draw(st.lists(from_model(Department), min_size=1))
definitions = draw(
st.lists(
from_model(
CertificationDefinition, department=st.sampled_from(departments)
),
min_size=1,
)
)
certification_versions = draw(
st.lists(
from_model(CertificationVersion, definition=st.sampled_from(definitions)),
min_size=1,
)
)
return draw(
st.lists(
from_model(
Certification,
number=st.none(),
certification_version=st.sampled_from(certification_versions),
)
)
)
class CertifiersReportTestCase(PermissionRequiredViewTestCaseMixin, TestCase):
permissions = [{"model": Certification, "codename": "view_certification"}]
path = "/paperwork/certifiers"
@given(certifications=random_certifications())
def test_certifers_report(self, certifications: list[Certification]) -> None:
self.client.force_login(self.user_with_permission)
response = self.client.get(self.path)
self.assertEqual(response.status_code, 200)
class CertificationCountReportTestCase(PermissionRequiredViewTestCaseMixin, TestCase):
permissions = [{"model": Certification, "codename": "view_certification"}]
path = "/paperwork/certification-count"
@given(certifications=random_certifications())
def test_certification_count_report(
self, certifications: list[Certification]
) -> None:
self.client.force_login(self.user_with_permission)
response = self.client.get(self.path)
self.assertEqual(response.status_code, 200)