How to use the pdpyras.RequestsError function in pdpyras

To help you get started, we’ve selected a few pdpyras examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PagerDuty / pdpyras / test_pdpyras.py View on Github external
# Test getting a connection error and succeeding the final time.
                returns = [
                    pdpyras.Urllib3Error("D'oh!")
                ]*sess.max_network_attempts
                returns.append(Response(200, json.dumps({'user': user})))
                request.side_effect = returns
                r = sess.get('/users/P123456')
                self.assertEqual(sess.max_network_attempts+1,
                    request.call_count)
                self.assertEqual(sess.max_network_attempts, sleep.call_count)
                self.assertTrue(r.ok)
                request.reset_mock()
                sleep.reset_mock()

                # Now test handling a non-transient error:
                raises = [pdpyras.RequestsError("D'oh!")]*(
                    sess.max_network_attempts-1)
                raises.extend([pdpyras.Urllib3Error("D'oh!")]*2)
                request.side_effect = raises
                self.assertRaises(pdpyras.PDClientError, sess.get, '/users')
                self.assertEqual(sess.max_network_attempts+1,
                    request.call_count)
                self.assertEqual(sess.max_network_attempts, sleep.call_count)

                # Test custom retry logic:
                sess.retry[404] = 3
                request.side_effect = [
                    Response(404, json.dumps({})),
                    Response(404, json.dumps({})),
                    Response(200, json.dumps({'user': user})),
                ]
                r = sess.get('/users/P123456')