robotframework-openapitools 1.0.0b5__py3-none-any.whl → 1.0.1__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.
@@ -1,123 +1,3 @@
1
- """
2
- # OpenApiLibCore for Robot Framework
3
-
4
- The OpenApiLibCore library is a utility library that is meant to simplify creation
5
- of other Robot Framework libraries for API testing based on the information in
6
- an OpenAPI document (also known as Swagger document).
7
- This document explains how to use the OpenApiLibCore library.
8
-
9
- My RoboCon 2022 talk about OpenApiDriver and OpenApiLibCore can be found
10
- [here](https://www.youtube.com/watch?v=7YWZEHxk9Ps)
11
-
12
- For more information about Robot Framework, see http://robotframework.org.
13
-
14
- ---
15
-
16
- > Note: OpenApiLibCore is still being developed so there are currently
17
- restrictions / limitations that you may encounter when using this library to run
18
- tests against an API. See [Limitations](#limitations) for details.
19
-
20
- ---
21
-
22
- ## Installation
23
-
24
- If you already have Python >= 3.8 with pip installed, you can simply run:
25
-
26
- `pip install --upgrade robotframework-openapi-libcore`
27
-
28
- ---
29
-
30
- ## OpenAPI (aka Swagger)
31
-
32
- The OpenAPI Specification (OAS) defines a standard, language-agnostic interface
33
- to RESTful APIs, see https://swagger.io/specification/
34
-
35
- The OpenApiLibCore implements a number of Robot Framework keywords that make it
36
- easy to interact with an OpenAPI implementation by using the information in the
37
- openapi document (Swagger file), for examply by automatic generation of valid values
38
- for requests based on the schema information in the document.
39
-
40
- > Note: OpenApiLibCore is designed for APIs based on the OAS v3
41
- The library has not been tested for APIs based on the OAS v2.
42
-
43
- ---
44
-
45
- ## Getting started
46
-
47
- Before trying to use the keywords exposed by OpenApiLibCore on the target API
48
- it's recommended to first ensure that the openapi document for the API is valid
49
- under the OpenAPI Specification.
50
-
51
- This can be done using the command line interface of a package that is installed as
52
- a prerequisite for OpenApiLibCore.
53
- Both a local openapi.json or openapi.yaml file or one hosted by the API server
54
- can be checked using the `prance validate <reference_to_file>` shell command:
55
-
56
- ```shell
57
- prance validate --backend=openapi-spec-validator http://localhost:8000/openapi.json
58
- Processing "http://localhost:8000/openapi.json"...
59
- -> Resolving external references.
60
- Validates OK as OpenAPI 3.0.2!
61
-
62
- prance validate --backend=openapi-spec-validator /tests/files/petstore_openapi.yaml
63
- Processing "/tests/files/petstore_openapi.yaml"...
64
- -> Resolving external references.
65
- Validates OK as OpenAPI 3.0.2!
66
- ```
67
-
68
- You'll have to change the url or file reference to the location of the openapi
69
- document for your API.
70
-
71
- > Note: Although recursion is technically allowed under the OAS, tool support is limited
72
- and changing the OAS to not use recursion is recommended.
73
- OpenApiLibCore has limited support for parsing OpenAPI documents with
74
- recursion in them. See the `recursion_limit` and `recursion_default` parameters.
75
-
76
- If the openapi document passes this validation, the next step is trying to do a test
77
- run with a minimal test suite.
78
- The example below can be used, with `source`, `origin` and `path` altered to
79
- fit your situation.
80
-
81
- ``` robotframework
82
- *** Settings ***
83
- Library OpenApiLibCore
84
- ... source=http://localhost:8000/openapi.json
85
- ... origin=http://localhost:8000
86
-
87
- *** Test Cases ***
88
- Getting Started
89
- ${url}= Get Valid Url path=/employees/{employee_id}
90
-
91
- ```
92
-
93
- Running the above suite for the first time may result in an error / failed test.
94
- You should look at the Robot Framework `log.html` to determine the reasons
95
- for the failing tests.
96
- Depending on the reasons for the failures, different solutions are possible.
97
-
98
- Details about the OpenApiLibCore library parameters and keywords that you may need can be found
99
- [here](https://marketsquare.github.io/robotframework-openapi-libcore/openapi_libcore.html).
100
-
101
- The OpenApiLibCore also support handling of relations between resources within the scope
102
- of the API being validated as well as handling dependencies on resources outside the
103
- scope of the API. In addition there is support for handling restrictions on the values
104
- of parameters and properties.
105
-
106
- Details about the `mappings_path` variable usage can be found
107
- [here](https://marketsquare.github.io/robotframework-openapi-libcore/advanced_use.html).
108
-
109
- ---
110
-
111
- ## Limitations
112
-
113
- There are currently a number of limitations to supported API structures, supported
114
- data types and properties. The following list details the most important ones:
115
- - Only JSON request and response bodies are supported.
116
- - No support for per-endpoint authorization levels.
117
- - Parsing of OAS 3.1 documents is supported by the parsing tools, but runtime behavior is untested.
118
-
119
- """
120
-
121
1
  import json as _json
122
2
  import sys
123
3
  from collections.abc import Mapping, MutableMapping
@@ -165,21 +45,18 @@ from OpenApiLibCore.parameter_utils import (
165
45
  )
166
46
  from OpenApiLibCore.protocols import ResponseValidatorType
167
47
  from OpenApiLibCore.request_data import RequestData, RequestValues
48
+ from openapitools_docs.docstrings import (
49
+ OPENAPILIBCORE_INIT_DOCSTRING,
50
+ OPENAPILIBCORE_LIBRARY_DOCSTRING,
51
+ )
168
52
 
169
53
  run_keyword = BuiltIn().run_keyword
170
54
  default_str_mapping: Mapping[str, str] = MappingProxyType({})
171
55
  default_json_mapping: Mapping[str, JSON] = MappingProxyType({})
172
56
 
173
57
 
174
- @library(scope="SUITE", doc_format="ROBOT")
58
+ @library(scope="SUITE", doc_format="HTML")
175
59
  class OpenApiLibCore: # pylint: disable=too-many-public-methods
176
- """
177
- Main class providing the keywords and core logic to interact with an OpenAPI server.
178
-
179
- Visit the [https://github.com/MarketSquare/robotframework-openapi-libcore | library page]
180
- for an introduction.
181
- """
182
-
183
60
  def __init__( # noqa: PLR0913, pylint: disable=dangerous-default-value
184
61
  self,
185
62
  source: str,
@@ -204,126 +81,6 @@ class OpenApiLibCore: # pylint: disable=too-many-public-methods
204
81
  cookies: MutableMapping[str, str] | CookieJar | None = None,
205
82
  proxies: MutableMapping[str, str] | None = None,
206
83
  ) -> None:
207
- """
208
- == Base parameters ==
209
-
210
- === source ===
211
- An absolute path to an openapi.json or openapi.yaml file or an url to such a file.
212
-
213
- === origin ===
214
- The server (and port) of the target server. E.g. ``https://localhost:8000``
215
-
216
- === base_path ===
217
- The routing between ``origin`` and the paths as found in the ``paths``
218
- section in the openapi document.
219
- E.g. ``/petshop/v2``.
220
-
221
- == Test case execution ==
222
-
223
- === response_validation ===
224
- By default, a ``WARN`` is logged when the Response received after a Request does not
225
- comply with the schema as defined in the openapi document for the given operation. The
226
- following values are supported:
227
-
228
- - ``DISABLED``: All Response validation errors will be ignored
229
- - ``INFO``: Any Response validation erros will be logged at ``INFO`` level
230
- - ``WARN``: Any Response validation erros will be logged at ``WARN`` level
231
- - ``STRICT``: The Test Case will fail on any Response validation errors
232
-
233
- === disable_server_validation ===
234
- If enabled by setting this parameter to ``True``, the Response validation will also
235
- include possible errors for Requests made to a server address that is not defined in
236
- the list of servers in the openapi document. This generally means that if there is a
237
- mismatch, every Test Case will raise this error. Note that ``localhost`` and
238
- ``127.0.0.1`` are not considered the same by Response validation.
239
-
240
- == API-specific configurations ==
241
-
242
- === mappings_path ===
243
- See [https://marketsquare.github.io/robotframework-openapi-libcore/advanced_use.html | this page]
244
- for an in-depth explanation.
245
-
246
- === invalid_property_default_response ===
247
- The default response code for requests with a JSON body that does not comply
248
- with the schema.
249
- Example: a value outside the specified range or a string value
250
- for a property defined as integer in the schema.
251
-
252
- === default_id_property_name ===
253
- The default name for the property that identifies a resource (i.e. a unique
254
- entity) within the API.
255
- The default value for this property name is ``id``.
256
- If the target API uses a different name for all the resources within the API,
257
- you can configure it globally using this property.
258
-
259
- If different property names are used for the unique identifier for different
260
- types of resources, an ``ID_MAPPING`` can be implemented using the ``mappings_path``.
261
-
262
- === faker_locale ===
263
- A locale string or list of locale strings to pass to the Faker library to be
264
- used in generation of string data for supported format types.
265
-
266
- === require_body_for_invalid_url ===
267
- When a request is made against an invalid url, this usually is because of a "404" request;
268
- a request for a resource that does not exist. Depending on API implementation, when a
269
- request with a missing or invalid request body is made on a non-existent resource,
270
- either a 404 or a 422 or 400 Response is normally returned. If the API being tested
271
- processes the request body before checking if the requested resource exists, set
272
- this parameter to True.
273
-
274
- == Parsing parameters ==
275
-
276
- === recursion_limit ===
277
- The recursion depth to which to fully parse recursive references before the
278
- `recursion_default` is used to end the recursion.
279
-
280
- === recursion_default ===
281
- The value that is used instead of the referenced schema when the
282
- `recursion_limit` has been reached.
283
- The default `{}` represents an empty object in JSON.
284
- Depending on schema definitions, this may cause schema validation errors.
285
- If this is the case, 'None' (``${NONE}`` in Robot Framework) or an empty list
286
- can be tried as an alternative.
287
-
288
- == Security-related parameters ==
289
- _Note: these parameters are equivalent to those in the ``requests`` library._
290
-
291
- === username ===
292
- The username to be used for Basic Authentication.
293
-
294
- === password ===
295
- The password to be used for Basic Authentication.
296
-
297
- === security_token ===
298
- The token to be used for token based security using the ``Authorization`` header.
299
-
300
- === auth ===
301
- A [https://requests.readthedocs.io/en/latest/api/#authentication | requests ``AuthBase`` instance]
302
- to be used for authentication instead of the ``username`` and ``password``.
303
-
304
- === cert ===
305
- The SSL certificate to use with all requests.
306
- If string: the path to ssl client cert file (.pem).
307
- If tuple: the ('cert', 'key') pair.
308
-
309
- === verify_tls ===
310
- Whether or not to verify the TLS / SSL certificate of the server.
311
- If boolean: whether or not to verify the server TLS certificate.
312
- If string: path to a CA bundle to use for verification.
313
-
314
- === extra_headers ===
315
- A dictionary with extra / custom headers that will be send with every request.
316
- This parameter can be used to send headers that are not documented in the
317
- openapi document or to provide an API-key.
318
-
319
- === cookies ===
320
- A dictionary or
321
- [https://docs.python.org/3/library/http.cookiejar.html#http.cookiejar.CookieJar | CookieJar object]
322
- to send with all requests.
323
-
324
- === proxies ===
325
- A dictionary of 'protocol': 'proxy url' to use for all requests.
326
- """
327
84
  self._source = source
328
85
  self._origin = origin
329
86
  self._base_path = base_path
@@ -912,3 +669,8 @@ class OpenApiLibCore: # pylint: disable=too-many-public-methods
912
669
 
913
670
  def read_paths(self) -> dict[str, PathItemObject]:
914
671
  return self.openapi_spec.paths
672
+
673
+ __init__.__doc__ = OPENAPILIBCORE_INIT_DOCSTRING
674
+
675
+
676
+ OpenApiLibCore.__doc__ = OPENAPILIBCORE_LIBRARY_DOCSTRING
@@ -0,0 +1,3 @@
1
+ from openapitools_docs.docstrings import OPENAPILIBGEN_DOCUMENTATION
2
+
3
+ __doc__ = OPENAPILIBGEN_DOCUMENTATION
@@ -8,8 +8,6 @@ from openapi_libgen.spec_parser import get_keyword_data
8
8
  from OpenApiLibCore.models import OpenApiObject
9
9
 
10
10
  HERE = Path(__file__).parent.resolve()
11
- INIT_TEMPLATE_PATH = HERE / "templates/__init__.jinja"
12
- LIBRARY_TEMPLATE_PATH = HERE / "templates/library.jinja"
13
11
 
14
12
 
15
13
  def load_openapi_spec(
File without changes