def test_repeat_record_created(self): ''' Tests that whenever an application with a repeater is saved that a repeat record is created. ''' application = Application(domain=self.domain) application.save() repeat_records = RepeatRecord.all(domain=self.domain, due_before=datetime.utcnow()) self.assertEqual(len(repeat_records), 0) app_structure_repeater = AppStructureRepeater(domain=self.domain, url=self.forwarding_url) app_structure_repeater.save() application.save() repeat_records = RepeatRecord.all(domain=self.domain, due_before=datetime.utcnow()) self.assertEqual(len(repeat_records), 1) for repeat_record in repeat_records: self.assertEqual(repeat_record.url, self.forwarding_url) self.assertEqual(repeat_record.get_payload(), application.get_id) repeat_record.delete() application.delete() app_structure_repeater.delete()
def test_repeat_record_forwarded(self): """ When an application with a repeater is saved, then HQ should try to forward the repeat record """ self.app_structure_repeater = AppStructureRepeater(domain=self.domain, url=self.forwarding_url) self.app_structure_repeater.save() self.addCleanup(self.app_structure_repeater.delete) with patch('corehq.motech.repeaters.models.simple_post') as mock_fire: self.application = Application(domain=self.domain) self.application.save() self.addCleanup(self.application.delete) self.assertEqual(mock_fire.call_count, 1)
def test_repeat_record_created(self): """ When an application with a repeater is saved, then a repeat record should be created """ self.app_structure_repeater = AppStructureRepeater(domain=self.domain, url=self.forwarding_url) self.app_structure_repeater.save() self.addCleanup(self.app_structure_repeater.delete) self.application = Application(domain=self.domain) self.application.save() self.addCleanup(self.application.delete) later = datetime.utcnow() + timedelta(hours=48 + 1) repeat_records = RepeatRecord.all(domain=self.domain, due_before=later) self.assertEqual(len(repeat_records), 1)