summaryrefslogtreecommitdiff
path: root/src/etcd/tests/unit/test_old_request.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/etcd/tests/unit/test_old_request.py')
-rw-r--r--src/etcd/tests/unit/test_old_request.py69
1 files changed, 20 insertions, 49 deletions
diff --git a/src/etcd/tests/unit/test_old_request.py b/src/etcd/tests/unit/test_old_request.py
index 9367ebd..0d43713 100644
--- a/src/etcd/tests/unit/test_old_request.py
+++ b/src/etcd/tests/unit/test_old_request.py
@@ -10,40 +10,21 @@ from etcd import EtcdException
class FakeHTTPResponse(object):
- def __init__(self, status, data=''):
+ def __init__(self, status, data='', headers=None):
self.status = status
self.data = data.encode('utf-8')
+ self.headers = headers or {
+ "x-etcd-cluster-id": "abdef12345",
+ }
def getheaders(self):
- return {}
+ return self.headers
-class TestClientRequest(unittest.TestCase):
+ def getheader(self, header):
+ return self.headers[header]
- def test_machines(self):
- """ Can request machines """
- client = etcd.Client()
- client.api_execute = mock.Mock(
- return_value=FakeHTTPResponse(200, data=
- "http://127.0.0.1:4002,"
- " http://127.0.0.1:4001,"
- " http://127.0.0.1:4003,"
- " http://127.0.0.1:4001")
- )
- assert client.machines == [
- 'http://127.0.0.1:4002',
- 'http://127.0.0.1:4001',
- 'http://127.0.0.1:4003',
- 'http://127.0.0.1:4001'
- ]
-
- def test_leader(self):
- """ Can request the leader """
- client = etcd.Client()
- client.api_execute = mock.Mock(
- return_value=FakeHTTPResponse(200, "http://127.0.0.1:7002"))
- result = client.leader
- self.assertEquals('http://127.0.0.1:7002', result)
+class TestClientRequest(unittest.TestCase):
def test_set(self):
""" Can set a value """
@@ -332,21 +313,7 @@ class TestClientApiExecutor(unittest.TestCase):
except ValueError as e:
self.assertEquals('message : cause', str(e))
- def test_set_error(self):
- """ http post error request 102 """
- client = etcd.Client()
- response = FakeHTTPResponse(
- status=400,
- data='{"message": "message", "cause": "cause", "errorCode": 102}')
- client.http.request_encode_body = mock.Mock(return_value=response)
- payload = {'value': 'value', 'prevValue': 'oldValue', 'ttl': '60'}
- try:
- client.api_execute('/v2/keys/testkey', client._MPUT, payload)
- self.fail()
- except KeyError as e:
- self.assertEquals('message : cause', str(e))
-
- def test_set_error(self):
+ def test_set_not_file_error(self):
""" http post error request 102 """
client = etcd.Client()
response = FakeHTTPResponse(
@@ -365,23 +332,27 @@ class TestClientApiExecutor(unittest.TestCase):
client = etcd.Client()
response = FakeHTTPResponse(status=400,
data='{"message": "message",'
- ' "cause": "cause",'
- ' "errorCode": 42}')
+ ' "cause": "cause",'
+ ' "errorCode": 42}')
client.http.request = mock.Mock(return_value=response)
try:
client.api_execute('/v2/keys/testkey', client._MGET)
self.fail()
except etcd.EtcdException as e:
- self.assertTrue(
- str(e).startswith("Unable to decode server response"))
+ self.assertEqual(str(e), "message : cause")
def test_get_error_request_invalid(self):
""" http get error request invalid """
client = etcd.Client()
- response = FakeHTTPResponse(status=200,
- data='{){){)*garbage*')
+ response = FakeHTTPResponse(status=400,
+ data='{)*garbage')
client.http.request = mock.Mock(return_value=response)
- self.assertRaises(etcd.EtcdException, client.get, '/testkey')
+ try:
+ client.api_execute('/v2/keys/testkey', client._MGET)
+ self.fail()
+ except etcd.EtcdException as e:
+ self.assertEqual(str(e),
+ "Bad response : {)*garbage")
def test_get_error_invalid(self):
""" http get error request invalid """