robotframework-schemathesislibrary 0.9.0__py3-none-any.whl → 0.10.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 robotframework-schemathesislibrary might be problematic. Click here for more details.

@@ -31,7 +31,7 @@ from schemathesis.core import NotSet
31
31
  from schemathesis.core.result import Ok
32
32
  from schemathesis.core.transport import Response
33
33
 
34
- __version__ = "0.9.0"
34
+ __version__ = "0.10.0"
35
35
 
36
36
 
37
37
  @dataclass
@@ -77,10 +77,42 @@ def from_case(case: Case) -> TestCaseData:
77
77
 
78
78
 
79
79
  class SchemathesisLibrary(DynamicCore):
80
+ """SchemathesisLibrary is a library for validating API cases using Schemathesis.
81
+
82
+ %TOC%
83
+
84
+ Example usage of the library and the `Call And Validate` keyword
85
+
86
+ Library must be imported with the `url` or `path` argument to specify the
87
+ OpenAPI schema. The library uses
88
+ [DataDriver|https://github.com/Snooz82/robotframework-datadriver] to generate
89
+ test cases from the OpenAPI schema by using
90
+ [Schemathesis|https://github.com/schemathesis/schemathesis/]. The library
91
+ creates test cases that takes one argument, `${case}`, which is a
92
+ Schemathesis
93
+ [Case|https://schemathesis.readthedocs.io/en/stable/reference/python/#schemathesis.Case]
94
+ object. The `Call And Validate` keyword can be used to call and validate
95
+ the case. The keyword will log the request and response details.
96
+
97
+ Example:
98
+ | *** Settings ***
99
+ | Library SchemathesisLibrary url=http://127.0.0.1/openapi.json
100
+ |
101
+ | Test Template Wrapper
102
+ |
103
+ | *** Test Cases ***
104
+ | All Tests # This test is deleted by DataDriver
105
+ | Wrapper test_case_1
106
+ |
107
+ | *** Keywords ***
108
+ | Wrapper
109
+ | [Arguments] ${case}
110
+ | Call And Validate ${case}
111
+ """
112
+
80
113
  ROBOT_LIBRARY_VERSION = __version__
81
114
  ROBOT_LISTENER_API_VERSION = 3
82
115
  ROBOT_LIBRARY_SCOPE = "TEST SUITE"
83
- """SchemathesisLibrary is a library for validating API cases using Schemathesis."""
84
116
 
85
117
  def __init__(
86
118
  self,
@@ -90,6 +122,14 @@ class SchemathesisLibrary(DynamicCore):
90
122
  path: "Path|None" = None,
91
123
  url: "str|None" = None,
92
124
  ) -> None:
125
+ """The SchemathesisLibrary can be initialized with the following arguments:
126
+
127
+ | =Argument= | =Description= |
128
+ | `headers` | Optional HTTP headers to be used schema is downloaded from `url`. |
129
+ | `max_examples` | Maximum number of examples to generate for each operation. Default is 5. |
130
+ | `path` | Path to the OpenAPI schema file. Using either `path` or `url` is mandatory. |
131
+ | `url` | URL where the OpenAPI schema can be downloaded. |
132
+ """
93
133
  self.ROBOT_LIBRARY_LISTENER = self
94
134
  SchemathesisReader.options = Options(headers=headers, max_examples=max_examples, path=path, url=url)
95
135
  self.data_driver = DataDriver(reader_class=SchemathesisReader)
@@ -110,7 +150,11 @@ class SchemathesisLibrary(DynamicCore):
110
150
  base_url: "str|None" = None,
111
151
  headers: "dict[str, Any]|None" = None,
112
152
  ) -> Response:
113
- """Validate a Schemathesis case."""
153
+ """Call and validate a Schemathesis case.
154
+
155
+ Example:
156
+ | ${response} = Call And Validate Case ${case}
157
+ """
114
158
  self.info(f"Case: {case.path} | {case.method} | {case.path_parameters}")
115
159
  self._log_case(case, headers)
116
160
  response = case.call_and_validate(base_url=base_url, headers=headers, auth=auth)
@@ -118,6 +162,43 @@ class SchemathesisLibrary(DynamicCore):
118
162
  self.debug(f"Response: {response.headers} | {response.status_code} | {response.text}")
119
163
  return response
120
164
 
165
+ @keyword
166
+ def call(
167
+ self,
168
+ case: Case,
169
+ *,
170
+ auth: "Any|None" = None,
171
+ base_url: "str|None" = None,
172
+ headers: "dict[str, Any]|None" = None,
173
+ ) -> Response:
174
+ """Call a Schemathesis case without validation.
175
+
176
+ The `Call` and `Validate Response` keywords can be used together
177
+ to call a case and validate the response.
178
+
179
+ Example:
180
+ | ${response} = Call Case ${case}
181
+ | Validate Response ${case} ${response}
182
+ """
183
+ self.info(f"Calling case: {case.path} | {case.method} | {case.path_parameters}")
184
+ self._log_case(case)
185
+ response = case.call(base_url=base_url, headers=headers, auth=auth)
186
+ self._log_request(response)
187
+ return response
188
+
189
+ @keyword
190
+ def validate_response(self, case: Case, response: Response) -> None:
191
+ """Validate a Schemathesis response.
192
+
193
+ The response is validated against the case's expectations.
194
+ The `Call` and `Validate Response` keywords can be used together
195
+ to call a case and validate the response. See the example from
196
+ `Call` keyword documentation.
197
+ """
198
+ self.info(f"Validating response: {response.status_code} | {response.headers}")
199
+ case.validate_response(response)
200
+ self.info("Response validation passed.")
201
+
121
202
  def info(self, message: str) -> None:
122
203
  logger.info(message)
123
204
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: robotframework-schemathesislibrary
3
- Version: 0.9.0
3
+ Version: 0.10.0
4
4
  Summary: Robot Framework SchemathesisLibrary to automatically create test cases from API specifications.
5
5
  Author-email: Tatu Aalto <aalto.tatu@gmail.com>
6
6
  License-Expression: Apache-2.0
@@ -0,0 +1,6 @@
1
+ SchemathesisLibrary/__init__.py,sha256=5djP2l57izkwadVfQxl2vr1kr2QRzv2zw_5uirdnz6E,9117
2
+ robotframework_schemathesislibrary-0.10.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
3
+ robotframework_schemathesislibrary-0.10.0.dist-info/METADATA,sha256=qolKj68hIRLbNxj9nq7r9aUxdTIE6sLkqi_FXOiWMMs,2670
4
+ robotframework_schemathesislibrary-0.10.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
5
+ robotframework_schemathesislibrary-0.10.0.dist-info/top_level.txt,sha256=bVGNag3IIuKRUVgjTtfRyDvyN3qRFYSSpmbCl5MBrUU,20
6
+ robotframework_schemathesislibrary-0.10.0.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- SchemathesisLibrary/__init__.py,sha256=KqOh3P8dCWHqedP-mawSjoeiXh1d6SUI16W3UxPBOAg,5928
2
- robotframework_schemathesislibrary-0.9.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
3
- robotframework_schemathesislibrary-0.9.0.dist-info/METADATA,sha256=711603PVQtLPiyzk-gvpxfFm_peQCkiGo67jj77DWzo,2669
4
- robotframework_schemathesislibrary-0.9.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
5
- robotframework_schemathesislibrary-0.9.0.dist-info/top_level.txt,sha256=bVGNag3IIuKRUVgjTtfRyDvyN3qRFYSSpmbCl5MBrUU,20
6
- robotframework_schemathesislibrary-0.9.0.dist-info/RECORD,,