Example #1
0
 def test_close_with_timeout(self, mock_post):
     mock_post.side_effect = Timeout(self.error_msg)
     with app.app_context() as ac:
         ac.g.trace_id = None
         ac.g.requests = requests.Session()
         with app.test_request_context():
             with self.assertRaises(ApplicationError) as context:
                 AccountAPI.close(self, '1234-567-890', '0987-654-321', 'customer')
                 self.assertTrue(ApplicationError in str(context.exception))
             self.assertEqual(context.exception.message,
                              'Connection to account_api timed out: {}'.format(self.error_msg))
             self.assertEqual(context.exception.code, 'E503')
             self.assertEqual(context.exception.http_code, 500)
Example #2
0
    def test_close_connection_error(self, mock_post):
        with app.app_context() as ac:
            ac.g.trace_id = None
            ac.g.requests = requests.Session()
            with app.test_request_context():
                mock_post.side_effect = ConnectionError(self.error_msg)

                with self.assertRaises(ApplicationError) as context:
                    AccountAPI.close(self, '1234-567-890', '0987-654-321', 'customer')

                self.assertEqual(context.exception.message,
                                 'Encountered an error connecting to account_api: {}'.format(self.error_msg))
                self.assertEqual(context.exception.code, 'E502')
                self.assertEqual(context.exception.http_code, 500)
Example #3
0
    def test_close_http_error(self, mock_post):
        with app.app_context() as ac:
            ac.g.trace_id = None
            ac.g.requests = requests.Session()
            with app.test_request_context():
                mock_post.side_effect = HTTPError(self.error_msg)

                with self.assertRaises(ApplicationError) as context:
                    AccountAPI.close(self, '1234-567-890', '0987-654-321', 'customer')

                self.assertEqual(context.exception.message,
                                 'Received the following response from account_api: {}'.format(self.error_msg))
                self.assertEqual(context.exception.code, 'E501')
                self.assertEqual(context.exception.http_code, 500)
Example #4
0
 def test_close(self, mock_post):
     with app.app_context() as ac:
         ac.g.trace_id = None
         ac.g.requests = requests.Session()
         with app.test_request_context():
             mock_post.return_value.text = 'Success'
             mock_post.return_value.status_code = 200
             response = AccountAPI.close(self, '1234-567-890', '0987-654-321', 'customer')
             assert response == {'message': 'closed'}