REST
qa_pytest_rest
__all__ = ['HttpMethod', 'RestConfiguration', 'RestSteps', 'RestTests']
module-attribute
HttpMethod
Bases: str
, Enum
Enum representing HTTP methods for REST requests.
Source code in qa-pytest-rest/src/qa_pytest_rest/rest_steps.py
17 18 19 20 21 22 23 24 25 |
|
DELETE = 'DELETE'
class-attribute
instance-attribute
GET = 'GET'
class-attribute
instance-attribute
PATCH = 'PATCH'
class-attribute
instance-attribute
POST = 'POST'
class-attribute
instance-attribute
PUT = 'PUT'
class-attribute
instance-attribute
RestConfiguration
Bases: BaseConfiguration
Configuration class for REST API endpoints.
Inherits from
BaseConfiguration
Source code in qa-pytest-rest/src/qa_pytest_rest/rest_configuration.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 |
|
base_url
cached
property
Returns the base URL for the endpoint from the configuration parser.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The base URL specified in the configuration under the 'rest/base_url' key. |
resource_uri(path=EMPTY_STRING)
Constructs and returns the full endpoint URL by joining the base endpoint URL with the specified path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str
|
The path to append to the base endpoint URL. Defaults to EMPTY_STRING. |
EMPTY_STRING
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The complete URL formed by joining the base endpoint and the provided path. |
Source code in qa-pytest-rest/src/qa_pytest_rest/rest_configuration.py
32 33 34 35 36 37 38 39 40 41 42 |
|
RestSteps
Bases: GenericSteps[TConfiguration]
BDD-style step definitions for REST API operations.
Type Parameters
TConfiguration: The configuration type, must be a RestConfiguration.
Attributes:
Name | Type | Description |
---|---|---|
_rest_session |
Session
|
The HTTP session used for sending REST requests. |
Source code in qa-pytest-rest/src/qa_pytest_rest/rest_steps.py
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 |
|
invoking(request)
Send a REST request and assert that the response is OK.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request
|
Request
|
The HTTP request to send. |
required |
Returns: Self: Enables method chaining. Raises: AssertionError: If the response is not OK.
Source code in qa-pytest-rest/src/qa_pytest_rest/rest_steps.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
the_invocation(request, by_rule)
Send a REST request and assert that the response matches the given matcher.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request
|
Request
|
The HTTP request to send. |
required |
by_rule
|
Matcher[Response]
|
The matcher to apply to the response. |
required |
Returns: Self: Enables method chaining. Raises: AssertionError: If the response does not match the rule.
Source code in qa-pytest-rest/src/qa_pytest_rest/rest_steps.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
RestTests
Bases: AbstractTestsBase[TSteps, TConfiguration]
Base class for REST API test cases.
This class provides a reusable test base for REST API testing, managing a requests.Session
for each test method. It is generic over the types of steps and configuration used.
Attributes:
Name | Type | Description |
---|---|---|
_rest_session |
Session
|
The HTTP session used for making REST requests. Not thread-safe. |
Type Parameters
TSteps: The type of the steps class, typically derived from RestSteps. TConfiguration: The type of the configuration class, typically derived from RestConfiguration.
Source code in qa-pytest-rest/src/qa_pytest_rest/rest_tests.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 |
|
rest_session
property
Returns the HTTP session used for making REST requests.
Returns:
Type | Description |
---|---|
Session
|
requests.Session: The HTTP session instance. |
setup_method()
Initializes a new requests.Session before each test method.
Source code in qa-pytest-rest/src/qa_pytest_rest/rest_tests.py
42 43 44 45 46 47 48 |
|
teardown_method()
Closes the requests.Session after each test method.
Source code in qa-pytest-rest/src/qa_pytest_rest/rest_tests.py
50 51 52 53 54 55 56 57 58 |
|