|
3 | 3 | import dns.name |
4 | 4 | import dns.rdtypes.IN.SRV |
5 | 5 | import dns.resolver |
| 6 | +from etcd.tests.unit import TestClientApiBase |
6 | 7 | try: |
7 | 8 | import mock |
8 | 9 | except ImportError: |
9 | 10 | from unittest import mock |
10 | 11 |
|
11 | 12 |
|
12 | | -class TestClient(unittest.TestCase): |
| 13 | +class TestClient(TestClientApiBase): |
| 14 | + |
13 | 15 |
|
14 | 16 | def test_instantiate(self): |
15 | 17 | """ client can be instantiated""" |
@@ -123,55 +125,37 @@ def test_get_headers_with_auth(self): |
123 | 125 |
|
124 | 126 | def test__set_version_info(self): |
125 | 127 | """Verify _set_version_info makes the proper call to the server""" |
126 | | - with mock.patch('urllib3.PoolManager') as _pm: |
127 | | - _request = _pm().request |
128 | | - # Return the expected data type |
129 | | - _request.return_value = mock.MagicMock( |
130 | | - data=b'{"etcdserver": "2.2.3", "etcdcluster": "2.3.0"}') |
131 | | - |
132 | | - # Create the client and make the call. |
133 | | - client = etcd.Client() |
134 | | - client._set_version_info() |
135 | | - |
136 | | - # Verify we call the proper endpoint |
137 | | - _request.assert_called_once_with( |
138 | | - client._MGET, |
139 | | - client._base_uri + '/version', |
140 | | - headers=mock.ANY, |
141 | | - redirect=mock.ANY, |
142 | | - timeout=mock.ANY) |
143 | | - |
144 | | - # Verify the properties while we are here |
145 | | - self.assertEquals('2.2.3', client.version) |
146 | | - self.assertEquals('2.3.0', client.cluster_version) |
| 128 | + data = {"etcdserver": "2.2.3", "etcdcluster": "2.3.0"} |
| 129 | + self._mock_api(200, data) |
| 130 | + self.client.api_execute.return_value.getheader.return_value = None |
| 131 | + # Create the client and make the call. |
| 132 | + self.client._set_version_info() |
| 133 | + |
| 134 | + # Verify we call the proper endpoint |
| 135 | + self.client.api_execute.assert_called_once_with( |
| 136 | + '/version', |
| 137 | + self.client._MGET |
| 138 | + ) |
| 139 | + # Verify the properties while we are here |
| 140 | + self.assertEquals('2.2.3', self.client.version) |
| 141 | + self.assertEquals('2.3.0', self.client.cluster_version) |
147 | 142 |
|
148 | 143 | def test_version_property(self): |
149 | 144 | """Ensure the version property is set on first access.""" |
150 | | - with mock.patch('urllib3.PoolManager') as _pm: |
151 | | - _request = _pm().request |
152 | | - # Return the expected data type |
153 | | - _request.return_value = mock.MagicMock( |
154 | | - data=b'{"etcdserver": "2.2.3", "etcdcluster": "2.3.0"}') |
155 | | - |
156 | | - # Create the client. |
157 | | - client = etcd.Client() |
| 145 | + data = {"etcdserver": "2.2.3", "etcdcluster": "2.3.0"} |
| 146 | + self._mock_api(200, data) |
| 147 | + self.client.api_execute.return_value.getheader.return_value = None |
158 | 148 |
|
159 | | - # Verify the version property is set |
160 | | - self.assertEquals('2.2.3', client.version) |
| 149 | + # Verify the version property is set |
| 150 | + self.assertEquals('2.2.3', self.client.version) |
161 | 151 |
|
162 | 152 | def test_cluster_version_property(self): |
163 | 153 | """Ensure the cluster version property is set on first access.""" |
164 | | - with mock.patch('urllib3.PoolManager') as _pm: |
165 | | - _request = _pm().request |
166 | | - # Return the expected data type |
167 | | - _request.return_value = mock.MagicMock( |
168 | | - data=b'{"etcdserver": "2.2.3", "etcdcluster": "2.3.0"}') |
169 | | - |
170 | | - # Create the client. |
171 | | - client = etcd.Client() |
172 | | - |
173 | | - # Verify the cluster_version property is set |
174 | | - self.assertEquals('2.3.0', client.cluster_version) |
| 154 | + data = {"etcdserver": "2.2.3", "etcdcluster": "2.3.0"} |
| 155 | + self._mock_api(200, data) |
| 156 | + self.client.api_execute.return_value.getheader.return_value = None |
| 157 | + # Verify the cluster_version property is set |
| 158 | + self.assertEquals('2.3.0', self.client.cluster_version) |
175 | 159 |
|
176 | 160 | def test_get_headers_without_auth(self): |
177 | 161 | client = etcd.Client() |
|
0 commit comments