本文整理汇总了Python中casexml.apps.case.models.CommCareCase.set_case_property方法的典型用法代码示例。如果您正苦于以下问题:Python CommCareCase.set_case_property方法的具体用法?Python CommCareCase.set_case_property怎么用?Python CommCareCase.set_case_property使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类casexml.apps.case.models.CommCareCase
的用法示例。
在下文中一共展示了CommCareCase.set_case_property方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_date_case_properties_for_equality
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import set_case_property [as 别名]
def test_date_case_properties_for_equality(self):
"""
Date case properties are automatically converted from string to date
when fetching from the db, so here we want to make sure this doesn't
interfere with our ability to compare dates for equality.
"""
case = CommCareCase(
domain=self.domain,
type='test-case-type-2',
)
self.rule2.automaticupdaterulecriteria_set = [
AutomaticUpdateRuleCriteria(
property_name='property1',
property_value='2016-02-24',
match_type=AutomaticUpdateRuleCriteria.MATCH_EQUAL,
),
]
case.set_case_property('property1', '2016-02-24')
case.save()
case = CommCareCase.get(case.get_id)
case.server_modified_on = datetime(2015, 1, 1)
self.assertTrue(self.rule2.rule_matches_case(case, datetime(2016, 1, 1)))
case.set_case_property('property1', '2016-02-25')
case.save()
case = CommCareCase.get(case.get_id)
case.server_modified_on = datetime(2015, 1, 1)
self.assertFalse(self.rule2.rule_matches_case(case, datetime(2016, 1, 1)))
case.delete()
示例2: test_phone_number_already_in_use
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import set_case_property [as 别名]
def test_phone_number_already_in_use(self):
case1 = CommCareCase(
domain='case-phone-number-test',
name='TEST1'
)
case1.set_case_property('contact_phone_number', '99987658765')
case1.set_case_property('contact_phone_number_is_verified', '1')
case1.save()
case2 = CommCareCase(
domain='case-phone-number-test',
name='TEST2'
)
case2.set_case_property('contact_phone_number', '99987698769')
case2.set_case_property('contact_phone_number_is_verified', '1')
case2.save()
self.assertIsNotNone(self.get_case_verified_number(case1))
self.assertIsNotNone(self.get_case_verified_number(case2))
case2.set_case_property('contact_phone_number', '99987658765')
case2.save()
self.assertIsNotNone(self.get_case_verified_number(case1))
self.assertIsNone(self.get_case_verified_number(case2))
case2.delete()
self.get_case_verified_number(case1).delete()
case1.delete()
示例3: test_date_case_properties_for_inequality
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import set_case_property [as 别名]
def test_date_case_properties_for_inequality(self):
case = CommCareCase(
domain=self.domain,
type='test-case-type-2',
)
self.rule2.automaticupdaterulecriteria_set = [
AutomaticUpdateRuleCriteria(
property_name='property1',
property_value='2016-02-24',
match_type=AutomaticUpdateRuleCriteria.MATCH_NOT_EQUAL,
),
]
case.set_case_property('property1', '2016-02-24')
case.save()
case = CommCareCase.get(case.get_id)
case.server_modified_on = datetime(2015, 1, 1)
self.assertFalse(self.rule2.rule_matches_case(case, datetime(2016, 1, 1)))
case.set_case_property('property1', '2016-02-25')
case.save()
case = CommCareCase.get(case.get_id)
case.server_modified_on = datetime(2015, 1, 1)
self.assertTrue(self.rule2.rule_matches_case(case, datetime(2016, 1, 1)))
case.delete()
示例4: test_match_days_since
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import set_case_property [as 别名]
def test_match_days_since(self):
case = CommCareCase(
domain=self.domain,
type='test-case-type-2',
server_modified_on=datetime(2015, 1, 1),
)
self.rule2.automaticupdaterulecriteria_set = [
AutomaticUpdateRuleCriteria(
property_name='last_visit_date',
property_value='30',
match_type=AutomaticUpdateRuleCriteria.MATCH_DAYS_SINCE,
),
]
self.assertFalse(self.rule2.rule_matches_case(case, datetime(2016, 1, 1)))
case.set_case_property('last_visit_date', '2015-12-30')
self.assertFalse(self.rule2.rule_matches_case(case, datetime(2016, 1, 1)))
case.set_case_property('last_visit_date', '2015-12-03')
self.assertFalse(self.rule2.rule_matches_case(case, datetime(2016, 1, 1)))
case.set_case_property('last_visit_date', '2015-12-02')
self.assertTrue(self.rule2.rule_matches_case(case, datetime(2016, 1, 1)))
case.set_case_property('last_visit_date', '2015-11-01')
self.assertTrue(self.rule2.rule_matches_case(case, datetime(2016, 1, 1)))
示例5: test_case_soft_delete
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import set_case_property [as 别名]
def test_case_soft_delete(self):
case = CommCareCase(
domain='case-phone-number-test',
name='TEST1'
)
case.set_case_property('contact_phone_number', '99987658765')
case.set_case_property('contact_phone_number_is_verified', '1')
case.save()
self.assertIsNotNone(self.get_case_verified_number(case))
case.doc_type += '-Deleted'
case.save()
self.assertIsNone(self.get_case_verified_number(case))
case.delete()
示例6: test_match_has_value
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import set_case_property [as 别名]
def test_match_has_value(self):
case = CommCareCase(domain=self.domain, type="test-case-type-2", server_modified_on=datetime(2015, 1, 1))
self.rule2.automaticupdaterulecriteria_set = [
AutomaticUpdateRuleCriteria(
property_name="property3", match_type=AutomaticUpdateRuleCriteria.MATCH_HAS_VALUE
)
]
self.assertFalse(self.rule2.rule_matches_case(case, datetime(2016, 1, 1)))
case.set_case_property("property3", "x")
self.assertTrue(self.rule2.rule_matches_case(case, datetime(2016, 1, 1)))
case.set_case_property("property3", "")
self.assertFalse(self.rule2.rule_matches_case(case, datetime(2016, 1, 1)))
示例7: MessageTestCase
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import set_case_property [as 别名]
class MessageTestCase(BaseReminderTestCase):
def setUp(self):
self.domain = "test"
self.parent_case = CommCareCase(
domain=self.domain,
type="parent",
name="P001",
)
self.parent_case.set_case_property("parent_prop1", "abc")
self.parent_case.save()
self.child_case = CommCareCase(
domain=self.domain,
type="child",
name="P002",
indices=[CommCareCaseIndex(
identifier="parent",
referenced_type="parent",
referenced_id=self.parent_case._id,
)],
)
self.child_case.set_case_property("child_prop1", "def")
self.child_case.save()
def tearDown(self):
self.child_case.delete()
self.parent_case.delete()
def test_message(self):
message = 'The EDD for client with ID {case.external_id} is approaching in {case.edd.days_until} days.'
case = {'external_id': 123, 'edd': datetime.utcnow() + timedelta(days=30)}
outcome = 'The EDD for client with ID 123 is approaching in 30 days.'
self.assertEqual(Message.render(message, case=case), outcome)
def test_template_params(self):
child_result = {"case": self.child_case.case_properties()}
child_result["case"]["parent"] = self.parent_case.case_properties()
self.assertEqual(
get_message_template_params(self.child_case), child_result)
parent_result = {"case": self.parent_case.case_properties()}
parent_result["case"]["parent"] = {}
self.assertEqual(
get_message_template_params(self.parent_case), parent_result)
示例8: test_match_not_equal
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import set_case_property [as 别名]
def test_match_not_equal(self):
case = CommCareCase(
domain=self.domain,
type='test-case-type-2',
server_modified_on=datetime(2015, 1, 1),
)
self.rule2.automaticupdaterulecriteria_set = [
AutomaticUpdateRuleCriteria(
property_name='property2',
property_value='value2',
match_type=AutomaticUpdateRuleCriteria.MATCH_NOT_EQUAL,
),
]
self.assertTrue(self.rule2.rule_matches_case(case, datetime(2016, 1, 1)))
case.set_case_property('property2', 'value2')
self.assertFalse(self.rule2.rule_matches_case(case, datetime(2016, 1, 1)))
case.set_case_property('property2', 'x')
self.assertTrue(self.rule2.rule_matches_case(case, datetime(2016, 1, 1)))
示例9: test_invalid_phone_format
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import set_case_property [as 别名]
def test_invalid_phone_format(self):
case = CommCareCase(
domain='case-phone-number-test',
name='TEST1'
)
case.set_case_property('contact_phone_number', '99987658765')
case.set_case_property('contact_phone_number_is_verified', '1')
case.save()
self.assertIsNotNone(self.get_case_verified_number(case))
case.set_case_property('contact_phone_number', 'xyz')
case.save()
self.assertIsNone(self.get_case_verified_number(case))
case.delete()
示例10: test_match_days_since
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import set_case_property [as 别名]
def test_match_days_since(self):
case = CommCareCase(domain=self.domain, type="test-case-type-2", server_modified_on=datetime(2015, 1, 1))
self.rule2.automaticupdaterulecriteria_set = [
AutomaticUpdateRuleCriteria(
property_name="last_visit_date",
property_value="30",
match_type=AutomaticUpdateRuleCriteria.MATCH_DAYS_SINCE,
)
]
self.assertFalse(self.rule2.rule_matches_case(case, datetime(2016, 1, 1)))
case.set_case_property("last_visit_date", "2015-12-30")
self.assertFalse(self.rule2.rule_matches_case(case, datetime(2016, 1, 1)))
case.set_case_property("last_visit_date", "2015-12-03")
self.assertFalse(self.rule2.rule_matches_case(case, datetime(2016, 1, 1)))
case.set_case_property("last_visit_date", "2015-12-02")
self.assertTrue(self.rule2.rule_matches_case(case, datetime(2016, 1, 1)))
case.set_case_property("last_visit_date", "2015-11-01")
self.assertTrue(self.rule2.rule_matches_case(case, datetime(2016, 1, 1)))
示例11: AllBackendTest
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import set_case_property [as 别名]
class AllBackendTest(BaseSMSTest):
def setUp(self):
super(AllBackendTest, self).setUp()
backend_api.TEST = True
self.domain_obj = Domain(name='all-backend-test')
self.domain_obj.save()
self.create_account_and_subscription(self.domain_obj.name)
self.domain_obj = Domain.get(self.domain_obj._id)
self.test_phone_number = '99912345'
self.contact1 = CommCareCase(domain=self.domain_obj.name)
self.contact1.set_case_property('contact_phone_number', self.test_phone_number)
self.contact1.set_case_property('contact_phone_number_is_verified', '1')
self.contact1.save()
self.contact1 = CommConnectCase.wrap(self.contact1.to_json())
# For use with megamobile only
self.contact2 = CommCareCase(domain=self.domain_obj.name)
self.contact2.set_case_property('contact_phone_number', '63%s' % self.test_phone_number)
self.contact2.set_case_property('contact_phone_number_is_verified', '1')
self.contact2.save()
self.contact2 = CommConnectCase.wrap(self.contact2.to_json())
self.unicel_backend = UnicelBackend(name='UNICEL', is_global=True)
self.unicel_backend.save()
self.mach_backend = MachBackend(name='MACH', is_global=True)
self.mach_backend.save()
self.tropo_backend = TropoBackend(name='TROPO', is_global=True)
self.tropo_backend.save()
self.http_backend = HttpBackend(name='HTTP', is_global=True)
self.http_backend.save()
self.telerivet_backend = TelerivetBackend(name='TELERIVET', is_global=True,
webhook_secret='telerivet-webhook-secret')
self.telerivet_backend.save()
self.test_backend = TestSMSBackend(name='TEST', is_global=True)
self.test_backend.save()
self.grapevine_backend = GrapevineBackend(name='GRAPEVINE', is_global=True)
self.grapevine_backend.save()
self.twilio_backend = TwilioBackend(name='TWILIO', is_global=True)
self.twilio_backend.save()
self.megamobile_backend = MegamobileBackend(name='MEGAMOBILE', is_global=True)
self.megamobile_backend.save()
self.smsgh_backend = SMSGHBackend(name='SMSGH', is_global=True)
self.smsgh_backend.save()
self.apposit_backend = AppositBackend(name='APPOSIT', is_global=True)
self.apposit_backend.save()
def _test_outbound_backend(self, backend, msg_text, mock_send):
self.domain_obj.default_sms_backend_id = backend._id
self.domain_obj.save()
send_sms(self.domain_obj.name, None, self.test_phone_number, msg_text)
sms = SMS.objects.get(
domain=self.domain_obj.name,
direction='O',
text=msg_text
)
self.assertTrue(mock_send.called)
msg_arg = mock_send.call_args[0][0]
self.assertEqual(msg_arg.date, sms.date)
def _verify_inbound_request(self, backend_api_id, msg_text):
sms = SMS.objects.get(
domain=self.domain_obj.name,
direction='I',
text=msg_text
)
self.assertEqual(sms.backend_api, backend_api_id)
def _simulate_inbound_request_with_payload(self, url,
content_type, payload):
response = Client().post(url, payload, content_type=content_type)
self.assertEqual(response.status_code, 200)
def _simulate_inbound_request(self, url, phone_param,
msg_param, msg_text, post=False, additional_params=None):
fcn = Client().post if post else Client().get
payload = {
phone_param: self.test_phone_number,
msg_param: msg_text,
}
if additional_params:
payload.update(additional_params)
response = fcn(url, payload)
self.assertEqual(response.status_code, 200)
#.........这里部分代码省略.........
示例12: StartConditionReminderTestCase
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import set_case_property [as 别名]
class StartConditionReminderTestCase(BaseReminderTestCase):
def setUp(self):
super(StartConditionReminderTestCase, self).setUp()
self.domain = "test"
self.user_id = "USER-ID-109351"
self.user = CommCareUser.create(self.domain, 'chw.bob5', '****', uuid=self.user_id, phone_number="99912345")
self.handler1 = CaseReminderHandler(
domain=self.domain,
case_type="case_type_a",
method=METHOD_SMS,
start_property='start_sending1',
start_value="^(ok|OK|\d\d\d\d-\d\d-\d\d)",
start_date='start_sending1',
start_offset=1,
start_match_type=MATCH_REGEX,
until='stop_sending1',
default_lang='en',
max_iteration_count=REPEAT_SCHEDULE_INDEFINITELY,
schedule_length=3,
event_interpretation=EVENT_AS_OFFSET,
events = [
CaseReminderEvent(
day_num = 0
,fire_time = time(0,0,0)
,message={"en":"Message1"}
,callback_timeout_intervals=[]
)
]
)
self.handler1.save()
self.case1 = CommCareCase(
domain=self.domain,
type="case_type_a",
user_id=self.user_id
)
self.case1.save()
def tearDown(self):
self.user.delete()
super(StartConditionReminderTestCase, self).tearDown()
def test_ok(self):
#
# Test changing a start condition of "ok"
#
# Spawn the reminder with an "ok" start condition value
CaseReminderHandler.now = datetime(year=2012, month=2, day=17, hour=12, minute=0)
self.assertEqual(self.handler1.get_reminder(self.case1), None)
self.case1.set_case_property("start_sending1", "ok")
self.case1.save()
reminder = self.handler1.get_reminder(self.case1)
self.assertNotEqual(reminder, None)
self.assertEqual(
reminder.next_fire
,CaseReminderHandler.now + timedelta(days=self.handler1.start_offset)
)
# Test that saving the case without changing the start condition has no effect
old_reminder_id = reminder._id
self.case1.set_case_property("case_property1", "abc")
self.case1.save()
reminder = self.handler1.get_reminder(self.case1)
self.assertNotEqual(reminder, None)
self.assertEqual(reminder._id, old_reminder_id)
# Test retiring the reminder
old_reminder_id = reminder._id
self.case1.set_case_property("start_sending1", None)
self.case1.save()
self.assertEqual(self.handler1.get_reminder(self.case1), None)
self.assertEqual(CaseReminder.get(old_reminder_id).doc_type, "CaseReminder-Deleted")
#
# Test changing a start condition which is a datetime value
#
# Spawn the reminder with datetime start condition value
start = datetime(2012,2,20,9,0,0)
self.case1.set_case_property("start_sending1", start)
self.case1.save()
reminder = self.handler1.get_reminder(self.case1)
self.assertNotEqual(reminder, None)
self.assertEqual(
reminder.next_fire
,start + timedelta(days=self.handler1.start_offset)
)
# Reset the datetime start condition
old_reminder_id = reminder._id
start = datetime(2012,2,22,10,15,0)
self.case1.set_case_property("start_sending1", start)
self.case1.save()
#.........这里部分代码省略.........
示例13: CaseTypeReminderTestCase
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import set_case_property [as 别名]
#.........这里部分代码省略.........
events = [
CaseReminderEvent(
day_num = 0
,fire_time = time(0,0,0)
,message={"en":"Message3"}
,callback_timeout_intervals=[]
)
]
)
self.handler3.save()
self.case1 = CommCareCase(
domain=self.domain,
type="case_type_a",
user_id=self.user_id
)
self.case1.save()
self.case2 = CommCareCase(
domain=self.domain,
type="case_type_b",
user_id=self.user_id
)
self.case2.save()
def tearDown(self):
self.user.delete()
super(CaseTypeReminderTestCase, self).tearDown()
def test_ok(self):
# Initial condition
CaseReminderHandler.now = datetime(year=2012, month=2, day=16, hour=11, minute=0)
self.case1.set_case_property("start_sending1", "ok")
self.case1.set_case_property("start_sending2", "ok")
self.case2.set_case_property("start_sending1", "ok")
self.case2.set_case_property("start_sending3", "ok")
self.case1.save()
self.case2.save()
self.assertNotEqual(self.handler1.get_reminder(self.case1), None)
self.assertEqual(self.handler1.get_reminder(self.case2), None)
self.assertNotEqual(self.handler2.get_reminder(self.case1), None)
self.assertEqual(self.handler2.get_reminder(self.case2), None)
self.assertEqual(self.handler3.get_reminder(self.case1), None)
self.assertEqual(self.handler3.get_reminder(self.case2), None)
self.assertEqual(
self.handler1.get_reminder(self.case1).next_fire
,CaseReminderHandler.now + timedelta(days=self.handler1.start_offset)
)
self.assertEqual(
self.handler2.get_reminder(self.case1).next_fire
,CaseReminderHandler.now + timedelta(days=self.handler2.start_offset)
)
# Test deactivation and spawn on change of CaseReminderHandler.case_type
CaseReminderHandler.now = datetime(year=2012, month=2, day=16, hour=11, minute=15)
self.handler1.case_type = "case_type_b"
self.handler1.save()
self.handler2.case_type = "case_type_b"
self.handler2.save()
self.handler3.case_type = "case_type_b"
self.handler3.save()
示例14: ReminderTestCase
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import set_case_property [as 别名]
class ReminderTestCase(BaseReminderTestCase):
"""
This is the original use case and tests a fixed reminder schedule.
"""
def setUp(self):
super(ReminderTestCase, self).setUp()
self.domain = "test"
self.case_type = "my_case_type"
self.message = "Hey you're getting this message."
self.handler = CaseReminderHandler(
domain=self.domain,
case_type=self.case_type,
method=METHOD_SMS,
start_property='start_sending',
start_value="ok",
start_date=None,
start_offset=1,
start_match_type=MATCH_EXACT,
until='stop_sending',
default_lang='en',
max_iteration_count=REPEAT_SCHEDULE_INDEFINITELY,
schedule_length=3,
event_interpretation=EVENT_AS_OFFSET,
events = [
CaseReminderEvent(
day_num = 0
,fire_time = time(0,0,0)
,message={"en":self.message}
,callback_timeout_intervals=[]
)
]
)
self.handler.save()
self.user_id = "USER-ID-109347"
self.user = CommCareUser.create(self.domain, 'chw.bob', '****', uuid=self.user_id, phone_number="99912345")
self.case = CommCareCase(
domain=self.domain,
type=self.case_type,
user_id=self.user_id,
)
self.case.save()
def tearDown(self):
self.user.delete()
super(ReminderTestCase, self).tearDown()
def test_ok(self):
self.assertEqual(self.handler.events[0].message['en'], self.message)
self.assertEqual(self.handler.get_reminder(self.case), None)
# create reminder
CaseReminderHandler.now = datetime(year=2011, month=7, day=7, hour=19, minute=8)
self.case.set_case_property('start_sending', 'ok')
self.case.save()
CaseReminderHandler.fire_reminders()
reminder = self.handler.get_reminder(self.case)
self.assertNotEqual(reminder, None)
self.assertEqual(
reminder.next_fire,
CaseReminderHandler.now + timedelta(days=self.handler.start_offset)
)
self.assertEqual(reminder.last_fired, None)
# fire a day after created
CaseReminderHandler.now = datetime(year=2011, month=7, day=8, hour=19, minute=8)
self.case.set_case_property('irrelevant_1', 'ok')
self.case.save()
CaseReminderHandler.fire_reminders()
reminder = self.handler.get_reminder(self.case)
self.assertNotEqual(reminder, None)
self.assertEqual(
reminder.next_fire,
CaseReminderHandler.now + timedelta(days=self.handler.schedule_length)
)
self.assertEqual(reminder.last_fired, CaseReminderHandler.now)
# Shouldn't fire until three days after created
last_fired = CaseReminderHandler.now
CaseReminderHandler.now = datetime(year=2011, month=7, day=9, hour=19, minute=8)
CaseReminderHandler.fire_reminders()
reminder = self.handler.get_reminder(self.case)
self.assertNotEqual(reminder, None)
self.assertEqual(reminder.last_fired, last_fired)
self.assertEqual(
reminder.next_fire,
last_fired + timedelta(days=self.handler.schedule_length)
)
# fire three days after last fired
CaseReminderHandler.now = datetime(year=2011, month=7, day=11, hour=19, minute=8)
self.case.set_case_property('irrelevant_2', 'ok')
self.case.save()
CaseReminderHandler.fire_reminders()
reminder = self.handler.get_reminder(self.case)
self.assertNotEqual(reminder, None)
self.assertEqual(
reminder.next_fire,
CaseReminderHandler.now + timedelta(days=self.handler.schedule_length)
)
self.assertEqual(reminder.last_fired, CaseReminderHandler.now)
#.........这里部分代码省略.........
示例15: ReminderCallbackTestCase
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import set_case_property [as 别名]
class ReminderCallbackTestCase(BaseReminderTestCase):
"""
This use case represents a reminder schedule with an expected callback:
Day1: 10:00 Callback Message 1 [simple reminder]
Day1: 11:00 Callback Message 2 [expects callback]
Day1: 11:15 Callback Message 2 [15-minute timeout if callback is not received]
Day1: 11:45 Callback Message 2 [30-minute timeout if callback is not received]
Day2: (same as Day1)
Day3: (same as Day1)
This case also tests handling of time zones using the timezone of Africa/Nairobi (UTC+3).
"""
def setUp(self):
super(ReminderCallbackTestCase, self).setUp()
self.domain = "test"
self.case_type = "my_case_type"
self.message_1 = "Callback Message 1"
self.message_2 = "Callback Message 2"
self.handler = CaseReminderHandler(
domain=self.domain,
case_type=self.case_type,
method=METHOD_SMS_CALLBACK,
start_property='start_sending',
start_value=None,
start_date=None,
start_offset=0,
start_match_type=MATCH_ANY_VALUE,
until='stop_sending',
default_lang='en',
max_iteration_count=3,
schedule_length=1,
event_interpretation=EVENT_AS_SCHEDULE,
events = [
CaseReminderEvent(
day_num = 0
,fire_time = time(10,00,00)
,message={"en":self.message_1}
,callback_timeout_intervals=[]
)
,CaseReminderEvent(
day_num = 0
,fire_time = time(11,00,00)
,message={"en":self.message_2}
,callback_timeout_intervals=[15,30]
)
]
)
self.handler.save()
self.user_id = "USER-ID-109349"
self.user = CommCareUser.create(self.domain, 'chw.bob3', '****', uuid=self.user_id, phone_number="99912345")
self.user.user_data["time_zone"]="Africa/Nairobi"
self.user.save()
self.case = CommCareCase(
domain=self.domain,
type=self.case_type,
user_id=self.user_id
)
self.case.save()
self.user.save_verified_number("test", "14445551234", True, None)
def tearDown(self):
self.user.delete()
super(ReminderCallbackTestCase, self).tearDown()
def test_ok(self):
self.assertEqual(self.handler.get_reminder(self.case), None)
# Spawn CaseReminder
CaseReminderHandler.now = datetime(year=2011, month=12, day=31, hour=23, minute=0)
self.case.set_case_property('start_sending', 'ok')
self.case.save()
reminder = self.handler.get_reminder(self.case)
self.assertNotEqual(reminder, None)
self.assertEqual(reminder.next_fire, datetime(year=2012, month=1, day=1, hour=7, minute=0))
self.assertEqual(reminder.start_date, date(year=2012, month=1, day=1))
self.assertEqual(reminder.schedule_iteration_num, 1)
self.assertEqual(reminder.current_event_sequence_num, 0)
self.assertEqual(reminder.last_fired, None)
######################
# Day1, 10:00 reminder
CaseReminderHandler.now = datetime(year=2012, month=1, day=1, hour=7, minute=0)
CaseReminderHandler.fire_reminders()
reminder = self.handler.get_reminder(self.case)
self.assertNotEqual(reminder, None)
self.assertEqual(reminder.next_fire, datetime(year=2012, month=1, day=1, hour=8, minute=0))
self.assertEqual(reminder.schedule_iteration_num, 1)
self.assertEqual(reminder.current_event_sequence_num, 1)
self.assertEqual(reminder.last_fired, CaseReminderHandler.now)
# Day1, 11:00 reminder
CaseReminderHandler.now = datetime(year=2012, month=1, day=1, hour=8, minute=1)
CaseReminderHandler.fire_reminders()
reminder = self.handler.get_reminder(self.case)
self.assertNotEqual(reminder, None)
self.assertEqual(reminder.next_fire, datetime(year=2012, month=1, day=1, hour=8, minute=15))
self.assertEqual(reminder.schedule_iteration_num, 1)
#.........这里部分代码省略.........