Modules
scanapi package modules
The modules below are documented automatically from their docstrings.
Core
from_()
Convert from other formats into ScanAPI
Source code in scanapi/cli.py
135 136 137 | |
from_openapi(input_path, base_url, output_path, log_level, config_path)
Convert an OpenAPI document (JSON or YAML) into ScanAPI format.
Arguments: OPENAPI_PATH: The OpenAPI file path (JSON or YAML).
Examples: scanapi from openapi api.json scanapi from openapi api.yaml -o scanapi.yaml
Source code in scanapi/cli.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
main()
Automated Testing and Documentation for your REST API.
Source code in scanapi/cli.py
67 68 69 70 | |
run(spec_path, output_path, no_report, config_path, template, log_level, open_browser)
Automated Testing and Documentation for your REST API.
Source code in scanapi/cli.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
Code Reference https://gist.github.com/joshbode/569627ced3076931b02f
Loader
Bases: SafeLoader
YAML/JSON Loader with !include constructor.
Source code in scanapi/config_loader.py
14 15 16 17 18 19 20 21 22 23 24 | |
__init__(stream)
Initialise Loader.
Source code in scanapi/config_loader.py
17 18 19 20 21 22 23 24 | |
construct_include(loader, node)
Include file referenced at node.
Source code in scanapi/config_loader.py
27 28 29 30 31 32 33 34 35 36 37 38 | |
load_config_file(file_path)
Loads configuration file. If non-empty file exists reads data and returns it.
Source code in scanapi/config_loader.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
write_report_path(uri)
Print path to generated documentation
Source code in scanapi/console.py
29 30 31 32 33 34 | |
write_result(result)
Print the test result to the console output
Source code in scanapi/console.py
17 18 19 20 21 22 23 24 25 26 | |
write_results(results)
Print the test results to the console output
Source code in scanapi/console.py
11 12 13 14 | |
write_summary()
Write tests summary in console
Source code in scanapi/console.py
37 38 39 40 41 42 43 44 45 | |
openapi_to_scanapi()
Caller function that tries to convert the specification file and write the report.
Uses prance for resolving and parsing the OpenAPI schema.
Source code in scanapi/convert.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
BadConfigIncludeError
Bases: Exception
Raised when the value of the !include yaml tag is not a scalar.
Source code in scanapi/errors.py
70 71 | |
BadConfigurationError
Bases: Exception
Raised when an environment variable was not set or badly configured.
Source code in scanapi/errors.py
52 53 54 55 56 57 58 59 | |
EmptyConfigFileError
Bases: Exception
Raised when the Config File loaded is empty
Source code in scanapi/errors.py
62 63 64 65 66 67 | |
HTTPMethodNotAllowedError
Bases: MalformedSpecError
Raised when the HTTP method in the API spec is invalid
Source code in scanapi/errors.py
8 9 10 11 12 13 14 15 16 | |
InvalidKeyError
Bases: MalformedSpecError
Raised when an invalid key is specified in the API spec
Source code in scanapi/errors.py
19 20 21 22 23 24 25 26 27 | |
InvalidPythonCodeError
Bases: MalformedSpecError
Raised when python code defined in the API spec raises an error
Source code in scanapi/errors.py
39 40 41 42 43 44 45 46 47 48 49 | |
MalformedSpecError
Bases: Exception
Raised when API spec is invalid;
base class for other exceptions
Source code in scanapi/errors.py
1 2 3 4 5 | |
MissingMandatoryKeyError
Bases: MalformedSpecError
Raised when one or more mandatory keys are missing
Source code in scanapi/errors.py
30 31 32 33 34 35 36 | |
Code based on solution: https://github.com/pytest-dev/pytest/blob/83891d9022076375cede03bfd8c932d450e6fcf8/src/_pytest/config/init.py#L67
ExitCode
Bases: IntEnum
Encodes the valid exit codes by ScanAPI.
Source code in scanapi/exit_code.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | |
hide_sensitive_info(response)
Takes response and hides the sensitive data replacing the info with the
string SENSITIVE_INFORMATION.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
Response
|
Response containing sensitive information to be hidden. |
required |
Source code in scanapi/hide_utils.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
Reporter
Class that writes the scan report
Attributes:
| Name | Type | Description |
|---|---|---|
output_path |
str
|
Report output path |
template |
str
|
Custom report template path |
Source code in scanapi/reporter.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
__init__(output_path=None, template=None)
Creates a Reporter instance object.
Source code in scanapi/reporter.py
24 25 26 27 28 29 30 31 | |
write(results, open_in_browser)
Part of the Reporter instance that is responsible for writing scanapi-report.html.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
generator
|
generator of dicts resulting of Request run(). |
required |
Source code in scanapi/reporter.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
scan()
Caller function that tries to scans the file and write the report.
Source code in scanapi/scan.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
Session
Class that handles each scanapi session.
Source code in scanapi/session.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
succeed
property
Property decorated method that returns if there were no no errors or failures.
__init__()
Constructs a Session object.
Source code in scanapi/session.py
10 11 12 13 14 15 16 | |
elapsed_time()
Returns the delta of time since session object started.
Source code in scanapi/session.py
48 49 50 | |
exit()
Handles the exiting of the Session.
Source code in scanapi/session.py
26 27 28 29 30 31 32 33 34 | |
increment_errors()
Increments error count.
Source code in scanapi/session.py
44 45 46 | |
increment_failures()
Increments failure count.
Source code in scanapi/session.py
40 41 42 | |
increment_successes()
Increments success count.
Source code in scanapi/session.py
36 37 38 | |
Settings
Bases: dict
Class for generating Settings dictionary.
Source code in scanapi/settings.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
has_global_config_file
property
Checks if there is a global config file.
has_local_config_file
property
Checks if there is a local config file.
__init__()
Constructs a Settings object with default values for all possible preferences.
Source code in scanapi/settings.py
27 28 29 30 31 32 | |
save_click_preferences(**preferences)
Saves all preference items to the Settings object.
Source code in scanapi/settings.py
49 50 51 52 53 54 | |
save_config_file_preferences(config_path=None)
Saves the Settings object config file preferences.
Source code in scanapi/settings.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
save_preferences(**click_preferences)
Caller function that begins the saving of Setting preferences.
Source code in scanapi/settings.py
56 57 58 59 60 | |
group_by_top_level_endpoint(results)
Groups results by endpoint name
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
[iterator]
|
iterator of request results |
required |
Returns:
| Type | Description |
|---|---|
|
[iterator]: an iterator with tuples containing the endpoint name |
|
|
and an iterator for all request results of that endpoint |
Source code in scanapi/template_render.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
render(template_path, context, is_external=False)
Controller function that handles the Jinja2 rending of the template.
Source code in scanapi/template_render.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
render_body(request)
Render body according to its request content type.
Source code in scanapi/template_render.py
34 35 36 37 38 39 | |
TestStatus
Class that holds test statuses - passed, failed or error.
Source code in scanapi/test_status.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
__test__ = False
class-attribute
instance-attribute
Encodes the valid test status.
join_urls(first_url, second_url)
Function that returns one url if two aren't given else joins the two urls and returns them.
Source code in scanapi/utils.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 | |
session_with_retry(retry_configuration, verify=True)
Instantiate a requests session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
retry_configuration
|
dict
|
Retry configuration for a request. Available for version >= 2.2.0. |
required |
verify
|
bool
|
SSL certificates used to verify the identity of requested hosts. |
True
|
Returns:
| Type | Description |
|---|---|
Client
|
httpx.Client: Configured client session. |
Source code in scanapi/utils.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
validate_keys(keys, available_keys, required_keys, scope)
Caller function that validates keys.
Source code in scanapi/utils.py
24 25 26 27 28 29 30 31 32 | |
Converters
OpenAPIToScanAPIConverter
Class responsible for parsing an OpenAPI schema and generating a skeleton ScanAPI yaml file with correct endpoints, request methods and authentication schema.
Attributes:
| Name | Type | Description |
|---|---|---|
specs |
dict
|
Dictionary parsed from the OpenAPI schema. |
Source code in scanapi/converters/from_openapi.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | |
convert(base_url)
Runs the conversion algorithm and returns a YAML convertable dictionary.
:param specs: dictionary representing the OpenAPI specs :param base_url: Base URL for the API
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
tuple
|
converted YAML dictionary and set of created variables |
Source code in scanapi/converters/from_openapi.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | |
get_api_target_name(operation, path, method)
Generates a variable friendly name for a request. Prioritizes the summary, then operationId and, if none is defined, fall back to using the method_path format.
Changes all slashes and spaces to underscores.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
generated target name |
Source code in scanapi/converters/from_openapi.py
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | |
get_required_params(operation)
Filters the received operation for required parameters. Path parameters are always required (see https://swagger.io/docs/specification/v3_0/describing-parameters/#path-parameters).
Returns:
| Type | Description |
|---|---|
list
|
list[dict]: Parameter name and location (in) |
Source code in scanapi/converters/from_openapi.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |
get_tests(operation)
Generates basic HTTP status code validation tests based on operation responses.
Focuses on successful responses for minimal smoke testing.
Returns:
| Type | Description |
|---|---|
list
|
list[dict]: Test name and assertion |
Source code in scanapi/converters/from_openapi.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | |
Evaluators
CodeEvaluator
Source code in scanapi/evaluators/code_evaluator.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
evaluate(sequence, spec_vars, is_a_test_case=False)
classmethod
Receive a sequence of characters and evaluate Python code present in it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sequence
|
str
|
Sequence of characters to be evaluated. |
required |
spec_vars
|
dict
|
Dictionary containing SpecEvaluator variables. |
required |
is_a_test_case
|
bool
|
Indicator for checking whether the given evaluation is a test case. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
Any
|
Tuple containing: - bool: True if Python statement is valid. - str | None: None if evaluation is valid; otherwise, the tested code. |
Raises:
| Type | Description |
|---|---|
InvalidPythonCodeError
|
Raised when receiving invalid Python statements (e.g. 1/0). |
Source code in scanapi/evaluators/code_evaluator.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
SpecEvaluator
Evaluate variables and assertions defined in the ScanAPI specification.
This class maintains a registry of spec variables and evaluates expressions defined in the ScanAPI spec. It can also filter response-derived variables and supports evaluation of test case assertions.
Source code in scanapi/evaluators/spec_evaluator.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
__contains__(key)
Check whether a variable exists in the registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Variable name. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the variable exists in the registry, otherwise False. |
Source code in scanapi/evaluators/spec_evaluator.py
158 159 160 161 162 163 164 165 166 167 168 | |
__delitem__(key)
Delete a variable from the registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Variable name to delete. |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the key is not present in the registry. |
Source code in scanapi/evaluators/spec_evaluator.py
144 145 146 147 148 149 150 151 152 153 154 155 156 | |
__getitem__(key)
Retrieve a variable value from the registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Variable name to retrieve. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Value for the given key. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the key is not present in the registry or endpoint variables. |
Source code in scanapi/evaluators/spec_evaluator.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
__init__(endpoint, spec_vars, extras=None, filter_responses=True)
Initialize a SpecEvaluator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint
|
EndpointNode
|
Endpoint instance for which the spec is being evaluated. |
required |
spec_vars
|
dict
|
Variables defined in the ScanAPI specification. |
required |
extras
|
dict
|
Optional extra variables to include in the registry. |
None
|
filter_responses
|
bool
|
Whether to filter out response-related variables. |
True
|
Source code in scanapi/evaluators/spec_evaluator.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
__repr__()
Return a string representation of the evaluator registry.
Source code in scanapi/evaluators/spec_evaluator.py
117 118 119 | |
evaluate(element)
Evaluate a spec element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element
|
Any
|
Spec element/expression to evaluate. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Evaluated value of the element. |
Source code in scanapi/evaluators/spec_evaluator.py
46 47 48 49 50 51 52 53 54 55 | |
evaluate_assertion(element)
Evaluate an assertion element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element
|
Any
|
Assertion expression from a test case. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Result of the evaluated assertion. |
Source code in scanapi/evaluators/spec_evaluator.py
57 58 59 60 61 62 63 64 65 66 | |
filter_response_var(spec_vars)
classmethod
Return a copy of spec_vars without response references.
Any items with a response.* reference in their value
are left out.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, Any]
|
Filtered dictionary. |
Source code in scanapi/evaluators/spec_evaluator.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
get(key, default=None)
Retrieve a value from the registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Name of the variable to retrieve. |
required |
default
|
Any
|
Value to return if the key does not exist. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Value associated with the given key or
|
Source code in scanapi/evaluators/spec_evaluator.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
keys()
Return a copy of the dictionary keys.
Returns:
| Type | Description |
|---|---|
KeysView[str]
|
KeysView[str]: The registry keys. |
Source code in scanapi/evaluators/spec_evaluator.py
170 171 172 173 174 175 176 | |
update(spec_vars, extras=None, filter_responses=False)
Update the evaluator registry with evaluated spec variables.
This method evaluates each variable in spec_vars
(optionally using extras during evaluation) and updates
the internal registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec_vars
|
dict
|
Mapping of spec variable names to expressions/values. |
required |
extras
|
dict
|
Optional extra variables to include in the registry. |
None
|
filter_responses
|
bool
|
Whether to filter out response-related variables. |
False
|
Source code in scanapi/evaluators/spec_evaluator.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
evaluate(expression, _spec_vars)
Evaluate a spec expression based on its type.
This function is implemented using
functools.singledispatch to support different types of
expressions (e.g. strings, dictionaries, lists).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expression
|
Any
|
Expression/value to evaluate. |
required |
_spec_vars
|
Any
|
SpecEvaluator instance or variable registry used during evaluation. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Evaluated result or original expression if no evaluation is needed. |
Source code in scanapi/evaluators/spec_evaluator.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |
StringEvaluator
Class that handles environment and custom variables evaluation.
It replaces every occurrence with ${customVariable}
or ${ENV} pattern.
Source code in scanapi/evaluators/string_evaluator.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
evaluate(sequence, spec_vars, is_a_test_case=False)
classmethod
Receives a sequence of characters and evaluates any custom or environment variables present on it
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sequence
|
string
|
sequence of characters to be evaluated spec_vars (dict): dictionary containing the SpecEvaluator variables |
required |
is_a_test_case
|
bool
|
indicator for checking if the given evaluation is a test case. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
Any
|
a tuple containing: - Boolean: True if python statement is valid - string: None if valid evaluation, tested code otherwise |
Source code in scanapi/evaluators/string_evaluator.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
replace_var_with_value(sequence, variable, variable_value)
classmethod
Receives a sequence of characters and replaces every occurrence of a variable with its value
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sequence
|
string
|
sequence of characters to be evaluated |
required |
variable
|
string
|
variable to be replaced |
required |
variable_value
|
any
|
value that will replace the variable |
required |
Returns:
| Name | Type | Description |
|---|---|---|
sequence |
string
|
sequence of characters with all occurrences of |
Any
|
the current variable replaced |
Source code in scanapi/evaluators/string_evaluator.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
Tree
EndpointNode
Class that represents an endpoint. It follows a tree-like structure where each EndpointNode may contain multiple children EndpointNodes.
Attributes:
| Name | Type | Description |
|---|---|---|
spec |
dict
|
dictionary containing the endpoint's specifications |
parent |
EndpointNode
|
the parent node |
child_nodes |
list of EndpointNodes
|
the children nodes |
spec_vars |
SpecEvaluator
|
evaluator used to evaluate expressions and store spec variables |
Source code in scanapi/tree/endpoint_node.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | |
delay
property
Get the time in milliseconds to be waited before making the endpoint call.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
the time to be waited. |
headers
property
Get the headers used in the endpoint call. The headers of the call include the parent's headers.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, Any]
|
the headers used in the endpoint call. |
is_root
property
Check if the EndpointNode is a root node.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
true if the node has no parent, false otherwise. |
name
property
Get the endpoint's name. The name is prepended by the parent's name, if it is not a root node.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The endpoint's name. |
options
property
Get the keywords arguments used in the endpoint call. The options of the call include the parent's options.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, Any]
|
the keyword used in the endpoint call. |
params
property
Get the parameters used in the endpoint call. The parameters of the call include the parent's parameters.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, Any]
|
the parameters used in the endpoint call. |
path
property
Get the endpoint's path. The path is prepended by the parent's path, if it is not a root node. The returned path already has all variables evaluated.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The endpoint's url. |
__build()
Validate the EndpointNode keys and create children EndpointNodes from endpoints in its specifications.
Source code in scanapi/tree/endpoint_node.py
77 78 79 80 81 82 83 84 85 86 | |
get_all_vars()
Get all variables in spec_vars from the node and its parents.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dict[str, Any]
|
dict from the variable's name to its value. |
Source code in scanapi/tree/endpoint_node.py
205 206 207 208 209 210 211 212 213 214 215 | |
propagate_spec_vars(spec_vars, extras=None)
Update the endpoint node spec_vars and propagate those changes to the parent nodes. It only includes new variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec_vars
|
dict
|
the new spec_vars. |
required |
extras
|
dict
|
extra variables used to update the spec_vars. |
None
|
Source code in scanapi/tree/endpoint_node.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
run()
Run the requests of the node and all children nodes.
Returns:
| Name | Type | Description |
|---|---|---|
iterator |
Iterator[dict[str, Any]]
|
Iterator that yields the test result of each request. |
Source code in scanapi/tree/endpoint_node.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
RequestNode
Class that represents a request. It's used as a child of an EndpointNode where each EndpointNode may contain multiple children RequestNode.
Attributes:
| Name | Type | Description |
|---|---|---|
spec |
dict
|
dictionary containing the request's specifications |
endpoint |
EndpointNode
|
the parent node |
Source code in scanapi/tree/request_node.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | |
run()
Make HTTP requests and generating test results for the given URLs.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, Any]
|
HTTP response and test results with request node name, |
dict[str, Any]
|
to be used by the report template. |
Source code in scanapi/tree/request_node.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
TestingNode
Represents a test node defined in the ScanAPI specification.
A TestingNode validates a test definition, executing its assertion against the evaluated API response, and reporting the result status.
Source code in scanapi/tree/testing_node.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
run()
Run the test assertion and return its result.
This method evaluates the assertion defined in the test, updates the global session counters based on the outcome, and returns a dictionary describing the test execution.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, Any]
|
A dictionary containing: - name (str): Full hierarchical name of the test. - status (TestStatus): Result of the test execution. - failure (any): Assertion failure details, if available. - error (str): Error message if an exception was raised. |
Source code in scanapi/tree/testing_node.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |