예제 #1
0
 def test_rest_action_connection(self):
     """Test the rest timeout indefinitely"""
     # This will try to actually connect to an invalid service
     test_base = Base(self.CERT, self.URLBASE)
     rest_function = test_base._session.get
     with self.assertRaises(requests.ConnectionError):
         test_base.rest_action(rest_function, self.URLBASE)
예제 #2
0
 def test_rest_action_not_json(self):
     """Test the rest timeout indefinitely"""
     self._register_uri(body='stuff')
     test_base = Base(self.CERT, self.URLBASE)
     rest_function = test_base._session.get
     with self.assertRaises(ValueError):
         test_base.rest_action(rest_function, self.URLBASE)
예제 #3
0
 def test_rest_action_timeout(self):
     """Test the rest timeout indefinitely"""
     self._register_uri(timeout=True)
     test_base = Base(self.CERT, self.URLBASE)
     rest_function = test_base._session.get
     with self.assertRaisesRegexp(
         requests.ConnectionError,
         'Max retries exceeded with url'
     ):
         test_base.rest_action(rest_function, self.URLBASE)
예제 #4
0
 def test_rest_action_success(self):
     """Test the rest action"""
     payload = {'a': 'b'}
     self._register_uri(body=json.dumps(payload))
     test_base = Base(self.CERT, self.URLBASE)
     rest_function = test_base._session.get
     response = test_base.rest_action(rest_function, self.URLBASE)
     self.assertEqual(payload, response)
예제 #5
0
 def test_rest_action_success_eventually(self):
     """Wait some time and then succeed"""
     payload = {'a': 'b'}
     self._register_uri(
         responses=[
             httpretty.Response(body=raise_timeout),
             httpretty.Response(body=raise_timeout),
             httpretty.Response(body=json.dumps(payload)),
         ]
     )
     test_base = Base(self.CERT, self.URLBASE)
     rest_function = test_base._session.get
     response = test_base.rest_action(rest_function, self.URLBASE)
     self.assertEqual(payload, response)