diff --git a/eventstore/signals.py b/eventstore/signals.py index 67e8b571..4b17909c 100644 --- a/eventstore/signals.py +++ b/eventstore/signals.py @@ -1,7 +1,14 @@ from django.db.models.signals import post_save from django.dispatch import receiver -from eventstore.models import OpenHIMQueue, PrebirthRegistration +from eventstore.models import ( + ChannelSwitch, + CHWRegistration, + OpenHIMQueue, + OptOut, + PrebirthRegistration, + PublicRegistration, +) @receiver(post_save, sender=PrebirthRegistration) @@ -11,3 +18,39 @@ def queue_prebirth_registration(sender, instance, created, **kwargs): object_id=instance.id, object_type=OpenHIMQueue.ObjectType.PREBIRTH_REGISTRATION, ) + + +@receiver(post_save, sender=PublicRegistration) +def queue_public_registration(sender, instance, created, **kwargs): + if created: + OpenHIMQueue.objects.create( + object_id=instance.id, + object_type=OpenHIMQueue.ObjectType.PUBLIC_REGISTRATION, + ) + + +@receiver(post_save, sender=CHWRegistration) +def queue_chw_registration(sender, instance, created, **kwargs): + if created: + OpenHIMQueue.objects.create( + object_id=instance.id, + object_type=OpenHIMQueue.ObjectType.CHW_REGISTRATION, + ) + + +@receiver(post_save, sender=ChannelSwitch) +def queue_channel_switch(sender, instance, created, **kwargs): + if created: + OpenHIMQueue.objects.create( + object_id=instance.id, + object_type=OpenHIMQueue.ObjectType.CHANNEL_SWITCH, + ) + + +@receiver(post_save, sender=OptOut) +def queue_optout(sender, instance, created, **kwargs): + if created: + OpenHIMQueue.objects.create( + object_id=instance.id, + object_type=OpenHIMQueue.ObjectType.OPTOUT, + ) diff --git a/eventstore/tests/test_models.py b/eventstore/tests/test_models.py index 27a92d0b..b811b8d7 100644 --- a/eventstore/tests/test_models.py +++ b/eventstore/tests/test_models.py @@ -3,13 +3,17 @@ from django.test import TestCase, override_settings from eventstore.models import ( + ChannelSwitch, + CHWRegistration, Covid19Triage, Event, HCSStudyBRandomization, HealthCheckUserProfile, Message, OpenHIMQueue, + OptOut, PrebirthRegistration, + PublicRegistration, ) @@ -587,3 +591,59 @@ def test_create_signal(self): self.assertEqual( queue_record.object_type, OpenHIMQueue.ObjectType.PREBIRTH_REGISTRATION ) + + +class PublicRegistrationTests(TestCase): + def test_create_signal(self): + publicregistration = PublicRegistration.objects.create( + contact_id="9e12d04c-af25-40b6-aa4f-57c72e8e3f91", + device_contact_id="9e12d04c-af25-40b6-aa4f-57c72e8e3f91", + ) + + queue_record = OpenHIMQueue.objects.first() + + self.assertEqual(queue_record.object_id, publicregistration.id) + self.assertEqual( + queue_record.object_type, OpenHIMQueue.ObjectType.PUBLIC_REGISTRATION + ) + + +class CHWRegistrationTests(TestCase): + def test_create_signal(self): + registration = CHWRegistration.objects.create( + contact_id="9e12d04c-af25-40b6-aa4f-57c72e8e3f91", + device_contact_id="9e12d04c-af25-40b6-aa4f-57c72e8e3f91", + ) + + queue_record = OpenHIMQueue.objects.first() + + self.assertEqual(queue_record.object_id, registration.id) + self.assertEqual( + queue_record.object_type, OpenHIMQueue.ObjectType.CHW_REGISTRATION + ) + + +class ChannelSwitchTests(TestCase): + def test_create_signal(self): + switch = ChannelSwitch.objects.create( + contact_id="9e12d04c-af25-40b6-aa4f-57c72e8e3f91", + ) + + queue_record = OpenHIMQueue.objects.first() + + self.assertEqual(queue_record.object_id, switch.id) + self.assertEqual( + queue_record.object_type, OpenHIMQueue.ObjectType.CHANNEL_SWITCH + ) + + +class OptoutTests(TestCase): + def test_create_signal(self): + optout = OptOut.objects.create( + contact_id="9e12d04c-af25-40b6-aa4f-57c72e8e3f91", + ) + + queue_record = OpenHIMQueue.objects.first() + + self.assertEqual(queue_record.object_id, optout.id) + self.assertEqual(queue_record.object_type, OpenHIMQueue.ObjectType.OPTOUT)