Skip to content

Commit 28964f6

Browse files
authored
fix(keyword): Add to keyword set client cert, cert as tuple type (#154)
* feat: add to keyword set client cert, cert as tuple type * feat: enable ruf
1 parent 3746592 commit 28964f6

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# (optional) test hooks for all files:
88
# pre-commit run --all-files --verbose
99

10-
default_stages: [commit]
10+
default_stages: [pre-commit]
1111

1212
repos:
1313
- repo: https://github.com/pre-commit/pre-commit-hooks

docs/index.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/REST/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,13 @@ def _input_client_cert(value):
308308
+ "must have length of 2: %s" % (value)
309309
)
310310
return value
311+
if isinstance(value, (tuple)):
312+
if len(value) != 2:
313+
raise RuntimeError(
314+
"Client cert given as a (Python) tuple, "
315+
+ "must have length of 2: %s" % (value)
316+
)
317+
return value
311318
try:
312319
value = loads(value)
313320
if not isinstance(value, str + (list)):

src/REST/keywords.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
from jsonschema.exceptions import SchemaError, ValidationError
2020
from openapi_core import OpenAPI
2121
from openapi_core.exceptions import OpenAPIError
22-
from openapi_core.contrib.requests import RequestsOpenAPIRequest, \
23-
RequestsOpenAPIResponse
22+
from openapi_core.contrib.requests import (
23+
RequestsOpenAPIRequest,
24+
RequestsOpenAPIResponse,
25+
)
2426
from pytz import UnknownTimeZoneError, utc
2527
from requests import request as client
2628
from requests.auth import HTTPBasicAuth, HTTPDigestAuth, HTTPProxyAuth
@@ -47,7 +49,7 @@ def get_keyword_names(self):
4749
def set_client_cert(self, cert):
4850
"""*Sets the client cert for the requests.*
4951
50-
The cert is either a path to a .pem file, or a JSON array, or a list
52+
The cert is either a path to a .pem file, or a JSON array, or a list, or a tuple
5153
having the cert path and the key path.
5254
5355
Values ``null`` and ``${None}`` can be used for clearing the cert.
@@ -56,6 +58,7 @@ def set_client_cert(self, cert):
5658
5759
| `Set Client Cert` | ${CURDIR}/client.pem |
5860
| `Set Client Cert` | ["${CURDIR}/client.cert", "${CURDIR}/client.key"] |
61+
| `Set Client Cert` | ("${CURDIR}/client.cert", "${CURDIR}/client.key") |
5962
| `Set Client Cert` | ${paths_list} |
6063
"""
6164
self.request["cert"] = self._input_client_cert(cert)
@@ -1447,7 +1450,9 @@ def _assert_spec(self, spec, response):
14471450
raise AssertionError(e) from e
14481451
else:
14491452
try:
1450-
validate_api_call(spec, raw_request=request, raw_response=response)
1453+
validate_api_call(
1454+
spec, raw_request=request, raw_response=response
1455+
)
14511456
except ValueError as e:
14521457
raise AssertionError(e)
14531458

0 commit comments

Comments
 (0)