1 # Copyright 2019 AT&T Intellectual Property. All rights reserved.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 from robot.api import logger
18 def log_wrapped(func):
19 def _log_wrapped(*args, **kwargs):
20 if 'endpoint' in kwargs:
21 endpoint = kwargs['endpoint']
22 logger.info("Creating session " + endpoint)
23 resp = func(*args, **kwargs)
25 alias = kwargs['alias']
26 logger.info("Received response from [" + alias + "]: " + resp.text)
32 def default_keywords(func):
33 def _default_keywords(*args, **kwargs):
34 dicts = _keyword_defaults(**kwargs)
35 return func(*args, **dicts)
37 def _keyword_defaults(**kwargs):
38 if 'alias' not in kwargs:
39 raise ValueError('named attribute alias required', 'alias')
40 if 'endpoint' not in kwargs:
41 raise ValueError('named attribute required', 'endpoint')
42 if 'data_path' not in kwargs:
43 kwargs['data_path'] = None # default to whatever is in the session
44 if 'data' not in kwargs:
45 kwargs['data'] = None # default to empty body
46 if 'sdc_user' not in kwargs:
47 kwargs['sdc_user'] = None # default to no user
48 if 'accept' not in kwargs:
49 kwargs['accept'] = "application/json" # default to json
50 if 'content_type' not in kwargs:
51 kwargs['content_type'] = "application/json" # default to json
52 if 'auth' not in kwargs:
53 kwargs['auth'] = None # default to no basic auth
54 if 'client_certs' not in kwargs:
55 kwargs['client_certs'] = None # default to no client cert
56 if 'files' not in kwargs:
57 kwargs['files'] = None # default to no file
60 return _default_keywords