From b02e0b572c57fa60f914226bceae4fadfae56a1b Mon Sep 17 00:00:00 2001 From: Robin Mackaij Date: Sun, 28 Aug 2022 17:47:14 +0200 Subject: [PATCH] Added support for 'cert' parameter --- docs/openapi_libcore.html | 2 +- pyproject.toml | 2 +- src/OpenApiLibCore/openapi_libcore.libspec | 52 +++++++++++++++------- src/OpenApiLibCore/openapi_libcore.py | 7 +++ 4 files changed, 45 insertions(+), 18 deletions(-) diff --git a/docs/openapi_libcore.html b/docs/openapi_libcore.html index b998e2e..837941c 100644 --- a/docs/openapi_libcore.html +++ b/docs/openapi_libcore.html @@ -1192,7 +1192,7 @@ jQuery.extend({highlight:function(e,t,n,r){if(e.nodeType===3){var i=e.data.match(t);if(i){var s=document.createElement(n||"span");s.className=r||"highlight";var o=e.splitText(i.index);o.splitText(i[0].length);var u=o.cloneNode(true);s.appendChild(u);o.parentNode.replaceChild(s,o);return 1}}else if(e.nodeType===1&&e.childNodes&&!/(script|style)/i.test(e.tagName)&&!(e.tagName===n.toUpperCase()&&e.className===r)){for(var a=0;a diff --git a/pyproject.toml b/pyproject.toml index 0f9ce8f..9219e3f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name="robotframework-openapi-libcore" -version = "1.5.0" +version = "1.6.0" description = "A Robot Framework library to facilitate library development for OpenAPI / Swagger APIs." license = "Apache-2.0" authors = ["Robin Mackaij "] diff --git a/src/OpenApiLibCore/openapi_libcore.libspec b/src/OpenApiLibCore/openapi_libcore.libspec index 3351182..8d87df7 100644 --- a/src/OpenApiLibCore/openapi_libcore.libspec +++ b/src/OpenApiLibCore/openapi_libcore.libspec @@ -1,13 +1,13 @@ - -1.5.0 + +1.6.0 <p>Main class providing the keywords and core logic to interact with an OpenAPI server.</p> <p>Visit the <a href="https://github.com/MarketSquare/robotframework-openapi-libcore">library page</a> for an introduction.</p> - + source str @@ -49,6 +49,13 @@ None None + +cert +str +Tuple[str, str] +None +None + extra_headers Dict[str, str] @@ -93,7 +100,9 @@ <h4>security_token</h4> <p>The token to be used for token based security using the <code>Authorization</code> header.</p> <h4>auth</h4> -<p>A <a href="https://docs.python-requests.org/en/latest/api/#authentication">requests AuthBase instance</a> to be used for authentication instead of the <code>username</code> and <code>password</code>.</p> +<p>A <a href="https://requests.readthedocs.io/en/latest/api/#authentication">requests AuthBase instance</a> to be used for authentication instead of the <code>username</code> and <code>password</code>.</p> +<h4>cert</h4> +<p>The SSL certificate to use with all requests. If string: the path to ssl client cert file (.pem). If tuple, ('cert', 'key') pair.</p> <h4>extra_headers</h4> <p>A dictionary with extra / custom headers that will be send with every request. This parameter can be used to send headers that are not documented in the openapi document or to provide an API-key.</p> <h4>invalid_property_default_response</h4> @@ -108,7 +117,7 @@ - + url @@ -141,7 +150,7 @@ <p>&gt; Note: provided username / password or auth objects take precedence over token based security</p> Perform a request using the security token or authentication set in the library. - + url @@ -155,7 +164,7 @@ <p>Ensure that the (right-most) <span class="name">id</span> of the resource referenced by the <span class="name">url</span> is used by the resource defined by the <span class="name">resource_relation</span>.</p> Ensure that the (right-most) `id` of the resource referenced by the `url` is used by the resource defined by the `resource_relation`. - + url @@ -165,7 +174,7 @@ <p>Perform a GET request on the <span class="name">url</span> and return the list of resource <span class="name">ids</span> from the response.</p> Perform a GET request on the `url` and return the list of resource `ids` from the response. - + url @@ -188,7 +197,7 @@ <p>&gt; Note: applicable UniquePropertyValueConstraint and IdReference Relations are considered before changes to <span class="name">json_data</span> are made.</p> Return `json_data` based on the `dto` on the `request_data` that will cause the provided `status_code` for the `method` operation on the `url`. - + status_code @@ -202,7 +211,7 @@ <p>Returns a version of <span class="name">params, headers</span> as present on <span class="name">request_data</span> that has been modified to cause the provided <span class="name">status_code</span>.</p> Returns a version of `params, headers` as present on `request_data` that has been modified to cause the provided `status_code`. - + valid_url @@ -213,7 +222,7 @@ <p>Raises ValueError if the valid_url cannot be invalidated.</p> Return an url with all the path parameters in the `valid_url` replaced by a random UUID. - + schema @@ -232,7 +241,7 @@ <p>Generate a valid (json-compatible) dict for all the <span class="name">dto_class</span> properties.</p> Generate a valid (json-compatible) dict for all the `dto_class` properties. - + url @@ -254,7 +263,7 @@ <p>Return <span class="name">json_data</span> based on the <span class="name">UniquePropertyValueConstraint</span> that must be returned by the <span class="name">get_relations</span> implementation on the <span class="name">dto</span> for the given <span class="name">conflict_status_code</span>.</p> Return `json_data` based on the `UniquePropertyValueConstraint` that must be returned by the `get_relations` implementation on the `dto` for the given `conflict_status_code`. - + url @@ -264,7 +273,7 @@ <p>Return the endpoint as found in the <span class="name">paths</span> section based on the given <span class="name">url</span>.</p> Return the endpoint as found in the `paths` section based on the given `url`. - + endpoint @@ -278,7 +287,7 @@ <p>Return an object with valid request data for body, headers and query params.</p> Return an object with valid request data for body, headers and query params. - + endpoint @@ -293,7 +302,7 @@ <p>To prevent resource conflicts with other test cases, a new resource is created (POST) if possible.</p> Support keyword that returns the `id` for an existing resource at `endpoint`. - + endpoint @@ -383,5 +392,16 @@ Get Valid Url + +<p>Strings must be Python <a href="https://docs.python.org/library/stdtypes.html#tuple">tuple</a> literals. They are converted to actual tuples using the <a href="https://docs.python.org/library/ast.html#ast.literal_eval">ast.literal_eval</a> function. They can contain any values <code>ast.literal_eval</code> supports, including tuples and other containers.</p> +<p>Examples: <code>('one', 'two')</code>, <code>(('one', 1), ('two', 2))</code></p> + +string +Sequence + + +__init__ + + diff --git a/src/OpenApiLibCore/openapi_libcore.py b/src/OpenApiLibCore/openapi_libcore.py index d9b0523..1805224 100644 --- a/src/OpenApiLibCore/openapi_libcore.py +++ b/src/OpenApiLibCore/openapi_libcore.py @@ -374,6 +374,7 @@ def __init__( # pylint: disable=too-many-arguments, too-many-locals, dangerous- password: str = "", security_token: str = "", auth: Optional[AuthBase] = None, + cert: Optional[Union[str, Tuple[str, str]]] = None, extra_headers: Optional[Dict[str, str]] = None, invalid_property_default_response: int = 422, recursion_limit: int = 1, @@ -408,6 +409,10 @@ def __init__( # pylint: disable=too-many-arguments, too-many-locals, dangerous- A [https://requests.readthedocs.io/en/latest/api/#authentication | requests AuthBase instance] to be used for authentication instead of the ``username`` and ``password``. + === cert === + The SSL certificate to use with all requests. + If string: the path to ssl client cert file (.pem). If tuple, ('cert', 'key') pair. + === extra_headers === A dictionary with extra / custom headers that will be send with every request. This parameter can be used to send headers that are not documented in the @@ -472,6 +477,7 @@ def recursion_limit_handler(limit, refstring, recursions): self.auth = auth if username and password: self.auth = HTTPBasicAuth(username, password) + self.cert = cert self.extra_headers = extra_headers self.invalid_property_default_response = invalid_property_default_response if mappings_path and str(mappings_path) != ".": @@ -1204,6 +1210,7 @@ def authorized_request( # pylint: disable=too-many-arguments headers=headers, json=json_data, auth=self.auth, + cert=self.cert, verify=False, ) logger.debug(f"Response text: {response.text}")