robotframework-schemathesislibrary 1.1.2__tar.gz
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.
- robotframework_schemathesislibrary-1.1.2/LICENSE +201 -0
- robotframework_schemathesislibrary-1.1.2/PKG-INFO +125 -0
- robotframework_schemathesislibrary-1.1.2/README.md +109 -0
- robotframework_schemathesislibrary-1.1.2/pyproject.toml +109 -0
- robotframework_schemathesislibrary-1.1.2/setup.cfg +4 -0
- robotframework_schemathesislibrary-1.1.2/src/SchemathesisLibrary/__init__.py +206 -0
- robotframework_schemathesislibrary-1.1.2/src/SchemathesisLibrary/schemathesisreader.py +96 -0
- robotframework_schemathesislibrary-1.1.2/src/robotframework_schemathesislibrary.egg-info/PKG-INFO +125 -0
- robotframework_schemathesislibrary-1.1.2/src/robotframework_schemathesislibrary.egg-info/SOURCES.txt +10 -0
- robotframework_schemathesislibrary-1.1.2/src/robotframework_schemathesislibrary.egg-info/dependency_links.txt +1 -0
- robotframework_schemathesislibrary-1.1.2/src/robotframework_schemathesislibrary.egg-info/requires.txt +4 -0
- robotframework_schemathesislibrary-1.1.2/src/robotframework_schemathesislibrary.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: robotframework-schemathesislibrary
|
|
3
|
+
Version: 1.1.2
|
|
4
|
+
Summary: Robot Framework SchemathesisLibrary to automatically create test cases from API specifications.
|
|
5
|
+
Author-email: Tatu Aalto <aalto.tatu@gmail.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Keywords: Robot Framework,Schemathesis,API Testing,Test Automation
|
|
8
|
+
Requires-Python: >=3.10.1
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: robotframework>=7.2.2
|
|
12
|
+
Requires-Dist: robotframework-datadriver>=1.11.2
|
|
13
|
+
Requires-Dist: robotframework-pythonlibcore>=4.4.1
|
|
14
|
+
Requires-Dist: schemathesis>=4.6.8
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# Robot Framework SchemathesisLibrary
|
|
18
|
+
Robot Framework SchemathesisLibrary is a library build top of the
|
|
19
|
+
[Schemathesis](https://github.com/schemathesis/schemathesis).
|
|
20
|
+
Schemathesis automatically generates thousands of test cases from
|
|
21
|
+
your OpenAPI or GraphQL schema and finds edge cases that break your
|
|
22
|
+
API.
|
|
23
|
+
|
|
24
|
+
SchemathesisLibrary uses
|
|
25
|
+
[DataDriver](https://github.com/Snooz82/robotframework-datadriver)
|
|
26
|
+
to create test cases from the Schemathesis
|
|
27
|
+
[Case](https://schemathesis.readthedocs.io/en/stable/reference/python/#schemathesis.Case)
|
|
28
|
+
object.
|
|
29
|
+
|
|
30
|
+
# Installation
|
|
31
|
+
Install with [pip](https://pypi.org/project/pip/), [uv](https://docs.astral.sh/uv/)
|
|
32
|
+
or any package manager that supports PyPi
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install robotframework-schemathesislibrary
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
# Keyword documentation
|
|
39
|
+
See
|
|
40
|
+
[keyword documentation](https://aaltat.github.io/robotframework-schemathesis/SchemathesisLibrary.html)
|
|
41
|
+
for more details. A link older keyword documentation can be found from
|
|
42
|
+
[versions page](https://aaltat.github.io/robotframework-schemathesis/versions/)
|
|
43
|
+
|
|
44
|
+
# Usage
|
|
45
|
+
Test are automatically generated based your API specification, SchemathesisLibrary uses
|
|
46
|
+
DataDriver internally, but you need to create template suite, so that DataDriver is able
|
|
47
|
+
to create needed test for your test suite.
|
|
48
|
+
|
|
49
|
+
SchemathesisLibrary must be imported by `url` or `path` argument, which tell where
|
|
50
|
+
the API specification can obtained. As like with Datadriver, there must be
|
|
51
|
+
[Test Template](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#test-templates)
|
|
52
|
+
setting defined. The template keyword must take one argument, usually referred as
|
|
53
|
+
`${case}` and the template keyword must call `Call And Validate` keyword with the
|
|
54
|
+
`${case}` argument.
|
|
55
|
+
|
|
56
|
+
Example test suite:
|
|
57
|
+
```robotframework
|
|
58
|
+
*** Settings ***
|
|
59
|
+
Library SchemathesisLibrary url=http://127.0.0.1/openapi.json
|
|
60
|
+
|
|
61
|
+
Test Template Wrapper
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
*** Test Cases ***
|
|
65
|
+
All Tests # This test is deleted by DataDriver
|
|
66
|
+
Wrapper test_case_1
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
*** Keywords ***
|
|
70
|
+
Wrapper
|
|
71
|
+
[Arguments] ${case}
|
|
72
|
+
Call And Validate ${case}
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
# Authentication
|
|
77
|
+
|
|
78
|
+
## Dynamic token authentication
|
|
79
|
+
Library currently supports Schemathesis
|
|
80
|
+
[dynamic token](https://schemathesis.readthedocs.io/en/stable/guides/auth/#dynamic-token-authentication)
|
|
81
|
+
authentication by the library import `auth` argument. The dynamic token generation
|
|
82
|
+
class should follow the Schemathesis documentation. The only addition is the import.
|
|
83
|
+
Importing the class must follow the Robot Framework library
|
|
84
|
+
[import rules](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#specifying-library-to-import)
|
|
85
|
+
, example if importing with filename, filename much match to the class name. Example
|
|
86
|
+
if test case looks like:
|
|
87
|
+
|
|
88
|
+
```robotframework
|
|
89
|
+
*** Settings ***
|
|
90
|
+
Library SchemathesisLibrary url=http://127.0.0.1/openapi.json auth=${CURDIR}/AuthExtension.py
|
|
91
|
+
Test Template Wrapper
|
|
92
|
+
|
|
93
|
+
*** Test Cases ***
|
|
94
|
+
All Tests
|
|
95
|
+
Wrapper test_case_1
|
|
96
|
+
|
|
97
|
+
*** Keywords ***
|
|
98
|
+
Wrapper
|
|
99
|
+
[Arguments] ${case}
|
|
100
|
+
Call And Validate ${case}
|
|
101
|
+
```
|
|
102
|
+
And `AuthExtension.py` looks like
|
|
103
|
+
```python
|
|
104
|
+
from base64 import b64encode
|
|
105
|
+
|
|
106
|
+
import schemathesis
|
|
107
|
+
from robot.api import logger
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
@schemathesis.auth()
|
|
111
|
+
class AuthExtension:
|
|
112
|
+
def get(self, case, ctx):
|
|
113
|
+
# Instead of hard coding secrets to class, it is better to get them dynamically.
|
|
114
|
+
# Jenkins or GitHub secrets, Azure keyvault, or from somewhere which is appropriate
|
|
115
|
+
# for your needs.
|
|
116
|
+
return b64encode("joulu:pukki".encode("utf-8")).decode("ascii")
|
|
117
|
+
|
|
118
|
+
def set(self, case, data, ctx):
|
|
119
|
+
case.headers = case.headers or {}
|
|
120
|
+
case.headers["Authorization"] = f"Basic {data}"
|
|
121
|
+
logger.debug(f"Updated headers for case: {case.operation.method} {case.operation.path}")
|
|
122
|
+
```
|
|
123
|
+
Then with all API calls, will have
|
|
124
|
+
[basic auth](https://en.wikipedia.org/wiki/Basic_access_authentication) set in the
|
|
125
|
+
headers for all calls made to your API endpoint.
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# Robot Framework SchemathesisLibrary
|
|
2
|
+
Robot Framework SchemathesisLibrary is a library build top of the
|
|
3
|
+
[Schemathesis](https://github.com/schemathesis/schemathesis).
|
|
4
|
+
Schemathesis automatically generates thousands of test cases from
|
|
5
|
+
your OpenAPI or GraphQL schema and finds edge cases that break your
|
|
6
|
+
API.
|
|
7
|
+
|
|
8
|
+
SchemathesisLibrary uses
|
|
9
|
+
[DataDriver](https://github.com/Snooz82/robotframework-datadriver)
|
|
10
|
+
to create test cases from the Schemathesis
|
|
11
|
+
[Case](https://schemathesis.readthedocs.io/en/stable/reference/python/#schemathesis.Case)
|
|
12
|
+
object.
|
|
13
|
+
|
|
14
|
+
# Installation
|
|
15
|
+
Install with [pip](https://pypi.org/project/pip/), [uv](https://docs.astral.sh/uv/)
|
|
16
|
+
or any package manager that supports PyPi
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install robotframework-schemathesislibrary
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
# Keyword documentation
|
|
23
|
+
See
|
|
24
|
+
[keyword documentation](https://aaltat.github.io/robotframework-schemathesis/SchemathesisLibrary.html)
|
|
25
|
+
for more details. A link older keyword documentation can be found from
|
|
26
|
+
[versions page](https://aaltat.github.io/robotframework-schemathesis/versions/)
|
|
27
|
+
|
|
28
|
+
# Usage
|
|
29
|
+
Test are automatically generated based your API specification, SchemathesisLibrary uses
|
|
30
|
+
DataDriver internally, but you need to create template suite, so that DataDriver is able
|
|
31
|
+
to create needed test for your test suite.
|
|
32
|
+
|
|
33
|
+
SchemathesisLibrary must be imported by `url` or `path` argument, which tell where
|
|
34
|
+
the API specification can obtained. As like with Datadriver, there must be
|
|
35
|
+
[Test Template](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#test-templates)
|
|
36
|
+
setting defined. The template keyword must take one argument, usually referred as
|
|
37
|
+
`${case}` and the template keyword must call `Call And Validate` keyword with the
|
|
38
|
+
`${case}` argument.
|
|
39
|
+
|
|
40
|
+
Example test suite:
|
|
41
|
+
```robotframework
|
|
42
|
+
*** Settings ***
|
|
43
|
+
Library SchemathesisLibrary url=http://127.0.0.1/openapi.json
|
|
44
|
+
|
|
45
|
+
Test Template Wrapper
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
*** Test Cases ***
|
|
49
|
+
All Tests # This test is deleted by DataDriver
|
|
50
|
+
Wrapper test_case_1
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
*** Keywords ***
|
|
54
|
+
Wrapper
|
|
55
|
+
[Arguments] ${case}
|
|
56
|
+
Call And Validate ${case}
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
# Authentication
|
|
61
|
+
|
|
62
|
+
## Dynamic token authentication
|
|
63
|
+
Library currently supports Schemathesis
|
|
64
|
+
[dynamic token](https://schemathesis.readthedocs.io/en/stable/guides/auth/#dynamic-token-authentication)
|
|
65
|
+
authentication by the library import `auth` argument. The dynamic token generation
|
|
66
|
+
class should follow the Schemathesis documentation. The only addition is the import.
|
|
67
|
+
Importing the class must follow the Robot Framework library
|
|
68
|
+
[import rules](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#specifying-library-to-import)
|
|
69
|
+
, example if importing with filename, filename much match to the class name. Example
|
|
70
|
+
if test case looks like:
|
|
71
|
+
|
|
72
|
+
```robotframework
|
|
73
|
+
*** Settings ***
|
|
74
|
+
Library SchemathesisLibrary url=http://127.0.0.1/openapi.json auth=${CURDIR}/AuthExtension.py
|
|
75
|
+
Test Template Wrapper
|
|
76
|
+
|
|
77
|
+
*** Test Cases ***
|
|
78
|
+
All Tests
|
|
79
|
+
Wrapper test_case_1
|
|
80
|
+
|
|
81
|
+
*** Keywords ***
|
|
82
|
+
Wrapper
|
|
83
|
+
[Arguments] ${case}
|
|
84
|
+
Call And Validate ${case}
|
|
85
|
+
```
|
|
86
|
+
And `AuthExtension.py` looks like
|
|
87
|
+
```python
|
|
88
|
+
from base64 import b64encode
|
|
89
|
+
|
|
90
|
+
import schemathesis
|
|
91
|
+
from robot.api import logger
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
@schemathesis.auth()
|
|
95
|
+
class AuthExtension:
|
|
96
|
+
def get(self, case, ctx):
|
|
97
|
+
# Instead of hard coding secrets to class, it is better to get them dynamically.
|
|
98
|
+
# Jenkins or GitHub secrets, Azure keyvault, or from somewhere which is appropriate
|
|
99
|
+
# for your needs.
|
|
100
|
+
return b64encode("joulu:pukki".encode("utf-8")).decode("ascii")
|
|
101
|
+
|
|
102
|
+
def set(self, case, data, ctx):
|
|
103
|
+
case.headers = case.headers or {}
|
|
104
|
+
case.headers["Authorization"] = f"Basic {data}"
|
|
105
|
+
logger.debug(f"Updated headers for case: {case.operation.method} {case.operation.path}")
|
|
106
|
+
```
|
|
107
|
+
Then with all API calls, will have
|
|
108
|
+
[basic auth](https://en.wikipedia.org/wiki/Basic_access_authentication) set in the
|
|
109
|
+
headers for all calls made to your API endpoint.
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "robotframework-schemathesislibrary"
|
|
3
|
+
version = "1.1.2"
|
|
4
|
+
description = "Robot Framework SchemathesisLibrary to automatically create test cases from API specifications."
|
|
5
|
+
authors = [
|
|
6
|
+
{ name="Tatu Aalto", email="aalto.tatu@gmail.com" },
|
|
7
|
+
]
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
license = "Apache-2.0"
|
|
10
|
+
requires-python = ">=3.10.1"
|
|
11
|
+
keywords = ["Robot Framework", "Schemathesis", "API Testing", "Test Automation"]
|
|
12
|
+
dependencies = [
|
|
13
|
+
"robotframework>=7.2.2",
|
|
14
|
+
"robotframework-datadriver>=1.11.2",
|
|
15
|
+
"robotframework-pythonlibcore>=4.4.1",
|
|
16
|
+
"schemathesis>=4.6.8",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[dependency-groups]
|
|
20
|
+
dev = [
|
|
21
|
+
"fastapi[standard]>=0.123.10",
|
|
22
|
+
"invoke>=2.2.1",
|
|
23
|
+
"mypy>=1.19.0",
|
|
24
|
+
"pytest>=9.0.1",
|
|
25
|
+
"requests>=2.32.5",
|
|
26
|
+
"robotframework-robocop>=6.13.0",
|
|
27
|
+
"ruff==0.14.8",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[tool.semantic_release.settings]
|
|
31
|
+
allow_zero_version = true
|
|
32
|
+
|
|
33
|
+
[tool.robocop.format]
|
|
34
|
+
overwrite = true
|
|
35
|
+
color = false
|
|
36
|
+
diff = false
|
|
37
|
+
|
|
38
|
+
configure = [
|
|
39
|
+
"OrderTags.enabled=True",
|
|
40
|
+
"NormalizeAssignments.equal_sign_type=space_and_equal_sign",
|
|
41
|
+
"RenameKeywords.enabled=True",
|
|
42
|
+
"RenameTestCases.enabled=True",
|
|
43
|
+
"RenameVariables.enabled=True",
|
|
44
|
+
"ReplaceWithVAR.enabled=True",
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
[tool.ruff]
|
|
48
|
+
line-length = 110
|
|
49
|
+
target-version = "py310"
|
|
50
|
+
|
|
51
|
+
[tool.ruff.lint]
|
|
52
|
+
select = [
|
|
53
|
+
"FAST",
|
|
54
|
+
"ANN",
|
|
55
|
+
"ASYNC",
|
|
56
|
+
"S",
|
|
57
|
+
"BLE",
|
|
58
|
+
"FBT",
|
|
59
|
+
"B",
|
|
60
|
+
"A",
|
|
61
|
+
"C4",
|
|
62
|
+
"T10",
|
|
63
|
+
"EXE",
|
|
64
|
+
"FIX",
|
|
65
|
+
"ISC",
|
|
66
|
+
"ICN",
|
|
67
|
+
"LOG",
|
|
68
|
+
"PIE",
|
|
69
|
+
"PYI",
|
|
70
|
+
"PT",
|
|
71
|
+
"Q",
|
|
72
|
+
"RSE",
|
|
73
|
+
"RET",
|
|
74
|
+
"SIM",
|
|
75
|
+
"SLOT",
|
|
76
|
+
"TID",
|
|
77
|
+
"TC",
|
|
78
|
+
"ARG",
|
|
79
|
+
"PTH",
|
|
80
|
+
"FLY",
|
|
81
|
+
"I",
|
|
82
|
+
"C90",
|
|
83
|
+
"NPY",
|
|
84
|
+
"PD",
|
|
85
|
+
"N",
|
|
86
|
+
"PERF",
|
|
87
|
+
"E",
|
|
88
|
+
"W",
|
|
89
|
+
"F",
|
|
90
|
+
"PL",
|
|
91
|
+
"UP",
|
|
92
|
+
"FURB",
|
|
93
|
+
"RUF",
|
|
94
|
+
"TRY"
|
|
95
|
+
]
|
|
96
|
+
|
|
97
|
+
ignore = [
|
|
98
|
+
"ANN401",
|
|
99
|
+
"E501",
|
|
100
|
+
"TRY003",
|
|
101
|
+
"N999"
|
|
102
|
+
]
|
|
103
|
+
|
|
104
|
+
[tool.ruff.format]
|
|
105
|
+
quote-style = "double"
|
|
106
|
+
|
|
107
|
+
[tool.mypy]
|
|
108
|
+
python_version = "3.10"
|
|
109
|
+
files = "src/SchemathesisLibrary"
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
# Copyright 2025- Tatu Aalto
|
|
2
|
+
#
|
|
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
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
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.
|
|
14
|
+
from typing import TYPE_CHECKING, Any
|
|
15
|
+
|
|
16
|
+
from DataDriver import DataDriver # type: ignore
|
|
17
|
+
from robot.api import logger
|
|
18
|
+
from robot.api.deco import keyword
|
|
19
|
+
from robot.result.model import TestCase as ResultTestCase # type: ignore
|
|
20
|
+
from robot.result.model import TestSuite as ResultTestSuite # type: ignore
|
|
21
|
+
from robot.running.model import TestCase, TestSuite # type: ignore
|
|
22
|
+
from robot.utils.dotdict import DotDict # type: ignore
|
|
23
|
+
from robotlibcore import DynamicCore # type: ignore
|
|
24
|
+
from schemathesis import Case
|
|
25
|
+
from schemathesis.core import NotSet
|
|
26
|
+
from schemathesis.core.transport import Response
|
|
27
|
+
|
|
28
|
+
from .schemathesisreader import Options, SchemathesisReader
|
|
29
|
+
|
|
30
|
+
if TYPE_CHECKING:
|
|
31
|
+
from pathlib import Path
|
|
32
|
+
|
|
33
|
+
__version__ = "1.1.2"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class SchemathesisLibrary(DynamicCore):
|
|
37
|
+
"""SchemathesisLibrary is a library for validating API cases using Schemathesis.
|
|
38
|
+
|
|
39
|
+
%TOC%
|
|
40
|
+
|
|
41
|
+
Example usage of the library and the `Call And Validate` keyword
|
|
42
|
+
|
|
43
|
+
Library must be imported with the `url` or `path` argument to specify the
|
|
44
|
+
OpenAPI schema. The library uses
|
|
45
|
+
[https://github.com/Snooz82/robotframework-datadriver|DataDriver] to generate
|
|
46
|
+
test cases from the OpenAPI schema by using
|
|
47
|
+
[https://github.com/schemathesis/schemathesis|Schemathesis]. The library
|
|
48
|
+
creates test cases that takes one argument, `${case}`, which is a
|
|
49
|
+
Schemathesis
|
|
50
|
+
[https://schemathesis.readthedocs.io/en/stable/reference/python/#schemathesis.Case|Case]
|
|
51
|
+
object. The `Call And Validate` keyword can be used to call and validate
|
|
52
|
+
the case. The keyword will log the request and response details.
|
|
53
|
+
|
|
54
|
+
Example:
|
|
55
|
+
| *** Settings ***
|
|
56
|
+
| Library SchemathesisLibrary url=http://127.0.0.1/openapi.json
|
|
57
|
+
|
|
|
58
|
+
| Test Template Wrapper
|
|
59
|
+
|
|
|
60
|
+
| *** Test Cases ***
|
|
61
|
+
| All Tests # This test is deleted by DataDriver
|
|
62
|
+
| Wrapper test_case_1
|
|
63
|
+
|
|
|
64
|
+
| *** Keywords ***
|
|
65
|
+
| Wrapper
|
|
66
|
+
| [Arguments] ${case}
|
|
67
|
+
| Call And Validate ${case}
|
|
68
|
+
"""
|
|
69
|
+
|
|
70
|
+
ROBOT_LIBRARY_VERSION = __version__
|
|
71
|
+
ROBOT_LISTENER_API_VERSION = 3
|
|
72
|
+
ROBOT_LIBRARY_SCOPE = "TEST SUITE"
|
|
73
|
+
|
|
74
|
+
def __init__(
|
|
75
|
+
self,
|
|
76
|
+
*,
|
|
77
|
+
headers: "dict[str, Any]|None" = None,
|
|
78
|
+
max_examples: int = 5,
|
|
79
|
+
path: "Path|None" = None,
|
|
80
|
+
url: "str|None" = None,
|
|
81
|
+
auth: str | None = None,
|
|
82
|
+
) -> None:
|
|
83
|
+
"""The SchemathesisLibrary can be initialized with the following arguments:
|
|
84
|
+
|
|
85
|
+
| =Argument= | =Description= |
|
|
86
|
+
| `headers` | Optional HTTP headers to be used when schema is downloaded from `url`. |
|
|
87
|
+
| `max_examples` | Maximum number of examples to generate for each operation. Default is 5. |
|
|
88
|
+
| `path` | Path to the OpenAPI schema file. Using either `path` or `url` is mandatory. |
|
|
89
|
+
| `url` | URL where the OpenAPI schema can be downloaded. |
|
|
90
|
+
| `auth` | Optional authentication class to be used passed for Schemathesis authentication when test cases are executed. |
|
|
91
|
+
|
|
92
|
+
The `headers` argument is only needed when the schema is downloaded from a URL and there is need to pass example
|
|
93
|
+
authentication headers to the endpoint. `headers` is not used the API calls are made during test execution.
|
|
94
|
+
|
|
95
|
+
`path` and `url` are mutually exclusive, only one of them should be used to specify the OpenAPI schema location.
|
|
96
|
+
|
|
97
|
+
`auth` can be used create Schemathesis
|
|
98
|
+
[https://schemathesis.readthedocs.io/en/stable/guides/auth/#dynamic-token-authentication|dynamic token]
|
|
99
|
+
authentication for the test cases. The dynamic token generation class should
|
|
100
|
+
follow the Schemathesis documentation. The only addition is the import. Importing
|
|
101
|
+
the class must follow the Robot Framework library
|
|
102
|
+
[https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#specifying-library-to-import|import rules]
|
|
103
|
+
, example if importing with filename, filename much match to the class name.
|
|
104
|
+
See example from
|
|
105
|
+
[https://github.com/aaltat/robotframework-schemathesis?tab=readme-ov-file##dynamic-token-authentication|README.md]
|
|
106
|
+
file
|
|
107
|
+
"""
|
|
108
|
+
self.ROBOT_LIBRARY_LISTENER = self
|
|
109
|
+
SchemathesisReader.options = Options(
|
|
110
|
+
headers=headers, max_examples=max_examples, path=path, url=url, auth=auth
|
|
111
|
+
)
|
|
112
|
+
self.data_driver = DataDriver(reader_class=SchemathesisReader)
|
|
113
|
+
DynamicCore.__init__(self, [])
|
|
114
|
+
|
|
115
|
+
def _start_suite(self, data: TestSuite, result: ResultTestSuite) -> None:
|
|
116
|
+
self.data_driver._start_suite(data, result)
|
|
117
|
+
|
|
118
|
+
def _start_test(self, data: TestCase, result: ResultTestCase) -> None:
|
|
119
|
+
self.data_driver._start_test(data, result)
|
|
120
|
+
|
|
121
|
+
@keyword
|
|
122
|
+
def call_and_validate(
|
|
123
|
+
self,
|
|
124
|
+
case: Case,
|
|
125
|
+
*,
|
|
126
|
+
base_url: str | None = None,
|
|
127
|
+
headers: dict[str, Any] | None = None,
|
|
128
|
+
) -> Response:
|
|
129
|
+
"""Call and validate a Schemathesis case.
|
|
130
|
+
|
|
131
|
+
Example:
|
|
132
|
+
| ${response} = Call And Validate Case ${case}
|
|
133
|
+
"""
|
|
134
|
+
headers = self._dot_dict_to_dict(headers) if headers else None
|
|
135
|
+
self.info(f"Case: {case.path} | {case.method} | {case.path_parameters}")
|
|
136
|
+
self._log_case(case, headers)
|
|
137
|
+
response = case.call_and_validate(base_url=base_url, headers=headers)
|
|
138
|
+
self._log_request(response)
|
|
139
|
+
self.debug(f"Response: {response.headers} | {response.status_code} | {response.text}")
|
|
140
|
+
return response
|
|
141
|
+
|
|
142
|
+
@keyword
|
|
143
|
+
def call(
|
|
144
|
+
self,
|
|
145
|
+
case: Case,
|
|
146
|
+
*,
|
|
147
|
+
base_url: str | None = None,
|
|
148
|
+
headers: dict[str, Any] | None = None,
|
|
149
|
+
) -> Response:
|
|
150
|
+
"""Call a Schemathesis case without validation.
|
|
151
|
+
|
|
152
|
+
The `Call` and `Validate Response` keywords can be used together
|
|
153
|
+
to call a case and validate the response.
|
|
154
|
+
|
|
155
|
+
Example:
|
|
156
|
+
| ${response} = Call Case ${case}
|
|
157
|
+
| Validate Response ${case} ${response}
|
|
158
|
+
"""
|
|
159
|
+
headers = self._dot_dict_to_dict(headers) if headers else None
|
|
160
|
+
self.info(f"Calling case: {case.path} | {case.method} | {case.path_parameters}")
|
|
161
|
+
self._log_case(case)
|
|
162
|
+
response = case.call(base_url=base_url, headers=headers)
|
|
163
|
+
self._log_request(response)
|
|
164
|
+
return response
|
|
165
|
+
|
|
166
|
+
@keyword
|
|
167
|
+
def validate_response(self, case: Case, response: Response) -> None:
|
|
168
|
+
"""Validate a Schemathesis response.
|
|
169
|
+
|
|
170
|
+
The response is validated against the case's expectations.
|
|
171
|
+
The `Call` and `Validate Response` keywords can be used together
|
|
172
|
+
to call a case and validate the response. See the example from
|
|
173
|
+
`Call` keyword documentation.
|
|
174
|
+
"""
|
|
175
|
+
self.info(f"Validating response: {response.status_code} | {response.headers}")
|
|
176
|
+
case.validate_response(response)
|
|
177
|
+
self.info("Response validation passed.")
|
|
178
|
+
|
|
179
|
+
def info(self, message: str) -> None:
|
|
180
|
+
logger.info(message)
|
|
181
|
+
|
|
182
|
+
def debug(self, message: str) -> None:
|
|
183
|
+
logger.debug(message)
|
|
184
|
+
|
|
185
|
+
def _log_case(
|
|
186
|
+
self,
|
|
187
|
+
case: Case,
|
|
188
|
+
headers: "dict[str, Any]|None" = None,
|
|
189
|
+
) -> None:
|
|
190
|
+
body = case.body if not isinstance(case.body, NotSet) else "Not set"
|
|
191
|
+
case_headers = headers if headers else case.headers
|
|
192
|
+
self.debug(
|
|
193
|
+
f"Case headers {case_headers!r} body {body!r} "
|
|
194
|
+
f"cookies {case.cookies!r} path parameters {case.path_parameters!r}"
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
def _log_request(self, resposen: Response) -> None:
|
|
198
|
+
self.debug(
|
|
199
|
+
f"Request: {resposen.request.method} {resposen.request.url} "
|
|
200
|
+
f"headers: {resposen.request.headers!r} body: {resposen.request.body!r}"
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
def _dot_dict_to_dict(self, dot_dict: dict[str, Any]) -> dict[str, Any]:
|
|
204
|
+
if isinstance(dot_dict, DotDict):
|
|
205
|
+
return dict(dot_dict)
|
|
206
|
+
return dot_dict
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Copyright 2025- Tatu Aalto
|
|
2
|
+
#
|
|
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
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
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.
|
|
14
|
+
from dataclasses import dataclass
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
from typing import Any
|
|
17
|
+
|
|
18
|
+
from DataDriver.AbstractReaderClass import AbstractReaderClass # type: ignore
|
|
19
|
+
from DataDriver.ReaderConfig import TestCaseData # type: ignore
|
|
20
|
+
from hypothesis import HealthCheck, Phase, Verbosity, given, settings
|
|
21
|
+
from hypothesis import strategies as st
|
|
22
|
+
from robot.api import logger
|
|
23
|
+
from robot.utils.importer import Importer # type: ignore
|
|
24
|
+
from schemathesis import Case, openapi
|
|
25
|
+
from schemathesis.core.result import Ok
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass
|
|
29
|
+
class Options:
|
|
30
|
+
max_examples: int
|
|
31
|
+
headers: dict[str, Any] | None = None
|
|
32
|
+
path: "Path|None" = None
|
|
33
|
+
url: str | None = None
|
|
34
|
+
auth: str | None = None
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class SchemathesisReader(AbstractReaderClass):
|
|
38
|
+
options: "Options|None" = None
|
|
39
|
+
|
|
40
|
+
def get_data_from_source(self) -> list[TestCaseData]:
|
|
41
|
+
if not self.options:
|
|
42
|
+
raise ValueError("Options must be set before calling get_data_from_source.")
|
|
43
|
+
url = self.options.url
|
|
44
|
+
path = self.options.path
|
|
45
|
+
if path and not Path(path).is_file():
|
|
46
|
+
raise ValueError(f"Provided path '{path}' is not a valid file.")
|
|
47
|
+
if path:
|
|
48
|
+
schema = openapi.from_path(path)
|
|
49
|
+
elif url:
|
|
50
|
+
headers = self.options.headers or {}
|
|
51
|
+
schema = openapi.from_url(url, headers=headers)
|
|
52
|
+
else:
|
|
53
|
+
raise ValueError("Either 'url' or 'path' must be provided to SchemathesisLibrary.")
|
|
54
|
+
all_cases: list[TestCaseData] = []
|
|
55
|
+
if self.options.auth:
|
|
56
|
+
import_extensions(self.options.auth)
|
|
57
|
+
logger.info(f"Using auth extension from: {self.options.auth}")
|
|
58
|
+
|
|
59
|
+
for op in schema.get_all_operations():
|
|
60
|
+
if isinstance(op, Ok):
|
|
61
|
+
# NOTE: (dd): `as_strategy` also accepts GenerationMode
|
|
62
|
+
# It could be used to produce positive / negative tests
|
|
63
|
+
strategy = op.ok().as_strategy().map(from_case) # type: ignore
|
|
64
|
+
add_examples(strategy, all_cases, self.options.max_examples) # type: ignore
|
|
65
|
+
return all_cases
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def from_case(case: Case) -> TestCaseData:
|
|
69
|
+
return TestCaseData(
|
|
70
|
+
test_case_name=f"{case.operation.label} - {case.id}",
|
|
71
|
+
arguments={"${case}": case},
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def add_examples(strategy: st.SearchStrategy, container: list[TestCaseData], max_examples: int) -> None:
|
|
76
|
+
@given(strategy)
|
|
77
|
+
@settings(
|
|
78
|
+
database=None,
|
|
79
|
+
max_examples=max_examples,
|
|
80
|
+
deadline=None,
|
|
81
|
+
verbosity=Verbosity.quiet,
|
|
82
|
+
phases=(Phase.generate,),
|
|
83
|
+
suppress_health_check=list(HealthCheck),
|
|
84
|
+
)
|
|
85
|
+
def example_generating_inner_function(ex: Any) -> None:
|
|
86
|
+
container.append(ex)
|
|
87
|
+
|
|
88
|
+
example_generating_inner_function()
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def import_extensions(library: str | Path) -> Any:
|
|
92
|
+
"""Import any extensions for SchemathesisLibrary."""
|
|
93
|
+
importer = Importer("test library")
|
|
94
|
+
lib = importer.import_module(library)
|
|
95
|
+
logger.info(f"Imported extension module: {lib}")
|
|
96
|
+
return lib
|
robotframework_schemathesislibrary-1.1.2/src/robotframework_schemathesislibrary.egg-info/PKG-INFO
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: robotframework-schemathesislibrary
|
|
3
|
+
Version: 1.1.2
|
|
4
|
+
Summary: Robot Framework SchemathesisLibrary to automatically create test cases from API specifications.
|
|
5
|
+
Author-email: Tatu Aalto <aalto.tatu@gmail.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Keywords: Robot Framework,Schemathesis,API Testing,Test Automation
|
|
8
|
+
Requires-Python: >=3.10.1
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: robotframework>=7.2.2
|
|
12
|
+
Requires-Dist: robotframework-datadriver>=1.11.2
|
|
13
|
+
Requires-Dist: robotframework-pythonlibcore>=4.4.1
|
|
14
|
+
Requires-Dist: schemathesis>=4.6.8
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# Robot Framework SchemathesisLibrary
|
|
18
|
+
Robot Framework SchemathesisLibrary is a library build top of the
|
|
19
|
+
[Schemathesis](https://github.com/schemathesis/schemathesis).
|
|
20
|
+
Schemathesis automatically generates thousands of test cases from
|
|
21
|
+
your OpenAPI or GraphQL schema and finds edge cases that break your
|
|
22
|
+
API.
|
|
23
|
+
|
|
24
|
+
SchemathesisLibrary uses
|
|
25
|
+
[DataDriver](https://github.com/Snooz82/robotframework-datadriver)
|
|
26
|
+
to create test cases from the Schemathesis
|
|
27
|
+
[Case](https://schemathesis.readthedocs.io/en/stable/reference/python/#schemathesis.Case)
|
|
28
|
+
object.
|
|
29
|
+
|
|
30
|
+
# Installation
|
|
31
|
+
Install with [pip](https://pypi.org/project/pip/), [uv](https://docs.astral.sh/uv/)
|
|
32
|
+
or any package manager that supports PyPi
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install robotframework-schemathesislibrary
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
# Keyword documentation
|
|
39
|
+
See
|
|
40
|
+
[keyword documentation](https://aaltat.github.io/robotframework-schemathesis/SchemathesisLibrary.html)
|
|
41
|
+
for more details. A link older keyword documentation can be found from
|
|
42
|
+
[versions page](https://aaltat.github.io/robotframework-schemathesis/versions/)
|
|
43
|
+
|
|
44
|
+
# Usage
|
|
45
|
+
Test are automatically generated based your API specification, SchemathesisLibrary uses
|
|
46
|
+
DataDriver internally, but you need to create template suite, so that DataDriver is able
|
|
47
|
+
to create needed test for your test suite.
|
|
48
|
+
|
|
49
|
+
SchemathesisLibrary must be imported by `url` or `path` argument, which tell where
|
|
50
|
+
the API specification can obtained. As like with Datadriver, there must be
|
|
51
|
+
[Test Template](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#test-templates)
|
|
52
|
+
setting defined. The template keyword must take one argument, usually referred as
|
|
53
|
+
`${case}` and the template keyword must call `Call And Validate` keyword with the
|
|
54
|
+
`${case}` argument.
|
|
55
|
+
|
|
56
|
+
Example test suite:
|
|
57
|
+
```robotframework
|
|
58
|
+
*** Settings ***
|
|
59
|
+
Library SchemathesisLibrary url=http://127.0.0.1/openapi.json
|
|
60
|
+
|
|
61
|
+
Test Template Wrapper
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
*** Test Cases ***
|
|
65
|
+
All Tests # This test is deleted by DataDriver
|
|
66
|
+
Wrapper test_case_1
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
*** Keywords ***
|
|
70
|
+
Wrapper
|
|
71
|
+
[Arguments] ${case}
|
|
72
|
+
Call And Validate ${case}
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
# Authentication
|
|
77
|
+
|
|
78
|
+
## Dynamic token authentication
|
|
79
|
+
Library currently supports Schemathesis
|
|
80
|
+
[dynamic token](https://schemathesis.readthedocs.io/en/stable/guides/auth/#dynamic-token-authentication)
|
|
81
|
+
authentication by the library import `auth` argument. The dynamic token generation
|
|
82
|
+
class should follow the Schemathesis documentation. The only addition is the import.
|
|
83
|
+
Importing the class must follow the Robot Framework library
|
|
84
|
+
[import rules](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#specifying-library-to-import)
|
|
85
|
+
, example if importing with filename, filename much match to the class name. Example
|
|
86
|
+
if test case looks like:
|
|
87
|
+
|
|
88
|
+
```robotframework
|
|
89
|
+
*** Settings ***
|
|
90
|
+
Library SchemathesisLibrary url=http://127.0.0.1/openapi.json auth=${CURDIR}/AuthExtension.py
|
|
91
|
+
Test Template Wrapper
|
|
92
|
+
|
|
93
|
+
*** Test Cases ***
|
|
94
|
+
All Tests
|
|
95
|
+
Wrapper test_case_1
|
|
96
|
+
|
|
97
|
+
*** Keywords ***
|
|
98
|
+
Wrapper
|
|
99
|
+
[Arguments] ${case}
|
|
100
|
+
Call And Validate ${case}
|
|
101
|
+
```
|
|
102
|
+
And `AuthExtension.py` looks like
|
|
103
|
+
```python
|
|
104
|
+
from base64 import b64encode
|
|
105
|
+
|
|
106
|
+
import schemathesis
|
|
107
|
+
from robot.api import logger
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
@schemathesis.auth()
|
|
111
|
+
class AuthExtension:
|
|
112
|
+
def get(self, case, ctx):
|
|
113
|
+
# Instead of hard coding secrets to class, it is better to get them dynamically.
|
|
114
|
+
# Jenkins or GitHub secrets, Azure keyvault, or from somewhere which is appropriate
|
|
115
|
+
# for your needs.
|
|
116
|
+
return b64encode("joulu:pukki".encode("utf-8")).decode("ascii")
|
|
117
|
+
|
|
118
|
+
def set(self, case, data, ctx):
|
|
119
|
+
case.headers = case.headers or {}
|
|
120
|
+
case.headers["Authorization"] = f"Basic {data}"
|
|
121
|
+
logger.debug(f"Updated headers for case: {case.operation.method} {case.operation.path}")
|
|
122
|
+
```
|
|
123
|
+
Then with all API calls, will have
|
|
124
|
+
[basic auth](https://en.wikipedia.org/wiki/Basic_access_authentication) set in the
|
|
125
|
+
headers for all calls made to your API endpoint.
|
robotframework_schemathesislibrary-1.1.2/src/robotframework_schemathesislibrary.egg-info/SOURCES.txt
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/SchemathesisLibrary/__init__.py
|
|
5
|
+
src/SchemathesisLibrary/schemathesisreader.py
|
|
6
|
+
src/robotframework_schemathesislibrary.egg-info/PKG-INFO
|
|
7
|
+
src/robotframework_schemathesislibrary.egg-info/SOURCES.txt
|
|
8
|
+
src/robotframework_schemathesislibrary.egg-info/dependency_links.txt
|
|
9
|
+
src/robotframework_schemathesislibrary.egg-info/requires.txt
|
|
10
|
+
src/robotframework_schemathesislibrary.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
SchemathesisLibrary
|