Ejemplo n.º 1
0
class TestHTTPClient(unittest.TestCase):
    def setUp(self):
        self.client = HTTPClient('127.0.0.1', '8500', 'http', False)
        self.client.http.request = Mock()

    def test_get(self):
        self.client.get(Mock(), '')
        self.client.get(Mock(), '', {'wait': '1s', 'index': 1, 'token': 'foo'})
        self.client.http.request.return_value.status = 500
        self.client.http.request.return_value.data = b'Foo'
        self.assertRaises(ConsulInternalError, self.client.get, Mock(), '')
        self.client.http.request.return_value.data = b"Invalid Session TTL '3000000000', must be between [10s=24h0m0s]"
        self.assertRaises(InvalidSessionTTL, self.client.get, Mock(), '')

    def test_unknown_method(self):
        try:
            self.client.bla(Mock(), '')
            self.assertFail()
        except Exception as e:
            self.assertTrue(isinstance(e, AttributeError))

    def test_put(self):
        self.client.put(Mock(), '/v1/session/create')
        self.client.put(Mock(),
                        '/v1/session/create',
                        params=[],
                        data='{"foo": "bar"}')
Ejemplo n.º 2
0
class TestHTTPClient(unittest.TestCase):

    def test_get(self):
        self.client = HTTPClient('127.0.0.1', '8500', 'http', False)
        self.client.session.get = Mock()
        self.client.get(Mock(), '')
        self.client.get(Mock(), '', {'wait': '1s', 'index': 1})
Ejemplo n.º 3
0
class TestHTTPClient(unittest.TestCase):

    def setUp(self):
        self.client = HTTPClient('127.0.0.1', '8500', 'http', False)
        self.client.http.request = Mock()

    def test_get(self):
        self.client.get(Mock(), '')
        self.client.get(Mock(), '', {'wait': '1s', 'index': 1, 'token': 'foo'})
        self.client.http.request.return_value.status = 500
        self.client.http.request.return_value.data = b'Foo'
        self.assertRaises(ConsulInternalError, self.client.get, Mock(), '')
        self.client.http.request.return_value.data = b"Invalid Session TTL '3000000000', must be between [10s=24h0m0s]"
        self.assertRaises(InvalidSessionTTL, self.client.get, Mock(), '')

    def test_unknown_method(self):
        try:
            self.client.bla(Mock(), '')
            self.assertFail()
        except Exception as e:
            self.assertTrue(isinstance(e, AttributeError))

    def test_put(self):
        self.client.put(Mock(), '/v1/session/create')
        self.client.put(Mock(), '/v1/session/create', data='{"foo": "bar"}')
Ejemplo n.º 4
0
 def test_get(self):
     client = HTTPClient('127.0.0.1', '8500', 'http', False)
     client.http.request = Mock()
     client.get(Mock(), '')
     client.get(Mock(), '', {'wait': '1s', 'index': 1})
     client.http.request.return_value.status = 500
     self.assertRaises(ConsulInternalError, client.get, Mock(), '')
     try:
         client.bla(Mock(), '')
         self.assertFail()
     except Exception as e:
         self.assertTrue(isinstance(e, AttributeError))
Ejemplo n.º 5
0
class TestHTTPClient(unittest.TestCase):
    def setUp(self):
        self.client = HTTPClient('127.0.0.1', '8500', 'http', False)
        self.client.http.request = Mock()

    def test_get(self):
        self.client.get(Mock(), '')
        self.client.get(Mock(), '', {'wait': '1s', 'index': 1})
        self.client.http.request.return_value.status = 500
        self.assertRaises(ConsulInternalError, self.client.get, Mock(), '')

    def test_unknown_method(self):
        try:
            self.client.bla(Mock(), '')
            self.assertFail()
        except Exception as e:
            self.assertTrue(isinstance(e, AttributeError))

    def test_put(self):
        self.client.put(Mock(), '/v1/session/create')
        self.client.put(Mock(), '/v1/session/create', data='{"foo": "bar"}')
Ejemplo n.º 6
0
 def setUp(self):
     self.client = HTTPClient('127.0.0.1', '8500', 'http', False)
     self.client.http.request = Mock()
Ejemplo n.º 7
0
 def setUp(self):
     self.client = HTTPClient('127.0.0.1', '8500', 'http', False)
     self.client.http.request = Mock()