Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add other model signals #591

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading