Skip to content

Commit feee797

Browse files
authored
Merge pull request kubernetes-client#9 from mbohlool/test
Add tox and travis support
2 parents 510db89 + bb49e2c commit feee797

File tree

8 files changed

+232
-114
lines changed

8 files changed

+232
-114
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,9 @@ ENV/
8787

8888
# Rope project settings
8989
.ropeproject
90+
91+
# Intellij IDEA files
92+
.idea/*
93+
*.iml
94+
.vscode
95+

.travis.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# ref: https://docs.travis-ci.com/user/languages/python
2+
language: python
3+
sudo: required
4+
5+
matrix:
6+
include:
7+
- python: 2.7
8+
env: TOXENV=py27
9+
- python: 2.7
10+
env: TOXENV=py27-functional
11+
- python: 2.7
12+
env: TOXENV=update-pep8
13+
- python: 2.7
14+
env: TOXENV=docs
15+
- python: 2.7
16+
env: TOXENV=coverage,codecov
17+
- python: 3.4
18+
env: TOXENV=py34
19+
- python: 3.5
20+
env: TOXENV=py35
21+
- python: 3.5
22+
env: TOXENV=py35-functional
23+
- python: 3.6
24+
env: TOXENV=py36
25+
- python: 3.6
26+
env: TOXENV=py36-functional
27+
28+
install:
29+
- pip install tox
30+
31+
script:
32+
- ./run_tox.sh tox
33+

api_client.py

+45-35
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,21 @@
2020

2121
from __future__ import absolute_import
2222

23-
from . import models
24-
from . import ws_client
25-
from .rest import RESTClientObject
26-
from .rest import ApiException
27-
28-
import os
29-
import re
3023
import json
3124
import mimetypes
25+
import os
26+
import re
3227
import tempfile
3328
import threading
34-
35-
from datetime import datetime
36-
from datetime import date
29+
from datetime import date, datetime
3730

3831
# python 2 and python 3 compatibility library
3932
from six import PY3, integer_types, iteritems, text_type
4033
from six.moves.urllib.parse import quote
4134

35+
from . import models, ws_client
4236
from .configuration import configuration
37+
from .rest import ApiException, RESTClientObject
4338

4439

4540
class ApiClient(object):
@@ -59,9 +54,9 @@ class ApiClient(object):
5954
:param header_name: a header to pass when making calls to the API.
6055
:param header_value: a header value to pass when making calls to the API.
6156
"""
57+
6258
def __init__(self, host=None, header_name=None, header_value=None,
6359
cookie=None, config=configuration):
64-
6560
"""
6661
Constructor of the class.
6762
"""
@@ -99,8 +94,8 @@ def __call_api(self, resource_path, method,
9994
path_params=None, query_params=None, header_params=None,
10095
body=None, post_params=None, files=None,
10196
response_type=None, auth_settings=None, callback=None,
102-
_return_http_data_only=None, collection_formats=None, _preload_content=True,
103-
_request_timeout=None):
97+
_return_http_data_only=None, collection_formats=None,
98+
_preload_content=True, _request_timeout=None):
10499

105100
# header parameters
106101
header_params = header_params or {}
@@ -163,11 +158,16 @@ def __call_api(self, resource_path, method,
163158
return_data = None
164159

165160
if callback:
166-
callback(return_data) if _return_http_data_only else callback((return_data, response_data.status, response_data.getheaders()))
161+
if _return_http_data_only:
162+
callback(return_data)
163+
else:
164+
callback((return_data,
165+
response_data.status, response_data.getheaders()))
167166
elif _return_http_data_only:
168167
return (return_data)
169168
else:
170-
return (return_data, response_data.status, response_data.getheaders())
169+
return (return_data, response_data.status,
170+
response_data.getheaders())
171171

172172
def sanitize_for_serialization(self, obj):
173173
"""
@@ -194,7 +194,7 @@ def sanitize_for_serialization(self, obj):
194194
for sub_obj in obj]
195195
elif isinstance(obj, tuple):
196196
return tuple(self.sanitize_for_serialization(sub_obj)
197-
for sub_obj in obj)
197+
for sub_obj in obj)
198198
elif isinstance(obj, (datetime, date)):
199199
return obj.isoformat()
200200
else:
@@ -248,7 +248,7 @@ def __deserialize(self, data, klass):
248248
if data is None:
249249
return None
250250

251-
if type(klass) == str:
251+
if isinstance(klass, str):
252252
if klass.startswith('list['):
253253
sub_kls = re.match('list\[(.*)\]', klass).group(1)
254254
return [self.__deserialize(sub_data, sub_kls)
@@ -285,8 +285,8 @@ def call_api(self, resource_path, method,
285285
path_params=None, query_params=None, header_params=None,
286286
body=None, post_params=None, files=None,
287287
response_type=None, auth_settings=None, callback=None,
288-
_return_http_data_only=None, collection_formats=None, _preload_content=True,
289-
_request_timeout=None):
288+
_return_http_data_only=None, collection_formats=None,
289+
_preload_content=True, _request_timeout=None):
290290
"""
291291
Makes the HTTP request (synchronous) and return the deserialized data.
292292
To make an async request, define a function for callback.
@@ -307,13 +307,18 @@ def call_api(self, resource_path, method,
307307
:param callback function: Callback function for asynchronous request.
308308
If provide this parameter,
309309
the request will be called asynchronously.
310-
:param _return_http_data_only: response data without head status code and headers
310+
:param _return_http_data_only: response data without head status code
311+
and headers
311312
:param collection_formats: dict of collection formats for path, query,
312313
header, and post parameters.
313-
:param _preload_content: if False, the urllib3.HTTPResponse object will be returned without
314-
reading/decoding response data. Default is True.
315-
:param _request_timeout: timeout setting for this request. If one number provided, it will be total request
316-
timeout. It can also be a pair (tuple) of (connection, read) timeouts.
314+
:param _preload_content: if False, the urllib3.HTTPResponse object will
315+
be returned without
316+
reading/decoding response data.
317+
Default is True.
318+
:param _request_timeout: timeout setting for this request. If one
319+
number provided, it will be total request
320+
timeout. It can also be a pair (tuple) of
321+
(connection, read) timeouts.
317322
:return:
318323
If provide parameter callback,
319324
the request will be called asynchronously.
@@ -326,7 +331,8 @@ def call_api(self, resource_path, method,
326331
path_params, query_params, header_params,
327332
body, post_params, files,
328333
response_type, auth_settings, callback,
329-
_return_http_data_only, collection_formats, _preload_content, _request_timeout)
334+
_return_http_data_only, collection_formats,
335+
_preload_content, _request_timeout)
330336
else:
331337
thread = threading.Thread(target=self.__call_api,
332338
args=(resource_path, method,
@@ -335,18 +341,22 @@ def call_api(self, resource_path, method,
335341
post_params, files,
336342
response_type, auth_settings,
337343
callback, _return_http_data_only,
338-
collection_formats, _preload_content, _request_timeout))
344+
collection_formats,
345+
_preload_content,
346+
_request_timeout))
339347
thread.start()
340348
return thread
341349

342350
def request(self, method, url, query_params=None, headers=None,
343-
post_params=None, body=None, _preload_content=True, _request_timeout=None):
351+
post_params=None, body=None, _preload_content=True,
352+
_request_timeout=None):
344353
"""
345354
Makes the HTTP request using RESTClient.
346355
"""
347356
# FIXME(dims) : We need a better way to figure out which
348357
# calls end up using web sockets
349-
if (url.endswith('/exec') or url.endswith('/attach')) and (method == "GET" or method == "POST"):
358+
if (url.endswith('/exec') or url.endswith('/attach')) and \
359+
(method == "GET" or method == "POST"):
350360
return ws_client.websocket_call(self.config,
351361
url,
352362
query_params=query_params,
@@ -458,14 +468,15 @@ def prepare_post_parameters(self, post_params=None, files=None):
458468
for k, v in iteritems(files):
459469
if not v:
460470
continue
461-
file_names = v if type(v) is list else [v]
471+
file_names = v if isinstance(v, list) else [v]
462472
for n in file_names:
463473
with open(n, 'rb') as f:
464474
filename = os.path.basename(f.name)
465475
filedata = f.read()
466-
mimetype = mimetypes.\
467-
guess_type(filename)[0] or 'application/octet-stream'
468-
params.append(tuple([k, tuple([filename, filedata, mimetype])]))
476+
mimetype = (mimetypes.guess_type(filename)[0] or
477+
'application/octet-stream')
478+
params.append(tuple([k, tuple([filename, filedata,
479+
mimetype])]))
469480

470481
return params
471482

@@ -543,9 +554,8 @@ def __deserialize_file(self, response):
543554

544555
content_disposition = response.getheader("Content-Disposition")
545556
if content_disposition:
546-
filename = re.\
547-
search(r'filename=[\'"]?([^\'"\s]+)[\'"]?', content_disposition).\
548-
group(1)
557+
filename = re.search(r'filename=[\'"]?([^\'"\s]+)[\'"]?',
558+
content_disposition).group(1)
549559
path = os.path.join(os.path.dirname(path), filename)
550560

551561
with open(path, "w") as f:

config/kube_config.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ def set_active_context(self, context_name=None):
130130
context_name = self._config['current-context']
131131
self._current_context = self._config['contexts'].get_with_name(
132132
context_name)
133-
if (self._current_context['context'].safe_get('user')
134-
and self._config.safe_get('users')):
133+
if (self._current_context['context'].safe_get('user') and
134+
self._config.safe_get('users')):
135135
user = self._config['users'].get_with_name(
136136
self._current_context['context']['user'], safe=True)
137137
if user:

configuration.py

+14-15
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
"""
44
Kubernetes
55
6-
No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
7-
8-
OpenAPI spec version: v1.5.0-snapshot
9-
10-
Generated by: https://github.com/swagger-api/swagger-codegen.git
6+
First version Generated by: https://github.com/swagger-api/swagger-codegen
117
128
Licensed under the Apache License, Version 2.0 (the "License");
139
you may not use this file except in compliance with the License.
@@ -24,11 +20,10 @@
2420

2521
from __future__ import absolute_import
2622

27-
import urllib3
28-
29-
import sys
3023
import logging
24+
import sys
3125

26+
import urllib3
3227
from six import iteritems
3328
from six.moves import http_client as httplib
3429

@@ -77,7 +72,8 @@ def __init__(self):
7772
self.debug = False
7873

7974
# SSL/TLS verification
80-
# Set this to false to skip verifying SSL certificate when calling API from https server.
75+
# Set this to false to skip verifying SSL certificate when calling API
76+
# from https server.
8177
self.verify_ssl = True
8278
# Set this to customize the certificate file to verify the peer.
8379
self.ssl_ca_cert = None
@@ -101,8 +97,8 @@ def logger_file(self, value):
10197
"""
10298
Sets the logger_file.
10399
104-
If the logger_file is None, then add stream handler and remove file handler.
105-
Otherwise, add file handler and remove stream handler.
100+
If the logger_file is None, then add stream handler and remove file
101+
handler. Otherwise, add file handler and remove stream handler.
106102
107103
:param value: The logger_file path.
108104
:type: str
@@ -184,8 +180,10 @@ def get_api_key_with_prefix(self, identifier):
184180
:param identifier: The identifier of apiKey.
185181
:return: The token for api key authentication.
186182
"""
187-
if self.api_key.get(identifier) and self.api_key_prefix.get(identifier):
188-
return self.api_key_prefix[identifier] + ' ' + self.api_key[identifier]
183+
if (self.api_key.get(identifier) and
184+
self.api_key_prefix.get(identifier)):
185+
return (self.api_key_prefix[identifier] + ' ' +
186+
self.api_key[identifier])
189187
elif self.api_key.get(identifier):
190188
return self.api_key[identifier]
191189

@@ -195,8 +193,9 @@ def get_basic_auth_token(self):
195193
196194
:return: The token for basic HTTP authentication.
197195
"""
198-
return urllib3.util.make_headers(basic_auth=self.username + ':' + self.password)\
199-
.get('authorization')
196+
return urllib3.util.make_headers(
197+
basic_auth=self.username + ':' + self.password).get(
198+
'authorization')
200199

201200
def auth_settings(self):
202201
"""

0 commit comments

Comments
 (0)