Esempio n. 1
0
 def setUpClass(cls):
     cls.records = [
         RepeatRecord(domain='a'),
         RepeatRecord(domain='b'),
         RepeatRecord(domain='c'),
     ]
     RepeatRecord.bulk_save(cls.records)
Esempio n. 2
0
    def test_get_all_repeat_records_by_domain_since(self):
        new_records = [
            # FAIL
            RepeatRecord(
                domain=self.domain,
                repeater_id=self.repeater_id,
                last_checked=datetime(2017, 5, 24, 0, 0, 0),
                failure_reason='some error',
            ),
            # CANCELLED
            RepeatRecord(
                domain=self.domain,
                repeater_id=self.repeater_id,
                last_checked=datetime(2017, 5, 10, 0, 0, 0),
                cancelled=True,
            ),
            # CANCELLED
            RepeatRecord(
                domain=self.domain,
                repeater_id=self.repeater_id,
                last_checked=datetime(2017, 5, 24, 0, 0, 0),
                cancelled=True,
            ),
        ]
        RepeatRecord.bulk_save(new_records)
        self.addCleanup(RepeatRecord.bulk_delete, new_records)

        records = list(
            iter_repeat_records_by_domain(self.domain,
                                          state=RECORD_CANCELLED_STATE,
                                          since=datetime(2017, 5, 20)))
        self.assertEqual(len(records), 1)
        record, = records
        self.assertEqual(record.to_json(), new_records[-1].to_json())
    def test_update_failure_next_check(self):
        now = datetime.utcnow()
        record = RepeatRecord(domain=self.domain, next_check=now)
        self.assertIsNone(record.last_checked)

        record.set_next_try()
        self.assertTrue(record.last_checked > now)
        self.assertEqual(record.next_check, record.last_checked + MIN_RETRY_WAIT)
Esempio n. 4
0
    def test_update_failure_next_check(self):
        now = datetime.utcnow()
        record = RepeatRecord(domain=self.domain, next_check=now)
        self.assertIsNone(record.last_checked)

        attempt = record.make_set_next_try_attempt(None)
        record.add_attempt(attempt)
        self.assertTrue(record.last_checked > now)
        self.assertEqual(record.next_check, record.last_checked + MIN_RETRY_WAIT)
Esempio n. 5
0
    def setUpClass(cls):
        before = datetime.utcnow() - timedelta(minutes=5)

        failed = RepeatRecord(
            domain=cls.domain,
            failure_reason='Some python error',
            repeater_id=cls.repeater_id,
            next_check=before,
        )
        success = RepeatRecord(
            domain=cls.domain,
            succeeded=True,
            repeater_id=cls.repeater_id,
            next_check=before,
        )
        pending = RepeatRecord(
            domain=cls.domain,
            succeeded=False,
            repeater_id=cls.repeater_id,
            next_check=before,
        )
        overdue = RepeatRecord(
            domain=cls.domain,
            succeeded=False,
            repeater_id=cls.repeater_id,
            next_check=before - timedelta(minutes=10),
        )
        other_id = RepeatRecord(
            domain=cls.domain,
            succeeded=False,
            repeater_id=cls.other_id,
            next_check=before,
        )

        cls.records = [
            failed,
            success,
            pending,
            overdue,
            other_id,
        ]

        for record in cls.records:
            record.save()
Esempio n. 6
0
 def setUp(self):
     super(TestBetsResponseHandling, self).setUp()
     user = CommCareUser.create(
         self.domain,
         "*****@*****.**",
         "123",
     )
     self.repeater = BETSUserRepeater(
         domain=self.domain,
         url='super-cool-url',
     )
     self.repeater.save()
     self.repeat_record = RepeatRecord(
         repeater_id=self.repeater.get_id,
         payload_id=user.user_id,
         next_check=datetime.utcnow(),
     )