From bde3935f2698b0145b8c1cf50fae0f67215e7c1f Mon Sep 17 00:00:00 2001 From: Yash Kumar Singh Date: Tue, 27 Apr 2021 12:05:04 +0530 Subject: [PATCH] =?UTF-8?q?Support=20customizing=20=E2=80=9CAccept?= =?UTF-8?q?=E2=80=9D=20header=20and=20added=20a=20testcase=20to=20test=20c?= =?UTF-8?q?ustom=20header?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dynamic/client.py | 13 ++++++++----- dynamic/test_client.py | 18 +++++++++++++++++- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/dynamic/client.py b/dynamic/client.py index 7b82b3d6a5..f69265085d 100644 --- a/dynamic/client.py +++ b/dynamic/client.py @@ -219,11 +219,14 @@ def request(self, method, path, body=None, **params): header_params = params.get('header_params', {}) form_params = [] local_var_files = {} - # HTTP header `Accept` - header_params['Accept'] = self.client.select_header_accept([ - 'application/json', - 'application/yaml', - ]) + + # Checking Accept header. + new_header_params = dict((key.lower(), value) for key, value in header_params.items()) + if not 'accept' in new_header_params: + header_params['Accept'] = self.client.select_header_accept([ + 'application/json', + 'application/yaml', + ]) # HTTP header `Content-Type` if params.get('content_type'): diff --git a/dynamic/test_client.py b/dynamic/test_client.py index b68e081fc3..54e41bb495 100644 --- a/dynamic/test_client.py +++ b/dynamic/test_client.py @@ -359,7 +359,7 @@ def test_configmap_apis(self): resp = api.get(namespace='default', pretty=True, label_selector="e2e-test=true") self.assertEqual([], resp.items) - + def test_node_apis(self): client = DynamicClient(api_client.ApiClient(configuration=self.config)) api = client.resources.get(api_version='v1', kind='Node') @@ -367,3 +367,19 @@ def test_node_apis(self): for item in api.get().items: node = api.get(name=item.metadata.name) self.assertTrue(len(dict(node.metadata.labels)) > 0) + + # test_node_apis_partial_object_metadata lists all nodes in the cluster, but only retrieves object metadata + def test_node_apis_partial_object_metadata(self): + client = DynamicClient(api_client.ApiClient(configuration=self.config)) + api = client.resources.get(api_version='v1', kind='Node') + + params = {'header_params': {'Accept': 'application/json;as=PartialObjectMetadataList;v=v1;g=meta.k8s.io'}} + resp = api.get(**params) + self.assertEqual('PartialObjectMetadataList', resp.kind) + self.assertEqual('meta.k8s.io/v1', resp.apiVersion) + + params = {'header_params': {'aCcePt': 'application/json;as=PartialObjectMetadataList;v=v1;g=meta.k8s.io'}} + resp = api.get(**params) + self.assertEqual('PartialObjectMetadataList', resp.kind) + self.assertEqual('meta.k8s.io/v1', resp.apiVersion) +