From c761a572ae14368ad002a911d07d14c5c5c1b703 Mon Sep 17 00:00:00 2001 From: SerenaFeng Date: Wed, 14 Mar 2018 16:17:34 +0800 Subject: bugfix: TestAPI Cookie cannot be found Change-Id: Ibab60aba26e30669dddab74ce61ed00197dc86a8 Signed-off-by: SerenaFeng --- .../testapi-client/testapiclient/utils/urlparse.py | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 testapi/testapi-client/testapiclient/utils/urlparse.py (limited to 'testapi/testapi-client/testapiclient/utils/urlparse.py') 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__)) -- cgit 1.2.3-korg