improved unicode encoding for the string in py2 and py3
[testsuite/python-testing-utils.git] / robotframework-onap / ONAPLibrary / RequestsDecorators.py
1 from robot.api import logger
2
3 def log_wrapped(func):
4     def _log_wrapped(*args, **kwargs):
5         if 'endpoint' in kwargs:
6             endpoint = kwargs['endpoint']
7             logger.info("Creating session " + endpoint)
8         resp = func(*args, **kwargs)
9         if 'alias' in kwargs:
10             alias = kwargs['alias']
11             logger.info("Received response from [" + alias + "]: " + resp.text)
12         return resp
13
14     return _log_wrapped
15
16 def default_keywords(func):
17     def _default_keywords(*args, **kwargs):
18         dicts = _keyword_defaults(**kwargs)
19         return func(*args, **dicts)
20
21     def _keyword_defaults(**kwargs):
22         if 'alias' not in kwargs:
23             raise ValueError('named attribute alias required', 'alias')
24         if 'endpoint' not in kwargs:
25             raise ValueError('named attribute required', 'endpoint')
26         if 'data_path' not in kwargs:
27             kwargs['data_path'] = None  # default to whatever is in the session
28         if 'data' not in kwargs:
29             kwargs['data'] = None  # default to empty body
30         if 'sdc_user' not in kwargs:
31             kwargs['sdc_user'] = None  # default to no user
32         if 'accept' not in kwargs:
33             kwargs['accept'] = "application/json"  # default to json
34         if 'content_type' not in kwargs:
35             kwargs['content_type'] = "application/json"  # default to json
36         if 'auth' not in kwargs:
37             kwargs['auth'] = None  # default to no basic auth
38         if 'client_certs' not in kwargs:
39             kwargs['client_certs'] = None  # default to no client cert
40         if 'files' not in kwargs:
41             kwargs['files'] = None   # default to no file
42         return kwargs
43
44     return _default_keywords
45