dothttp-req 0.0.44a39__tar.gz → 0.0.44a41__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.
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/PKG-INFO +1 -1
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dotextensions/server/handlers/basic_handlers.py +70 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dotextensions/server/server.py +4 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dothttp/script/js3py.py +155 -1
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/pyproject.toml +1 -1
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/LICENSE.txt +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/README.md +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dotextensions/__init__.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dotextensions/server/__init__.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dotextensions/server/__main__.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dotextensions/server/agent.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dotextensions/server/handlers/__init__.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dotextensions/server/handlers/fs_handlers.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dotextensions/server/handlers/gohandler.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dotextensions/server/handlers/har2httphandler.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dotextensions/server/handlers/http2har.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dotextensions/server/handlers/http2postman.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dotextensions/server/handlers/postman2http.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dotextensions/server/models/__init__.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dotextensions/server/models/har.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dotextensions/server/postman/__init__.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dotextensions/server/postman2_1/__init__.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dotextensions/server/utils.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dotextensions/version/__init__.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dotextensions/version/__main__.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dothttp/__init__.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dothttp/__main__.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dothttp/__version__.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dothttp/auth/__init__.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dothttp/auth/azure_auth.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dothttp/exceptions.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dothttp/http.tx +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dothttp/models/__init__.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dothttp/models/computed.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dothttp/models/parse_models.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dothttp/parse/__init__.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dothttp/parse/dsl_jsonparser.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dothttp/parse/expression.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dothttp/parse/request_base.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dothttp/postScript.js +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dothttp/property_schema.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dothttp/script/__init__.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dothttp/utils/__init__.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dothttp/utils/common.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dothttp/utils/constants.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dothttp/utils/curl_utils.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dothttp/utils/json_utils.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dothttp/utils/log_utils.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dothttp/utils/property_util.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dothttp_test/__init__.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dothttp_test/__main__.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dothttp_test/conftest.py +0 -0
- {dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dothttp_test/dothttp_test.py +0 -0
{dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dotextensions/server/handlers/basic_handlers.py
RENAMED
|
@@ -21,6 +21,7 @@ from dothttp.parse.request_base import (
|
|
|
21
21
|
RequestCompiler,
|
|
22
22
|
dothttp_model,
|
|
23
23
|
)
|
|
24
|
+
from dothttp.script import DothttpResponse
|
|
24
25
|
from ..models import BaseHandler, Command, DothttpTypes, Result
|
|
25
26
|
from .gohandler import TypeFromPos
|
|
26
27
|
from . import logger
|
|
@@ -203,6 +204,13 @@ class RunHttpFileHandler(BaseHandler):
|
|
|
203
204
|
"status": resp.status_code,
|
|
204
205
|
"method": resp.request.method,
|
|
205
206
|
"url": resp.url,
|
|
207
|
+
# capture the request too so the response round-trips for a
|
|
208
|
+
# tests-only replay (redirect hops keep their own request)
|
|
209
|
+
"request": {
|
|
210
|
+
"method": resp.request.method,
|
|
211
|
+
"url": resp.request.url,
|
|
212
|
+
"headers": dict(resp.request.headers),
|
|
213
|
+
},
|
|
206
214
|
}
|
|
207
215
|
|
|
208
216
|
def get_request_comp(self, config):
|
|
@@ -325,6 +333,68 @@ class ContentExecuteHandler(RunHttpFileHandler):
|
|
|
325
333
|
return Result(id=command.id, result=result)
|
|
326
334
|
|
|
327
335
|
|
|
336
|
+
class RunTestBase:
|
|
337
|
+
"""
|
|
338
|
+
Runs only the test script of a dothttp definition against a
|
|
339
|
+
previously-captured response, without re-issuing the HTTP request.
|
|
340
|
+
|
|
341
|
+
The captured response is passed in ``command.params["response"]`` using
|
|
342
|
+
the same serialized shape that the execute handlers emit
|
|
343
|
+
(``{body, output_file, headers, status, method, url}``) and is adapted
|
|
344
|
+
into a ``requests.Response``-like object via ``DothttpResponse``.
|
|
345
|
+
"""
|
|
346
|
+
|
|
347
|
+
def get_test_result(self, command, comp: RequestCompiler) -> Result:
|
|
348
|
+
# parse + resolve + compile the test script (and pre/init scripts);
|
|
349
|
+
# crucially this does NOT call comp.get_response(), so no request goes out
|
|
350
|
+
comp.load_def()
|
|
351
|
+
if comp.property_util.errors:
|
|
352
|
+
return Result(
|
|
353
|
+
id=command.id,
|
|
354
|
+
result={
|
|
355
|
+
"errors": [
|
|
356
|
+
{"var": list(error.kwargs["var"]), "message": str(error)}
|
|
357
|
+
for error in comp.property_util.errors
|
|
358
|
+
],
|
|
359
|
+
"error": True,
|
|
360
|
+
"error_message": "errors found while resolving properties",
|
|
361
|
+
},
|
|
362
|
+
)
|
|
363
|
+
resp = DothttpResponse(command.params.get("response") or {})
|
|
364
|
+
script_result = comp.script_execution.execute_test_script(resp).as_json()
|
|
365
|
+
return Result(
|
|
366
|
+
id=command.id,
|
|
367
|
+
result={
|
|
368
|
+
"script_result": script_result,
|
|
369
|
+
**self._get_resp_data(resp),
|
|
370
|
+
},
|
|
371
|
+
)
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
class RunHttpFileTestHandler(RunHttpFileHandler, RunTestBase):
|
|
375
|
+
name = "/file/test"
|
|
376
|
+
|
|
377
|
+
def get_method(self):
|
|
378
|
+
return RunHttpFileTestHandler.name
|
|
379
|
+
|
|
380
|
+
def execute(self, command):
|
|
381
|
+
config = self.get_config(command)
|
|
382
|
+
comp = self.get_request_comp(config)
|
|
383
|
+
return self.get_test_result(command, comp)
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
class ContentTestHandler(ContentExecuteHandler, RunTestBase):
|
|
387
|
+
name = "/content/test"
|
|
388
|
+
|
|
389
|
+
def get_method(self):
|
|
390
|
+
return ContentTestHandler.name
|
|
391
|
+
|
|
392
|
+
def execute(self, command):
|
|
393
|
+
config = self.get_config(command)
|
|
394
|
+
comp = self.get_request_comp(config)
|
|
395
|
+
return self.get_test_result(command, comp)
|
|
396
|
+
|
|
397
|
+
|
|
328
398
|
class FormatHttpFileHandler(BaseHandler):
|
|
329
399
|
method = "/file/format"
|
|
330
400
|
|
|
@@ -11,9 +11,11 @@ from dothttp.__version__ import __version__ as version
|
|
|
11
11
|
from .handlers.basic_handlers import (
|
|
12
12
|
ContentExecuteHandler,
|
|
13
13
|
ContentNameReferencesHandler,
|
|
14
|
+
ContentTestHandler,
|
|
14
15
|
FormatHttpFileHandler,
|
|
15
16
|
GetNameReferencesHandler,
|
|
16
17
|
RunHttpFileHandler,
|
|
18
|
+
RunHttpFileTestHandler,
|
|
17
19
|
VersionHandler,
|
|
18
20
|
GetHoveredResolvedParamContentHandler,
|
|
19
21
|
GetHoveredResolvedParamFileHandler
|
|
@@ -37,6 +39,8 @@ handlers: Dict[str, BaseHandler] = {
|
|
|
37
39
|
GetNameReferencesHandler(),
|
|
38
40
|
ImportPostmanCollection(),
|
|
39
41
|
ContentExecuteHandler(),
|
|
42
|
+
RunHttpFileTestHandler(),
|
|
43
|
+
ContentTestHandler(),
|
|
40
44
|
Http2Har(),
|
|
41
45
|
ContentNameReferencesHandler(),
|
|
42
46
|
TypeFromPos(),
|
|
@@ -19,9 +19,13 @@ import xmltodict
|
|
|
19
19
|
import jsonschema
|
|
20
20
|
import requests
|
|
21
21
|
import yaml
|
|
22
|
+
import collections
|
|
23
|
+
import itertools
|
|
24
|
+
import re
|
|
22
25
|
from cryptography import *
|
|
23
26
|
from faker import Faker
|
|
24
27
|
from requests import Response
|
|
28
|
+
from requests.structures import CaseInsensitiveDict
|
|
25
29
|
from RestrictedPython import compile_restricted, safe_globals
|
|
26
30
|
from RestrictedPython.Eval import default_guarded_getiter
|
|
27
31
|
from RestrictedPython.Guards import guarded_iter_unpack_sequence
|
|
@@ -66,10 +70,58 @@ allowed_global = {
|
|
|
66
70
|
"open": open,
|
|
67
71
|
"json": json,
|
|
68
72
|
"yaml": yaml,
|
|
73
|
+
"dict": dict,
|
|
74
|
+
"next": next,
|
|
75
|
+
"list": list,
|
|
76
|
+
"tuple": tuple,
|
|
77
|
+
"set": set,
|
|
78
|
+
"str": str,
|
|
79
|
+
"int": int,
|
|
80
|
+
"float": float,
|
|
81
|
+
"bool": bool,
|
|
82
|
+
"bytes": bytes,
|
|
83
|
+
"bytearray": bytearray,
|
|
84
|
+
"frozenset": frozenset,
|
|
85
|
+
"enumerate": enumerate,
|
|
86
|
+
"zip": zip,
|
|
87
|
+
"range": range,
|
|
88
|
+
"reversed": reversed,
|
|
89
|
+
"sorted": sorted,
|
|
90
|
+
"filter": filter,
|
|
91
|
+
"map": map,
|
|
92
|
+
"slice": slice,
|
|
93
|
+
"len": len,
|
|
94
|
+
"max": max,
|
|
95
|
+
"min": min,
|
|
96
|
+
"sum": sum,
|
|
97
|
+
"abs": abs,
|
|
98
|
+
"round": round,
|
|
99
|
+
"pow": pow,
|
|
100
|
+
"divmod": divmod,
|
|
101
|
+
"any": any,
|
|
102
|
+
"all": all,
|
|
103
|
+
"collections": collections,
|
|
104
|
+
"defaultdict": collections.defaultdict,
|
|
105
|
+
"Counter": collections.Counter,
|
|
106
|
+
"OrderedDict": collections.OrderedDict,
|
|
107
|
+
"deque": collections.deque,
|
|
108
|
+
"namedtuple": collections.namedtuple,
|
|
109
|
+
"itertools": itertools,
|
|
110
|
+
"re": re,
|
|
111
|
+
"isinstance": isinstance,
|
|
112
|
+
"issubclass": issubclass,
|
|
69
113
|
"cryptography": cryptography,
|
|
70
114
|
"jsonschema": jsonschema,
|
|
71
115
|
"requests": requests,
|
|
72
116
|
"xmltodict": xmltodict,
|
|
117
|
+
"Exception": Exception,
|
|
118
|
+
"ValueError": ValueError,
|
|
119
|
+
"KeyError": KeyError,
|
|
120
|
+
"IndexError": IndexError,
|
|
121
|
+
"TypeError": TypeError,
|
|
122
|
+
"AttributeError": AttributeError,
|
|
123
|
+
"AssertionError": AssertionError,
|
|
124
|
+
"ZeroDivisionError": ZeroDivisionError,
|
|
73
125
|
}
|
|
74
126
|
allowed_global.update(safe_globals)
|
|
75
127
|
|
|
@@ -151,13 +203,115 @@ class Properties(dict):
|
|
|
151
203
|
self.clear(key, "")
|
|
152
204
|
|
|
153
205
|
|
|
206
|
+
@dataclass
|
|
207
|
+
class _RequestInfo:
|
|
208
|
+
method: typing.Union[None, str] = None
|
|
209
|
+
url: typing.Union[None, str] = None
|
|
210
|
+
headers: CaseInsensitiveDict = field(default_factory=CaseInsensitiveDict)
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
class DothttpResponse:
|
|
214
|
+
"""
|
|
215
|
+
A ``requests.Response``-like adapter built from dothttp's serialized
|
|
216
|
+
response format::
|
|
217
|
+
|
|
218
|
+
{
|
|
219
|
+
"body": <str | bytes>, # or "body_base64": <str>
|
|
220
|
+
"output_file": <str>,
|
|
221
|
+
"headers": {<name>: <value>},
|
|
222
|
+
"status": <int>,
|
|
223
|
+
"method": <str>,
|
|
224
|
+
"url": <str>,
|
|
225
|
+
"request_headers": {<name>: <value>}, # optional
|
|
226
|
+
"history": [<response dict>, ...], # optional, redirect hops
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
It exposes the subset of the ``requests.Response`` surface that test
|
|
230
|
+
scripts rely on (``status_code``, ``headers``, ``text``, ``content``,
|
|
231
|
+
``json()``, ``url``, ``ok``, ``request.method``, ``history`` ...), so
|
|
232
|
+
tests can run against a previously captured response without re-issuing
|
|
233
|
+
the request. ``history`` entries (redirect hops) are themselves
|
|
234
|
+
``DothttpResponse`` instances, mirroring ``requests``.
|
|
235
|
+
"""
|
|
236
|
+
|
|
237
|
+
def __init__(self, data: dict):
|
|
238
|
+
body = data.get("body", "")
|
|
239
|
+
if isinstance(body, (bytes, bytearray)):
|
|
240
|
+
self._content = bytes(body)
|
|
241
|
+
elif data.get("body_base64"):
|
|
242
|
+
self._content = base64.b64decode(data["body_base64"])
|
|
243
|
+
else:
|
|
244
|
+
self._content = (body or "").encode("utf-8")
|
|
245
|
+
self.status_code = data.get("status", 0)
|
|
246
|
+
self.headers = CaseInsensitiveDict(data.get("headers") or {})
|
|
247
|
+
self.url = data.get("url", "")
|
|
248
|
+
self.reason = data.get("reason", "")
|
|
249
|
+
self.output_file = data.get("output_file", "")
|
|
250
|
+
self.encoding = data.get("encoding") or self._guess_encoding()
|
|
251
|
+
self.cookies = data.get("cookies", {})
|
|
252
|
+
self.elapsed = datetime.timedelta(0)
|
|
253
|
+
# redirect hops, each captured in the same serialized shape
|
|
254
|
+
self.history = [
|
|
255
|
+
DothttpResponse(hop) for hop in (data.get("history") or [])
|
|
256
|
+
]
|
|
257
|
+
# the request that produced this response; a nested "request" dict
|
|
258
|
+
# takes precedence, else fall back to the top-level method/url and
|
|
259
|
+
# the "request_headers" emitted by the execute handlers
|
|
260
|
+
request = data.get("request") or {}
|
|
261
|
+
self.request = _RequestInfo(
|
|
262
|
+
method=request.get("method", data.get("method")),
|
|
263
|
+
url=request.get("url", data.get("url")),
|
|
264
|
+
headers=CaseInsensitiveDict(
|
|
265
|
+
request.get("headers") or data.get("request_headers") or {}
|
|
266
|
+
),
|
|
267
|
+
)
|
|
268
|
+
|
|
269
|
+
def _guess_encoding(self):
|
|
270
|
+
content_type = (self.headers.get("content-type") or "").lower()
|
|
271
|
+
if "charset=" in content_type:
|
|
272
|
+
return content_type.split("charset=")[-1].split(";")[0].strip()
|
|
273
|
+
return "utf-8"
|
|
274
|
+
|
|
275
|
+
@property
|
|
276
|
+
def content(self) -> bytes:
|
|
277
|
+
return self._content
|
|
278
|
+
|
|
279
|
+
@property
|
|
280
|
+
def text(self) -> str:
|
|
281
|
+
try:
|
|
282
|
+
return self._content.decode(self.encoding or "utf-8", errors="replace")
|
|
283
|
+
except (LookupError, TypeError):
|
|
284
|
+
return self._content.decode("utf-8", errors="replace")
|
|
285
|
+
|
|
286
|
+
@property
|
|
287
|
+
def ok(self) -> bool:
|
|
288
|
+
return self.status_code < 400
|
|
289
|
+
|
|
290
|
+
def json(self, **kwargs):
|
|
291
|
+
return json.loads(self.text, **kwargs)
|
|
292
|
+
|
|
293
|
+
def iter_content(self, chunk_size=1, decode_unicode=False):
|
|
294
|
+
content = self.text if decode_unicode else self._content
|
|
295
|
+
for i in range(0, len(content), chunk_size):
|
|
296
|
+
yield content[i : i + chunk_size]
|
|
297
|
+
|
|
298
|
+
def raise_for_status(self):
|
|
299
|
+
if 400 <= self.status_code:
|
|
300
|
+
raise requests.HTTPError(
|
|
301
|
+
f"{self.status_code} Error for url: {self.url}", response=self
|
|
302
|
+
)
|
|
303
|
+
|
|
304
|
+
def __repr__(self):
|
|
305
|
+
return f"<DothttpResponse [{self.status_code}]>"
|
|
306
|
+
|
|
307
|
+
|
|
154
308
|
@dataclass
|
|
155
309
|
class Client:
|
|
156
310
|
request: HttpDef
|
|
157
311
|
properties: Properties
|
|
158
312
|
env_properties: Properties
|
|
159
313
|
infile_properties: Properties
|
|
160
|
-
response: Response = None
|
|
314
|
+
response: typing.Union[Response, "DothttpResponse"] = None
|
|
161
315
|
|
|
162
316
|
|
|
163
317
|
class ScriptExecutionEnvironmentBase:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dotextensions/server/handlers/fs_handlers.py
RENAMED
|
File without changes
|
|
File without changes
|
{dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dotextensions/server/handlers/har2httphandler.py
RENAMED
|
File without changes
|
|
File without changes
|
{dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dotextensions/server/handlers/http2postman.py
RENAMED
|
File without changes
|
{dothttp_req-0.0.44a39 → dothttp_req-0.0.44a41}/dotextensions/server/handlers/postman2http.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|