"""Fixtures for the NotificationModel model and related functionality in the notifications app."""importtypingimportpytestfromdevices.modelsimportDeviceModelfromdjango.core.managementimportcall_commandfrompki.modelsimportDomainModel,IssuingCaModelfromnotifications.modelsimportNotificationMessageModel,NotificationStatus@pytest.fixture
[docs]defsetup_test_issuing_ca()->IssuingCaModel:"""Use custom management command to create a test Issuing CA."""call_command('create_single_test_issuing_ca')issuing_ca=IssuingCaModel.objects.get(unique_name='issuing-ca-a-test-fixture')returntyping.cast('IssuingCaModel',issuing_ca)
@pytest.fixture
[docs]deftest_domain(setup_test_issuing_ca:IssuingCaModel)->DomainModel:"""Create a domain linked to the test issuing CA."""domain,_=DomainModel.objects.get_or_create(unique_name='test-domain',defaults={'issuing_ca':setup_test_issuing_ca},)domain.issuing_ca=setup_test_issuing_cadomain.save()returndomain
@pytest.fixture
[docs]deftest_device(test_domain:DomainModel)->DeviceModel:"""Create a test device fixture."""device=DeviceModel.objects.create(common_name='test-device-1',serial_number='TEST123456',domain=test_domain,)returntyping.cast('DeviceModel',device)
@pytest.fixture
[docs]deftest_message()->NotificationMessageModel:"""Create a NotificationMessageModel used for custom notifications."""returnNotificationMessageModel.objects.create(short_description='Test short',long_description='Test long description')
@pytest.fixture
[docs]deftest_status()->NotificationStatus:"""Create a notification status object."""returnNotificationStatus.objects.create(status=NotificationStatus.StatusChoices.NEW)