Skip to content

Commit

Permalink
Merge pull request #591 from praekeltfoundation/add-openhim-queue
Browse files Browse the repository at this point in the history
Add other model signals
  • Loading branch information
erikh360 committed Nov 23, 2023
2 parents a295cf0 + fe2541b commit 7e2d2ca
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 1 deletion.
45 changes: 44 additions & 1 deletion eventstore/signals.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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,
)
60 changes: 60 additions & 0 deletions eventstore/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


Expand Down Expand Up @@ -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)

0 comments on commit 7e2d2ca

Please sign in to comment.