summaryrefslogtreecommitdiffstats
path: root/testapi/testapi-client/testapiclient/utils/urlparse.py
diff options
context:
space:
mode:
authorSerena Feng <feng.xiaowei@zte.com.cn>2018-03-14 12:59:53 +0000
committerGerrit Code Review <gerrit@opnfv.org>2018-03-14 12:59:53 +0000
commitbd27d9c8a76887b129ba79117b727f0f0428d106 (patch)
tree52468a2f3342415b3e92af671bcadaad2abd54a9 /testapi/testapi-client/testapiclient/utils/urlparse.py
parent29b0c572ba4609df208b7e716a42335a32f686d9 (diff)
parentc761a572ae14368ad002a911d07d14c5c5c1b703 (diff)
Merge "bugfix: TestAPI Cookie cannot be found"
Diffstat (limited to 'testapi/testapi-client/testapiclient/utils/urlparse.py')
-rw-r--r--testapi/testapi-client/testapiclient/utils/urlparse.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/testapi/testapi-client/testapiclient/utils/urlparse.py b/testapi/testapi-client/testapiclient/utils/urlparse.py
new file mode 100644
index 0000000..9f99a46
--- /dev/null
+++ b/testapi/testapi-client/testapiclient/utils/urlparse.py
@@ -0,0 +1,40 @@
+import os
+
+from six.moves.urllib import parse
+
+
+def path_join(base, *urls):
+ def _path_join(base, url):
+ if not base.endswith('/'):
+ base += '/'
+ return parse.urljoin(base, url)
+
+ urls = (base,) + urls
+ return reduce(_path_join, urls)
+
+
+def query_join(base, **queries):
+ return base + '?' + parse.urlencode(queries)
+
+
+def resource_join(url):
+ testapi_url = os.environ.get('testapi_url')
+ return path_join(testapi_url, url)
+
+
+def get_queries(queries, parsed_args):
+ if not isinstance(queries, list):
+ queries = [queries]
+
+ return {query: getattr(parsed_args, query)
+ for query in queries
+ if hasattr(parsed_args, query) and getattr(parsed_args, query)}
+
+
+def query_by(base, queries, parsed_args):
+ qs = get_queries(queries, parsed_args)
+ return query_join(base, **qs) if qs else base
+
+
+def url_format(base, parsed_args):
+ return base.format(**(parsed_args.__dict__))