From 9568a32b002538bb6296ef81e691fb519f8ec445 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Fri, 16 Feb 2024 12:47:24 -0500 Subject: [PATCH] paperwork: Add basic tests for CertifiersReport and CertificationCountReport --- paperwork/tests.py | 62 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/paperwork/tests.py b/paperwork/tests.py index 24138dd..9f4fb61 100644 --- a/paperwork/tests.py +++ b/paperwork/tests.py @@ -7,7 +7,14 @@ from hypothesis import given from hypothesis import strategies as st 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: @@ -68,3 +75,56 @@ class InstructorOrVendorReportTestCase(PermissionRequiredViewTestCaseMixin, Test self.client.force_login(self.user_with_permission) response = self.client.get(self.path) 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)