From 9bca507c1f51b02659e1b6d532aaffe9bf9fe82d 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 | 6 ++++-- dynamic/test_client.py | 13 ++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/dynamic/client.py b/dynamic/client.py index 7b82b3d6..93fa416a 100644 --- a/dynamic/client.py +++ b/dynamic/client.py @@ -219,8 +219,10 @@ 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([ + + # User didn't specify the Accept header. Default it to json and yaml. + if not 'Accept' in header_params or not 'accept' in header_params: + header_params['Accept'] = self.client.select_header_accept([ 'application/json', 'application/yaml', ]) diff --git a/dynamic/test_client.py b/dynamic/test_client.py index b68e081f..7d1814cf 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,14 @@ 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) +