Skip to content

Commit a3e922a

Browse files
authored
Merge pull request #98 from dims/fix-patch-tests
Fix for patch_* to work
2 parents 4c3aced + 9c6c965 commit a3e922a

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

kubernetes/client/rest.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,18 @@ def request(self, method, url, query_params=None, headers=None,
146146
if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']:
147147
if query_params:
148148
url += '?' + urlencode(query_params)
149-
if re.search('json', headers['Content-Type'], re.IGNORECASE):
149+
if headers['Content-Type'] == 'application/json-patch+json':
150+
headers[
151+
'Content-Type'] = 'application/strategic-merge-patch+json'
152+
request_body = None
153+
if body:
154+
request_body = json.dumps(body)
155+
r = self.pool_manager.request(method, url,
156+
body=request_body,
157+
preload_content=_preload_content,
158+
timeout=timeout,
159+
headers=headers)
160+
elif re.search('json', headers['Content-Type'], re.IGNORECASE):
150161
request_body = None
151162
if body:
152163
request_body = json.dumps(body)

kubernetes/e2e_test/test_client.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,15 @@ def test_service_apis(self):
105105
self.assertEqual('frontend', resp.metadata.name)
106106
self.assertTrue(resp.status)
107107

108-
# TODO(dims) : Fails with "json: cannot unmarshal object into
109-
# Go value of type jsonpatch.Patch"
110-
# service_manifest['spec']['ports'] = [{'name': 'new',
111-
# 'port': 8080,
112-
# 'protocol': 'TCP',
113-
# 'targetPort': 8080}]
114-
# resp = api.patch_namespaced_service(body=service_manifest,
115-
# name='frontend',
116-
# namespace='default')
117-
# self.assertEqual(2, len(resp.spec.ports))
118-
# self.assertTrue(resp.status)
108+
service_manifest['spec']['ports'] = [{'name': 'new',
109+
'port': 8080,
110+
'protocol': 'TCP',
111+
'targetPort': 8080}]
112+
resp = api.patch_namespaced_service(body=service_manifest,
113+
name='frontend',
114+
namespace='default')
115+
self.assertEqual(2, len(resp.spec.ports))
116+
self.assertTrue(resp.status)
119117

120118
resp = api.delete_namespaced_service(name='frontend',
121119
namespace='default')
@@ -182,11 +180,9 @@ def test_configmap_apis(self):
182180
name='test-configmap', namespace='default')
183181
self.assertEqual('test-configmap', resp.metadata.name)
184182

185-
# TODO(dims): Fails with "json: cannot unmarshal object
186-
# into Go value of type jsonpatch.Patch"
187-
# test_configmap['data']['config.json'] = "{}"
188-
# resp = api.patch_namespaced_config_map(
189-
# name='test-configmap', namespace='default', body=test_configmap)
183+
test_configmap['data']['config.json'] = "{}"
184+
resp = api.patch_namespaced_config_map(
185+
name='test-configmap', namespace='default', body=test_configmap)
190186

191187
resp = api.delete_namespaced_config_map(
192188
name='test-configmap', body={}, namespace='default')

0 commit comments

Comments
 (0)