Skip to content
This repository has been archived by the owner on Mar 13, 2022. It is now read-only.

Commit

Permalink
Support customizing “Accept” header and added a testcase to test cust…
Browse files Browse the repository at this point in the history
…om header
  • Loading branch information
Yashks1994 committed May 6, 2021
1 parent 8a969ee commit 9bca507
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 4 additions & 2 deletions dynamic/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
])
Expand Down
13 changes: 12 additions & 1 deletion dynamic/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,22 @@ 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')

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)

0 comments on commit 9bca507

Please sign in to comment.