summaryrefslogtreecommitdiffstats
path: root/testapi
diff options
context:
space:
mode:
authorSerenaFeng <feng.xiaowei@zte.com.cn>2018-03-07 17:06:22 +0800
committerSerenaFeng <feng.xiaowei@zte.com.cn>2018-03-07 17:27:11 +0800
commit50303ed3d17797c918d2743220be80af1445344f (patch)
tree818119d545c7fa99653e3c1eda1b5d6a4be6b4d3 /testapi
parentdcff4557e191f0ed925fd1306c7fca1a645b4654 (diff)
simply http client process
Change-Id: I85b87be7d57b7c3ecb087b27729bc86934283366 Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'testapi')
-rw-r--r--testapi/testapi-client/testapiclient/http_client.py (renamed from testapi/testapi-client/testapiclient/httpClient.py)23
-rw-r--r--testapi/testapi-client/testapiclient/pods.py6
-rw-r--r--testapi/testapi-client/testapiclient/projects.py7
3 files changed, 24 insertions, 12 deletions
diff --git a/testapi/testapi-client/testapiclient/httpClient.py b/testapi/testapi-client/testapiclient/http_client.py
index f8683b9..a2bd65d 100644
--- a/testapi/testapi-client/testapiclient/httpClient.py
+++ b/testapi/testapi-client/testapiclient/http_client.py
@@ -3,7 +3,7 @@ import json
import requests
-class HTTPClient():
+class HTTPClient(object):
__instance = None
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
@@ -49,3 +49,24 @@ class HTTPClient():
else:
r = session.delete(url)
return r.text
+
+
+def http_request(method, *args, **kwargs):
+ client = HTTPClient.get_Instance()
+ return getattr(client, method)(*args, **kwargs)
+
+
+def get(url):
+ return http_request('get', url)
+
+
+def post(url, session, data):
+ return http_request('post', url, session, data)
+
+
+def put(url, session, data):
+ return http_request('put', url, session, data)
+
+
+def delete(url, session, data):
+ return http_request('delete', url, session, data)
diff --git a/testapi/testapi-client/testapiclient/pods.py b/testapi/testapi-client/testapiclient/pods.py
index 64bb74d..0864c22 100644
--- a/testapi/testapi-client/testapiclient/pods.py
+++ b/testapi/testapi-client/testapiclient/pods.py
@@ -2,7 +2,7 @@ import json
from testapiclient import command
from testapiclient import config
-from testapiclient import httpClient
+from testapiclient import http_client
from testapiclient import identity
from testapiclient import user
@@ -20,7 +20,6 @@ class PodGet(command.Lister):
return parser
def take_action(self, parsed_args):
- http_client = httpClient.HTTPClient.get_Instance()
url = PODS_URL
if(parsed_args.name):
url = PODS_URL + "?name=" + parsed_args.name
@@ -40,7 +39,6 @@ class PodGetOne(command.ShowOne):
return parser
def take_action(self, parsed_args):
- http_client = httpClient.HTTPClient.get_Instance()
pods = http_client.get(PODS_URL + "/" + parsed_args.name)
print pods
@@ -61,7 +59,6 @@ class PodCreate(command.Command):
@identity.authenticate
def take_action(self, parsed_args):
- http_client = httpClient.HTTPClient.get_Instance()
response = http_client.post(PODS_URL,
user.User.session,
parsed_args.pod)
@@ -84,6 +81,5 @@ class PodDelete(command.Command):
@identity.authenticate
def take_action(self, parsed_args):
- http_client = httpClient.HTTPClient.get_Instance()
print http_client.delete(PODS_URL + "/" + parsed_args.name,
user.User.session)
diff --git a/testapi/testapi-client/testapiclient/projects.py b/testapi/testapi-client/testapiclient/projects.py
index cd55e74..ee2e884 100644
--- a/testapi/testapi-client/testapiclient/projects.py
+++ b/testapi/testapi-client/testapiclient/projects.py
@@ -2,7 +2,7 @@ import json
from testapiclient import command
from testapiclient import config
-from testapiclient import httpClient
+from testapiclient import http_client
from testapiclient import identity
from testapiclient import user
@@ -19,7 +19,6 @@ class ProjectGet(command.Lister):
return parser
def take_action(self, parsed_args):
- http_client = httpClient.HTTPClient.get_Instance()
url = PROJECTS_URL
if parsed_args.name:
url = url + "?name=" + parsed_args.name
@@ -38,7 +37,6 @@ class ProjectGetOne(command.ShowOne):
return parser
def take_action(self, parsed_args):
- http_client = httpClient.HTTPClient.get_Instance()
url = PROJECTS_URL + "/" + parsed_args.name
project = http_client.get(url)
print project
@@ -57,7 +55,6 @@ class ProjectCreate(command.Command):
@identity.authenticate
def take_action(self, parsed_args):
- http_client = httpClient.HTTPClient.get_Instance()
response = http_client.post(ProjectCreate.projects_url,
user.User.session,
parsed_args.project)
@@ -79,7 +76,6 @@ class ProjectDelete(command.Command):
@identity.authenticate
def take_action(self, parsed_args):
- http_client = httpClient.HTTPClient.get_Instance()
projects = http_client.delete(
PROJECTS_URL + "/" + parsed_args.name,
user.User.session)
@@ -103,7 +99,6 @@ class ProjectPut(command.Command):
@identity.authenticate
def take_action(self, parsed_args):
- http_client = httpClient.HTTPClient.get_Instance()
projects = http_client.put(
PROJECTS_URL + "/" + parsed_args.name,
user.User.session,