holado 0.3.0__py3-none-any.whl → 0.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of holado might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: holado
3
- Version: 0.3.0
3
+ Version: 0.4.0
4
4
  Summary: HolAdo framework
5
5
  Project-URL: Homepage, https://gitlab.com/holado_framework/python
6
6
  Project-URL: Issues, https://gitlab.com/holado_framework/python/-/issues
@@ -289,7 +289,7 @@ holado_python/tests/behave/steps/iterable_steps.py,sha256=f4vGIWBH8Qnjq69Q-ZBluY
289
289
  holado_python/tests/behave/steps/builtins/str_steps.py,sha256=ugNIz5v5EpkiRBDmwDl2JtAq5RWXu6UnLv7HH73WiXw,2101
290
290
  holado_python/tests/behave/steps/standard_library/csv_steps.py,sha256=VJ5wmr0CQ8voBSgnXQUBAdYkEGFOCs95JKcV52tVMOo,7460
291
291
  holado_python/tests/behave/steps/standard_library/datetime_steps.py,sha256=mWbYb-CjSVKKWNcBaBzL24jP86C0v-NZ8W3hfrzHlbc,7815
292
- holado_python/tests/behave/steps/standard_library/hashlib_steps.py,sha256=zhLtKeHhLED-s-67chSqG9asCdOG9fRBUWbF8deKBoU,2979
292
+ holado_python/tests/behave/steps/standard_library/hashlib_steps.py,sha256=j1NmcvFAFKYAhWeYWc6Xf32M0CPGTgk2fHcaBBbav8o,2978
293
293
  holado_python/tests/behave/steps/standard_library/multiprocessing_steps.py,sha256=DD--5bxCvFTXY6KBqKzKAuOrOK0aZdPjbRR5SO0PZBo,2519
294
294
  holado_python/tests/behave/steps/standard_library/queue_steps.py,sha256=GdHKKIka5tzFxVTBYPJNywyVLDtggZF2RB_mFIbyLdI,17429
295
295
  holado_python/tests/behave/steps/standard_library/socket_steps.py,sha256=IkZ88bR9QK3ji3JhnfKbEBWL1lDje2bzKv1iCaXUg4A,17742
@@ -326,11 +326,11 @@ holado_report/report/reports/feature_report.py,sha256=i0wpk3LQLArVjWDsP9UcNSJzAU
326
326
  holado_report/report/reports/scenario_report.py,sha256=eMyqw9EzaKMmX3pGFJN1rqAOQ5eqO2ISZdxAfK3XQR4,2945
327
327
  holado_rest/__init__.py,sha256=BOeE6t6ejeqRYd44SE4vYJVTNz01BwcVCIWfwRQ5axg,1526
328
328
  holado_rest/api/rest/TODO.txt,sha256=2hhmTDatpplFhgv8fkBPM4WOa6pow-978-0pmN51cU0,59
329
- holado_rest/api/rest/rest_client.py,sha256=DPKvGuXC4DTsVqlVp5PebUHAW6z2H94fLmygfYm8CY8,4980
330
- holado_rest/api/rest/rest_manager.py,sha256=JA1yzXIn3KEMhBzYs7HqN47xh4JaWA_UULkopYaqu2o,3392
329
+ holado_rest/api/rest/rest_client.py,sha256=jFn0V3qbXsLqBintzD9fVVBgULkGGRkBJhhN_9dzNAw,5666
330
+ holado_rest/api/rest/rest_manager.py,sha256=nekokAwN73n7Dn3nLhwf22XaKDW1sYjy4-JLWdfGxBQ,3559
331
331
  holado_rest/tests/behave/steps/__init__.py,sha256=lEH5NYkKtpgDV2ZAO1qAGNN4ipwILWMpgvQgnamgYKk,1283
332
332
  holado_rest/tests/behave/steps/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
333
- holado_rest/tests/behave/steps/api/rest_client_steps.py,sha256=jL-8rYicYxrkQVUIzxybxgbb_a5TWZE7P-nB-_Yvxh8,7584
333
+ holado_rest/tests/behave/steps/api/rest_client_steps.py,sha256=-msAniL0tBxhwPGIIWMryxuvVCfzQS_B2TngIdluVZg,9793
334
334
  holado_rest/tests/behave/steps/private/__init__.py,sha256=TGsd7qLZpPQRxphFzgepFa22NhHSoZgxAWSIqwvA4L8,1276
335
335
  holado_rest/tests/behave/steps/private/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
336
336
  holado_rest/tests/behave/steps/private/api/rest_steps.py,sha256=Sca0EM6uuzG-Zk976vz-EKvbwViha2vABAOpkXp9gTg,3360
@@ -539,7 +539,7 @@ test_holado/tools/django/api_rest/api_rest/api1/serializers.py,sha256=o_YxFr-tgC
539
539
  test_holado/tools/django/api_rest/api_rest/api1/tests.py,sha256=mrbGGRNg5jwbTJtWWa7zSKdDyeB4vmgZCRc2nk6VY-g,60
540
540
  test_holado/tools/django/api_rest/api_rest/api1/views.py,sha256=kOt2xT6bxO47_z__5yYR9kcYIWWv4qYzpX0K8Tqonik,758
541
541
  test_holado/tools/django/api_rest/api_rest/api1/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
542
- holado-0.3.0.dist-info/METADATA,sha256=6_P7Ukb6sh53S603UEpYVACcVgWDWrun95rGLaJOMFo,6043
543
- holado-0.3.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
544
- holado-0.3.0.dist-info/licenses/LICENSE,sha256=IgGmNlcFHnbp7UWrLJqAFvs_HIgjJDTmjCNRircJLsk,1070
545
- holado-0.3.0.dist-info/RECORD,,
542
+ holado-0.4.0.dist-info/METADATA,sha256=PZDIHDuLFY830G2HzgDA7fBQ3C4eDwADIhnCN-xzAVo,6043
543
+ holado-0.4.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
544
+ holado-0.4.0.dist-info/licenses/LICENSE,sha256=IgGmNlcFHnbp7UWrLJqAFvs_HIgjJDTmjCNRircJLsk,1070
545
+ holado-0.4.0.dist-info/RECORD,,
@@ -40,7 +40,7 @@ def __get_variable_manager():
40
40
  def step_impl(context, var_name, code_size, content, prefix):
41
41
  """Return a code computed with content as input.
42
42
  Dynamic part of the code is computed with blake2b hash algorithm.
43
- If code_size (minus length of prefix if defined) is not a multiple of 2, it is rounded to the multiple of 2 juste below.
43
+ If code_size (minus length of prefix if defined) is not a multiple of 2, it is rounded to the multiple of 2 just below.
44
44
  """
45
45
  var_name = StepTools.evaluate_variable_name(var_name)
46
46
  code_size = StepTools.evaluate_scenario_parameter(code_size)
@@ -15,6 +15,7 @@ from holado_core.common.exceptions.functional_exception import FunctionalExcepti
15
15
  from holado_core.common.exceptions.technical_exception import TechnicalException
16
16
  import logging
17
17
  from holado_core.common.tools.tools import Tools
18
+ import json
18
19
 
19
20
  logger = logging.getLogger(__name__)
20
21
 
@@ -56,6 +57,13 @@ class RestClient(object):
56
57
  if Tools.do_log(logger, logging.DEBUG):
57
58
  logger.debug(f"[{self.name}] Authenticate with token type '{token_type}' and access token '{access_token}'")
58
59
  self.__headers['Authorization'] = f'{token_type} {access_token}'
60
+
61
+ def with_ssl(self, ssl_kwargs):
62
+ unexpected_keys = set(ssl_kwargs.keys()).difference(['verify', 'cert'])
63
+ if len(unexpected_keys) > 0:
64
+ raise TechnicalException(f"Unmanaged SSL arguments: {unexpected_keys}")
65
+
66
+ self.__kwargs.update(ssl_kwargs)
59
67
 
60
68
  def response_result(self, response, status_ok=200):
61
69
  if response.status_code != status_ok:
@@ -63,8 +71,10 @@ class RestClient(object):
63
71
 
64
72
  if "application/json" in response.headers['Content-Type']:
65
73
  return response.json()
66
- else:
74
+ elif response.headers['Content-Type'].startswith('text'):
67
75
  return response.text
76
+ else:
77
+ return response.content
68
78
 
69
79
  def request(self, method, path, **kwargs):
70
80
  url = self.__build_url(path=path)
@@ -104,6 +114,13 @@ class RestClient(object):
104
114
  if self.__headers:
105
115
  res['headers'] = self.__headers
106
116
  if request_kwargs:
117
+ # Ensure data is in json string format
118
+ if 'data' in request_kwargs:
119
+ data = request_kwargs.pop('data')
120
+ if not isinstance(data, str):
121
+ data = json.dumps(data)
122
+ res['data'] = data
123
+
107
124
  for key in list(request_kwargs.keys()):
108
125
  if key in res and isinstance(res[key], dict):
109
126
  res[key].update(request_kwargs.pop(key))
@@ -33,6 +33,7 @@ class RestManager(object):
33
33
  url = kwargs.pop("url")
34
34
  headers = Tools.pop_sub_kwargs(kwargs, "headers.")
35
35
  authentication = Tools.pop_sub_kwargs(kwargs, "authentication.")
36
+ ssl_kwargs = Tools.pop_sub_kwargs(kwargs, "ssl.")
36
37
  if len(kwargs) > 0:
37
38
  raise TechnicalException(f"Unmanaged arguments: {kwargs}")
38
39
 
@@ -53,6 +54,10 @@ class RestManager(object):
53
54
  else:
54
55
  raise TechnicalException(f"Unmanaged authentication type '{authentication.keys()}' (possible authentication types: 'user', 'token'")
55
56
 
57
+ # Manage ssl if needed
58
+ if len(ssl_kwargs) > 0:
59
+ res.with_ssl(ssl_kwargs)
60
+
56
61
  return res
57
62
 
58
63
  def _new_rest_client(self, name, url, headers):
@@ -63,21 +63,62 @@ if RestClient.is_available():
63
63
  var_name = StepTools.evaluate_variable_name(var_name)
64
64
  path = StepTools.evaluate_scenario_parameter(path)
65
65
  client = StepTools.evaluate_variable_value(var_client)
66
+
67
+ # Manage request arguments as step table
68
+ request_kwargs = {}
69
+ if hasattr(context, "table") and context.table is not None:
70
+ table = BehaveStepTools.convert_step_table_2_value_table_with_header(context.table)
71
+ request_kwargs = ValueTableConverter.convert_name_value_table_2_json_object(table)
72
+
73
+ # Manage request arguments as json text
74
+ # Manage data as json text
75
+ text = BehaveStepTools.get_step_multiline_text(context, raise_exception_if_none=False)
76
+ if text is not None:
77
+ if len(request_kwargs) > 0:
78
+ raise TechnicalException(f"Request kwargs are already set to {request_kwargs}")
79
+ request_kwargs = json.loads(text)
80
+
81
+ # Process request
82
+ res = client.request(request_method, path, **request_kwargs)
83
+
84
+ # Store result
85
+ if Tools.do_log(logger, logging.DEBUG):
86
+ res_table = TableManager.convert_object_attributes_2_name_value_table(res)
87
+ logger.debug(f"Response of {request_method} {path}:\n{res_table.represent(4)}")
88
+ __get_variable_manager().register_variable(var_name, res)
89
+
90
+ @Step(r"(?P<var_name>{Variable}) = (?P<request_method>delete|get|patch|post|put) (?P<path>{Str}) \(REST client: (?P<var_client>{Variable})\)")
91
+ def step_impl(context, var_name, request_method, path, var_client):
92
+ var_name = StepTools.evaluate_variable_name(var_name)
93
+ client = StepTools.evaluate_variable_value(var_client)
66
94
 
67
- # Manage data as table
95
+ execute_steps(format_step_with_context(context,
96
+ u"__RESPONSE__@ = response of {request_method} {path} (REST client: {var_client})"
97
+ .format(request_method=request_method, path=path, var_client=var_client) ))
98
+
99
+ response = __get_variable_manager().get_variable_value("__RESPONSE__@")
100
+ res = client.response_result(response)
101
+
102
+ __get_variable_manager().register_variable(var_name, res)
103
+
104
+ @Step(r"(?P<var_name>{Variable}) = response of (?P<request_method>delete|get|patch|post|put) (?P<path>{Str}) with data \(REST client: (?P<var_client>{Variable})\)")
105
+ def step_impl(context, var_name, request_method, path, var_client):
106
+ var_name = StepTools.evaluate_variable_name(var_name)
107
+ path = StepTools.evaluate_scenario_parameter(path)
108
+ client = StepTools.evaluate_variable_value(var_client)
109
+
68
110
  data = None
111
+
112
+ # Manage request arguments as step table
69
113
  if hasattr(context, "table") and context.table is not None:
70
114
  table = BehaveStepTools.convert_step_table_2_value_table_with_header(context.table)
71
- data_obj = ValueTableConverter.convert_name_value_table_2_json_object(table)
72
- data = json.dumps(data_obj)
73
- if Tools.do_log(logger, logging.TRACE): # @UndefinedVariable
74
- logger.trace(f"Transformed parameters to JSON is: {data}")
75
-
115
+ json_obj = ValueTableConverter.convert_name_value_table_2_json_object(table)
116
+ data = json.dumps(json_obj)
117
+
118
+ # Manage request arguments as json text
76
119
  # Manage data as json text
77
120
  text = BehaveStepTools.get_step_multiline_text(context, raise_exception_if_none=False)
78
121
  if text is not None:
79
- if request_method in ['delete', 'get']:
80
- raise TechnicalException(f"Unexpected json text for request method '{request_method}'")
81
122
  if data is not None:
82
123
  raise TechnicalException(f"Data is already set to [{data}]")
83
124
  data = text
@@ -91,13 +132,13 @@ if RestClient.is_available():
91
132
  logger.debug(f"Response of {request_method} {path}:\n{res_table.represent(4)}")
92
133
  __get_variable_manager().register_variable(var_name, res)
93
134
 
94
- @When(r"(?P<var_name>{Variable}) = (?P<request_method>delete|get|patch|post|put) (?P<path>{Str}) \(REST client: (?P<var_client>{Variable})\)")
135
+ @Step(r"(?P<var_name>{Variable}) = (?P<request_method>delete|get|patch|post|put) (?P<path>{Str}) with data \(REST client: (?P<var_client>{Variable})\)")
95
136
  def step_impl(context, var_name, request_method, path, var_client):
96
137
  var_name = StepTools.evaluate_variable_name(var_name)
97
138
  client = StepTools.evaluate_variable_value(var_client)
98
139
 
99
140
  execute_steps(format_step_with_context(context,
100
- u"__RESPONSE__@ = response of {request_method} {path} (REST client: {var_client})"
141
+ u"__RESPONSE__@ = response of {request_method} {path} with data (REST client: {var_client})"
101
142
  .format(request_method=request_method, path=path, var_client=var_client) ))
102
143
 
103
144
  response = __get_variable_manager().get_variable_value("__RESPONSE__@")
File without changes