Skip to content

Commit

Permalink
Add test for recipient filter with FF on
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinRiese committed Dec 5, 2024
1 parent 5ba8892 commit 589ad5c
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion corehq/messaging/scheduling/tests/test_recipients.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
Field,
)
from corehq.apps.domain.shortcuts import create_domain
from corehq.apps.es.tests.utils import es_test
from corehq.apps.es.users import user_adapter
from corehq.apps.es.client import manager
from corehq.apps.groups.models import Group
from corehq.apps.hqcase.utils import update_case
from corehq.apps.locations.models import SQLLocation
Expand Down Expand Up @@ -42,7 +45,7 @@
from corehq.util.test_utils import (
create_test_case,
set_parent_case,
unregistered_django_model,
unregistered_django_model, flag_enabled,
)
from testapps.test_pillowtop.utils import process_pillow_changes

Expand Down Expand Up @@ -133,6 +136,7 @@ def test_passes_with_user_case_filter(self):
._passes_user_data_filter(self.mobile_user))


@es_test(requires=[user_adapter])
class SchedulingRecipientTest(TestCase):
domain = 'scheduling-recipient-test'

Expand All @@ -146,9 +150,14 @@ def setUpClass(cls):
cls.country_location = make_loc('usa', domain=cls.domain, type='country')
cls.state_location = make_loc('ma', domain=cls.domain, type='state', parent=cls.country_location)
cls.city_location = make_loc('boston', domain=cls.domain, type='city', parent=cls.state_location)
cls.city_location_2 = make_loc('salem', domain=cls.domain, type='city', parent=cls.state_location)

cls.mobile_user = CommCareUser.create(cls.domain, 'mobile', 'abc', None, None)
cls.mobile_user.set_location(cls.city_location)
cls.mobile_user.add_to_assigned_locations(cls.city_location_2)

user_adapter.index(cls.mobile_user, refresh=True)
manager.index_refresh(user_adapter.index_name)

cls.mobile_user2 = CommCareUser.create(cls.domain, 'mobile2', 'abc', None, None)
cls.mobile_user2.set_location(cls.state_location)
Expand Down Expand Up @@ -605,6 +614,47 @@ def test_expand_location_recipients_with_location_type_filter(self):
[self.mobile_user.get_id]
)

def test_expand_location_recipients_secondary_does_not_match(self):
schedule = TimedSchedule.create_simple_daily_schedule(
self.domain,
TimedEvent(time=time(9, 0)),
SMSContent(message={'en': 'Hello'})
)
schedule.include_descendant_locations = False
schedule.save()

instance = CaseTimedScheduleInstance(
domain=self.domain,
timed_schedule_id=schedule.schedule_id,
recipient_type='Location',
recipient_id=self.city_location_2.location_id
)
self.assertEqual(
list(instance.expand_recipients()),
[]
)

@flag_enabled('INCLUDE_ALL_LOCATIONS')
def test_expand_location_recipients_secondary_matches(self):
schedule = TimedSchedule.create_simple_daily_schedule(
self.domain,
TimedEvent(time=time(9, 0)),
SMSContent(message={'en': 'Hello'})
)
schedule.include_descendant_locations = False
schedule.save()

instance = CaseTimedScheduleInstance(
domain=self.domain,
timed_schedule_id=schedule.schedule_id,
recipient_type='Location',
recipient_id=self.city_location_2.location_id
)
self.assertEqual(
[self.mobile_user.get_id],
self.user_ids(instance.expand_recipients()),
)

def test_expand_group_recipients(self):
schedule = TimedSchedule.create_simple_daily_schedule(
self.domain,
Expand Down

0 comments on commit 589ad5c

Please sign in to comment.