Ejemplo n.º 1
0
    def test_backoff_on_connection_error(self):
        with patch('corehq.motech.repeaters.models.simple_post') as simple_post:
            simple_post.side_effect = ConnectionError()

            payload = self.repeater.get_payload(self.repeat_record)
            send_request(self.repeater, self.repeat_record, payload)

            self.assertEqual(self.repeat_record.attempts.last().state,
                             RECORD_FAILURE_STATE)
            repeater_stub = self.reget_repeater_stub()
            self.assertIsNotNone(repeater_stub.next_attempt_at)
Ejemplo n.º 2
0
    def test_success_on_200(self):
        resp = ResponseMock(status_code=200, reason='OK')
        with patch('corehq.motech.repeaters.models.simple_post') as simple_post:
            simple_post.return_value = resp

            payload = self.repeater.get_payload(self.repeat_record)
            send_request(self.repeater, self.repeat_record, payload)

            self.assertEqual(self.repeat_record.attempts.last().state,
                             RECORD_SUCCESS_STATE)
            repeater_stub = self.reget_repeater_stub()
            self.assertIsNone(repeater_stub.next_attempt_at)
Ejemplo n.º 3
0
    def test_backoff_on_503(self):
        resp = ResponseMock(status_code=503, reason='Service Unavailable')
        with patch('corehq.motech.repeaters.models.simple_post') as simple_post:
            simple_post.return_value = resp

            payload = self.repeater.get_payload(self.repeat_record)
            send_request(self.repeater, self.repeat_record, payload)

            self.assertEqual(self.repeat_record.attempts.last().state,
                             RECORD_FAILURE_STATE)
            repeater_stub = self.reget_repeater_stub()
            self.assertIsNotNone(repeater_stub.next_attempt_at)
Ejemplo n.º 4
0
    def test_no_backoff_on_409(self):
        resp = ResponseMock(status_code=409, reason='Conflict')
        with patch('corehq.motech.repeaters.models.simple_post') as simple_post:
            simple_post.return_value = resp

            payload = self.repeater.get_payload(self.repeat_record)
            send_request(self.repeater, self.repeat_record, payload)

            self.assertEqual(self.repeat_record.attempts.last().state,
                             RECORD_FAILURE_STATE)
            repeater_stub = self.reget_repeater_stub()
            # Trying tomorrow is just as likely to work as in 5 minutes
            self.assertIsNone(repeater_stub.next_attempt_at)
Ejemplo n.º 5
0
    def test_no_backoff_on_500(self):
        resp = ResponseMock(status_code=500, reason='Internal Server Error')
        with patch('corehq.motech.repeaters.models.simple_request'
                   ) as simple_request:
            simple_request.return_value = resp

            payload = self.repeater.get_payload(self.repeat_record)
            send_request(self.repeater, self.repeat_record, payload)

            self.assertEqual(self.repeat_record.attempts.last().state,
                             RECORD_FAILURE_STATE)
            sql_repeater = self.reget_sql_repeater()
            self.assertIsNone(sql_repeater.next_attempt_at)