class TestRepeaterPause(BaseRepeaterTest): domain = 'rep-pause' def setUp(self): super().setUp() self.connx = ConnectionSettings.objects.create( domain=self.domain, url='case-repeater-url', ) self.repeater = CaseRepeater( domain=self.domain, connection_settings_id=self.connx.id, ) self.repeater.save() self.post_xml(self.xform_xml, self.domain) self.repeater = reloaded(self.repeater) def tearDown(self): self.repeater.delete() self.connx.delete() FormProcessorTestUtils.delete_all_cases_forms_ledgers(self.domain) delete_all_repeat_records() super(TestRepeaterPause, self).tearDown() @run_with_all_backends def test_trigger_when_paused(self): # not paused with patch.object(RepeatRecord, 'fire') as mock_fire: with patch.object(RepeatRecord, 'postpone_by') as mock_postpone_fire: # calls process_repeat_record(): self.repeat_record = self.repeater.register( CaseAccessors(self.domain_obj).get_case(CASE_ID)) self.assertEqual(mock_fire.call_count, 1) self.assertEqual(mock_postpone_fire.call_count, 0) # paused self.repeater.pause() # re fetch repeat record repeat_record_id = self.repeat_record.get_id self.repeat_record = RepeatRecord.get(repeat_record_id) process_repeat_record(self.repeat_record) self.assertEqual(mock_fire.call_count, 1) self.assertEqual(mock_postpone_fire.call_count, 1) # resumed self.repeater.resume() # re fetch repeat record repeat_record_id = self.repeat_record.get_id self.repeat_record = RepeatRecord.get(repeat_record_id) process_repeat_record(self.repeat_record) self.assertEqual(mock_fire.call_count, 2) self.assertEqual(mock_postpone_fire.call_count, 1)
class TestRepeaterPause(BaseRepeaterTest): def setUp(self): super(TestRepeaterPause, self).setUp() self.domain_name = "test-domain" self.domain = create_domain(self.domain_name) self.repeater = CaseRepeater( domain=self.domain_name, url='case-repeater-url', ) self.repeater.save() self.post_xml(self.xform_xml, self.domain_name) self.repeat_record = self.repeater.register( CaseAccessors(self.domain).get_case(CASE_ID)) @run_with_all_backends @flag_enabled('ENABLE_REPEATER_EDIT_AND_PAUSE') def test_trigger_when_paused(self): # not paused with patch.object(RepeatRecord, 'fire') as mock_fire: with patch.object(RepeatRecord, 'postpone_by') as mock_postpone_fire: process_repeat_record(self.repeat_record) self.assertEqual(mock_fire.call_count, 1) self.assertEqual(mock_postpone_fire.call_count, 0) # paused self.repeater.pause() # re fetch repeat record repeat_record_id = self.repeat_record.get_id self.repeat_record = RepeatRecord.get(repeat_record_id) process_repeat_record(self.repeat_record) self.assertEqual(mock_fire.call_count, 1) self.assertEqual(mock_postpone_fire.call_count, 1) # resumed self.repeater.resume() # re fetch repeat record repeat_record_id = self.repeat_record.get_id self.repeat_record = RepeatRecord.get(repeat_record_id) process_repeat_record(self.repeat_record) self.assertEqual(mock_fire.call_count, 2) self.assertEqual(mock_postpone_fire.call_count, 1) def tearDown(self): self.domain.delete() self.repeater.delete() delete_all_repeat_records() super(TestRepeaterPause, self).tearDown()
class TestRepeaterDeleted(BaseRepeaterTest): domain = 'rep-deleted' def setUp(self): super().setUp() self.connx = ConnectionSettings.objects.create( domain=self.domain, url='case-repeater-url', ) self.repeater = CaseRepeater( domain=self.domain, connection_settings_id=self.connx.id, format='case_json', ) self.repeater.save() self.post_xml(self.xform_xml, self.domain) self.repeater = reloaded(self.repeater) def tearDown(self): self.repeater.delete() # Making sure that SQL repeater are deleted after retire is called. SQLRepeater.all_objects.all().delete() self.connx.delete() FormProcessorTestUtils.delete_all_cases_forms_ledgers(self.domain) delete_all_repeat_records() super().tearDown() def test_trigger_when_deleted(self): self.repeater.retire() with patch.object(RepeatRecord, 'fire') as mock_fire: self.repeat_record = self.repeater.register( CommCareCase.objects.get_case(CASE_ID, self.domain)) _process_repeat_record(self.repeat_record) self.assertEqual(mock_fire.call_count, 0) self.assertEqual(self.repeat_record.doc_type, "RepeatRecord-Deleted") def test_paused_then_deleted(self): self.repeater.pause() self.repeater.retire() with patch.object(RepeatRecord, 'fire') as mock_fire: self.repeat_record = self.repeater.register( CommCareCase.objects.get_case(CASE_ID, self.domain)) _process_repeat_record(self.repeat_record) self.assertEqual(mock_fire.call_count, 0) self.assertEqual(self.repeat_record.doc_type, "RepeatRecord-Deleted")
class TestRepeaterDeleted(BaseRepeaterTest): domain = 'rep-deleted' def setUp(self): super().setUp() self.connx = ConnectionSettings.objects.create( domain=self.domain, url='case-repeater-url', ) self.repeater = CaseRepeater( domain=self.domain, connection_settings_id=self.connx.id, ) self.repeater.save() self.post_xml(self.xform_xml, self.domain) self.repeater = reloaded(self.repeater) def tearDown(self): self.repeater.delete() self.connx.delete() FormProcessorTestUtils.delete_all_cases_forms_ledgers(self.domain) delete_all_repeat_records() super().tearDown() @run_with_all_backends def test_trigger_when_deleted(self): self.repeater.retire() with patch.object(RepeatRecord, 'fire') as mock_fire: self.repeat_record = self.repeater.register( CaseAccessors(self.domain_obj).get_case(CASE_ID)) process_repeat_record(self.repeat_record) self.assertEqual(mock_fire.call_count, 0) self.assertEqual(self.repeat_record.doc_type, "RepeatRecord-Deleted") @run_with_all_backends def test_paused_then_deleted(self): self.repeater.pause() self.repeater.retire() with patch.object(RepeatRecord, 'fire') as mock_fire: self.repeat_record = self.repeater.register( CaseAccessors(self.domain_obj).get_case(CASE_ID)) process_repeat_record(self.repeat_record) self.assertEqual(mock_fire.call_count, 0) self.assertEqual(self.repeat_record.doc_type, "RepeatRecord-Deleted")
class TestRepeaterPause(BaseRepeaterTest): def setUp(self): super(TestRepeaterPause, self).setUp() self.domain_name = "test-domain" self.domain = create_domain(self.domain_name) self.repeater = CaseRepeater( domain=self.domain_name, url='case-repeater-url', ) self.repeater.save() self.post_xml(self.xform_xml, self.domain_name) @run_with_all_backends def test_trigger_when_paused(self): # not paused with patch.object(RepeatRecord, 'fire') as mock_fire: with patch.object(RepeatRecord, 'postpone_by') as mock_postpone_fire: # calls process_repeat_record(): self.repeat_record = self.repeater.register(CaseAccessors(self.domain).get_case(CASE_ID)) self.assertEqual(mock_fire.call_count, 1) self.assertEqual(mock_postpone_fire.call_count, 0) # paused self.repeater.pause() # re fetch repeat record repeat_record_id = self.repeat_record.get_id self.repeat_record = RepeatRecord.get(repeat_record_id) process_repeat_record(self.repeat_record) self.assertEqual(mock_fire.call_count, 1) self.assertEqual(mock_postpone_fire.call_count, 1) # resumed self.repeater.resume() # re fetch repeat record repeat_record_id = self.repeat_record.get_id self.repeat_record = RepeatRecord.get(repeat_record_id) process_repeat_record(self.repeat_record) self.assertEqual(mock_fire.call_count, 2) self.assertEqual(mock_postpone_fire.call_count, 1) def tearDown(self): self.domain.delete() self.repeater.delete() delete_all_repeat_records() super(TestRepeaterPause, self).tearDown()
class TestRepeaterDeleted(BaseRepeaterTest): def setUp(self): super(TestRepeaterDeleted, self).setUp() self.domain_name = "test-domain" self.domain = create_domain(self.domain_name) self.repeater = CaseRepeater( domain=self.domain_name, url='case-repeater-url', ) self.repeater.save() self.post_xml(self.xform_xml, self.domain_name) def tearDown(self): self.domain.delete() self.repeater.delete() delete_all_repeat_records() super(TestRepeaterDeleted, self).tearDown() @run_with_all_backends def test_trigger_when_deleted(self): self.repeater.retire() with patch.object(RepeatRecord, 'fire') as mock_fire: self.repeat_record = self.repeater.register( CaseAccessors(self.domain).get_case(CASE_ID)) process_repeat_record(self.repeat_record) self.assertEqual(mock_fire.call_count, 0) self.assertEqual(self.repeat_record.doc_type, "RepeatRecord-Deleted") @run_with_all_backends def test_paused_then_deleted(self): self.repeater.pause() self.repeater.retire() with patch.object(RepeatRecord, 'fire') as mock_fire: self.repeat_record = self.repeater.register( CaseAccessors(self.domain).get_case(CASE_ID)) process_repeat_record(self.repeat_record) self.assertEqual(mock_fire.call_count, 0) self.assertEqual(self.repeat_record.doc_type, "RepeatRecord-Deleted")
class TestRepeaterDeleted(BaseRepeaterTest): def setUp(self): super(TestRepeaterDeleted, self).setUp() self.domain_name = "test-domain" self.domain = create_domain(self.domain_name) self.repeater = CaseRepeater( domain=self.domain_name, url='case-repeater-url', ) self.repeater.save() self.post_xml(self.xform_xml, self.domain_name) def tearDown(self): self.domain.delete() self.repeater.delete() delete_all_repeat_records() super(TestRepeaterDeleted, self).tearDown() @run_with_all_backends def test_trigger_when_deleted(self): self.repeater.retire() with patch.object(RepeatRecord, 'fire') as mock_fire: self.repeat_record = self.repeater.register(CaseAccessors(self.domain).get_case(CASE_ID)) process_repeat_record(self.repeat_record) self.assertEqual(mock_fire.call_count, 0) self.assertEqual(self.repeat_record.doc_type, "RepeatRecord-Deleted") @run_with_all_backends def test_paused_then_deleted(self): self.repeater.pause() self.repeater.retire() with patch.object(RepeatRecord, 'fire') as mock_fire: self.repeat_record = self.repeater.register(CaseAccessors(self.domain).get_case(CASE_ID)) process_repeat_record(self.repeat_record) self.assertEqual(mock_fire.call_count, 0) self.assertEqual(self.repeat_record.doc_type, "RepeatRecord-Deleted")