dothttp-req 0.0.44a38__tar.gz → 0.0.44a40__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.
Files changed (53) hide show
  1. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/PKG-INFO +5 -5
  2. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dotextensions/server/handlers/basic_handlers.py +70 -0
  3. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dotextensions/server/server.py +4 -0
  4. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dothttp/script/js3py.py +104 -1
  5. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/pyproject.toml +5 -5
  6. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/LICENSE.txt +0 -0
  7. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/README.md +0 -0
  8. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dotextensions/__init__.py +0 -0
  9. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dotextensions/server/__init__.py +0 -0
  10. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dotextensions/server/__main__.py +0 -0
  11. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dotextensions/server/agent.py +0 -0
  12. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dotextensions/server/handlers/__init__.py +0 -0
  13. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dotextensions/server/handlers/fs_handlers.py +0 -0
  14. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dotextensions/server/handlers/gohandler.py +0 -0
  15. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dotextensions/server/handlers/har2httphandler.py +0 -0
  16. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dotextensions/server/handlers/http2har.py +0 -0
  17. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dotextensions/server/handlers/http2postman.py +0 -0
  18. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dotextensions/server/handlers/postman2http.py +0 -0
  19. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dotextensions/server/models/__init__.py +0 -0
  20. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dotextensions/server/models/har.py +0 -0
  21. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dotextensions/server/postman/__init__.py +0 -0
  22. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dotextensions/server/postman2_1/__init__.py +0 -0
  23. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dotextensions/server/utils.py +0 -0
  24. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dotextensions/version/__init__.py +0 -0
  25. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dotextensions/version/__main__.py +0 -0
  26. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dothttp/__init__.py +0 -0
  27. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dothttp/__main__.py +0 -0
  28. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dothttp/__version__.py +0 -0
  29. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dothttp/auth/__init__.py +0 -0
  30. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dothttp/auth/azure_auth.py +0 -0
  31. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dothttp/exceptions.py +0 -0
  32. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dothttp/http.tx +0 -0
  33. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dothttp/models/__init__.py +0 -0
  34. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dothttp/models/computed.py +0 -0
  35. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dothttp/models/parse_models.py +0 -0
  36. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dothttp/parse/__init__.py +0 -0
  37. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dothttp/parse/dsl_jsonparser.py +0 -0
  38. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dothttp/parse/expression.py +0 -0
  39. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dothttp/parse/request_base.py +0 -0
  40. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dothttp/postScript.js +0 -0
  41. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dothttp/property_schema.py +0 -0
  42. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dothttp/script/__init__.py +0 -0
  43. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dothttp/utils/__init__.py +0 -0
  44. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dothttp/utils/common.py +0 -0
  45. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dothttp/utils/constants.py +0 -0
  46. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dothttp/utils/curl_utils.py +0 -0
  47. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dothttp/utils/json_utils.py +0 -0
  48. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dothttp/utils/log_utils.py +0 -0
  49. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dothttp/utils/property_util.py +0 -0
  50. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dothttp_test/__init__.py +0 -0
  51. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dothttp_test/__main__.py +0 -0
  52. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dothttp_test/conftest.py +0 -0
  53. {dothttp_req-0.0.44a38 → dothttp_req-0.0.44a40}/dothttp_test/dothttp_test.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dothttp-req
3
- Version: 0.0.44a38
3
+ Version: 0.0.44a40
4
4
  Summary: Dothttp is Simple http client for testing and development
5
5
  License: MIT
6
6
  License-File: LICENSE.txt
@@ -14,8 +14,8 @@ Classifier: Programming Language :: Python :: 3.12
14
14
  Classifier: Programming Language :: Python :: 3.13
15
15
  Classifier: Programming Language :: Python :: 3.14
16
16
  Requires-Dist: cryptography (==50.0.1)
17
- Requires-Dist: faker (==40.21.0)
18
- Requires-Dist: idna (==3.18)
17
+ Requires-Dist: faker (==40.39.0)
18
+ Requires-Dist: idna (==3.20)
19
19
  Requires-Dist: jsonschema (==4.26.0)
20
20
  Requires-Dist: jstyleson (==0.0.2)
21
21
  Requires-Dist: msal (==1.39.0)
@@ -27,10 +27,10 @@ Requires-Dist: requests-hawk (==1.2.1)
27
27
  Requires-Dist: requests-ntlm (==1.3.0)
28
28
  Requires-Dist: requests-pkcs12 (==1.27)
29
29
  Requires-Dist: restrictedpython (==8.5)
30
- Requires-Dist: textx (==4.2.3)
30
+ Requires-Dist: textx (==4.4.0)
31
31
  Requires-Dist: toml (==0.10.2)
32
32
  Requires-Dist: truststore (==0.10.4)
33
- Requires-Dist: urllib3 (==2.7.0)
33
+ Requires-Dist: urllib3 (==2.8.0)
34
34
  Requires-Dist: xmltodict (>=1.0.2,<2.0.0)
35
35
  Project-URL: Bug Tracker, https://github.com/cedric05/dothttp
36
36
  Description-Content-Type: text/markdown
@@ -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(),
@@ -22,6 +22,7 @@ import yaml
22
22
  from cryptography import *
23
23
  from faker import Faker
24
24
  from requests import Response
25
+ from requests.structures import CaseInsensitiveDict
25
26
  from RestrictedPython import compile_restricted, safe_globals
26
27
  from RestrictedPython.Eval import default_guarded_getiter
27
28
  from RestrictedPython.Guards import guarded_iter_unpack_sequence
@@ -151,13 +152,115 @@ class Properties(dict):
151
152
  self.clear(key, "")
152
153
 
153
154
 
155
+ @dataclass
156
+ class _RequestInfo:
157
+ method: typing.Union[None, str] = None
158
+ url: typing.Union[None, str] = None
159
+ headers: CaseInsensitiveDict = field(default_factory=CaseInsensitiveDict)
160
+
161
+
162
+ class DothttpResponse:
163
+ """
164
+ A ``requests.Response``-like adapter built from dothttp's serialized
165
+ response format::
166
+
167
+ {
168
+ "body": <str | bytes>, # or "body_base64": <str>
169
+ "output_file": <str>,
170
+ "headers": {<name>: <value>},
171
+ "status": <int>,
172
+ "method": <str>,
173
+ "url": <str>,
174
+ "request_headers": {<name>: <value>}, # optional
175
+ "history": [<response dict>, ...], # optional, redirect hops
176
+ }
177
+
178
+ It exposes the subset of the ``requests.Response`` surface that test
179
+ scripts rely on (``status_code``, ``headers``, ``text``, ``content``,
180
+ ``json()``, ``url``, ``ok``, ``request.method``, ``history`` ...), so
181
+ tests can run against a previously captured response without re-issuing
182
+ the request. ``history`` entries (redirect hops) are themselves
183
+ ``DothttpResponse`` instances, mirroring ``requests``.
184
+ """
185
+
186
+ def __init__(self, data: dict):
187
+ body = data.get("body", "")
188
+ if isinstance(body, (bytes, bytearray)):
189
+ self._content = bytes(body)
190
+ elif data.get("body_base64"):
191
+ self._content = base64.b64decode(data["body_base64"])
192
+ else:
193
+ self._content = (body or "").encode("utf-8")
194
+ self.status_code = data.get("status", 0)
195
+ self.headers = CaseInsensitiveDict(data.get("headers") or {})
196
+ self.url = data.get("url", "")
197
+ self.reason = data.get("reason", "")
198
+ self.output_file = data.get("output_file", "")
199
+ self.encoding = data.get("encoding") or self._guess_encoding()
200
+ self.cookies = data.get("cookies", {})
201
+ self.elapsed = datetime.timedelta(0)
202
+ # redirect hops, each captured in the same serialized shape
203
+ self.history = [
204
+ DothttpResponse(hop) for hop in (data.get("history") or [])
205
+ ]
206
+ # the request that produced this response; a nested "request" dict
207
+ # takes precedence, else fall back to the top-level method/url and
208
+ # the "request_headers" emitted by the execute handlers
209
+ request = data.get("request") or {}
210
+ self.request = _RequestInfo(
211
+ method=request.get("method", data.get("method")),
212
+ url=request.get("url", data.get("url")),
213
+ headers=CaseInsensitiveDict(
214
+ request.get("headers") or data.get("request_headers") or {}
215
+ ),
216
+ )
217
+
218
+ def _guess_encoding(self):
219
+ content_type = (self.headers.get("content-type") or "").lower()
220
+ if "charset=" in content_type:
221
+ return content_type.split("charset=")[-1].split(";")[0].strip()
222
+ return "utf-8"
223
+
224
+ @property
225
+ def content(self) -> bytes:
226
+ return self._content
227
+
228
+ @property
229
+ def text(self) -> str:
230
+ try:
231
+ return self._content.decode(self.encoding or "utf-8", errors="replace")
232
+ except (LookupError, TypeError):
233
+ return self._content.decode("utf-8", errors="replace")
234
+
235
+ @property
236
+ def ok(self) -> bool:
237
+ return self.status_code < 400
238
+
239
+ def json(self, **kwargs):
240
+ return json.loads(self.text, **kwargs)
241
+
242
+ def iter_content(self, chunk_size=1, decode_unicode=False):
243
+ content = self.text if decode_unicode else self._content
244
+ for i in range(0, len(content), chunk_size):
245
+ yield content[i : i + chunk_size]
246
+
247
+ def raise_for_status(self):
248
+ if 400 <= self.status_code:
249
+ raise requests.HTTPError(
250
+ f"{self.status_code} Error for url: {self.url}", response=self
251
+ )
252
+
253
+ def __repr__(self):
254
+ return f"<DothttpResponse [{self.status_code}]>"
255
+
256
+
154
257
  @dataclass
155
258
  class Client:
156
259
  request: HttpDef
157
260
  properties: Properties
158
261
  env_properties: Properties
159
262
  infile_properties: Properties
160
- response: Response = None
263
+ response: typing.Union[Response, "DothttpResponse"] = None
161
264
 
162
265
 
163
266
  class ScriptExecutionEnvironmentBase:
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "dothttp-req"
3
- version = "0.0.44a38"
3
+ version = "0.0.44a40"
4
4
  description = "Dothttp is Simple http client for testing and development"
5
5
  authors = ["Prasanth <kesavarapu.siva@gmail.com>"]
6
6
  license = "MIT"
@@ -24,13 +24,13 @@ dothttp = 'dothttp.__main__:main'
24
24
  python = ">=3.12,<3.15"
25
25
  jsonschema = "4.26.0"
26
26
  jstyleson = "0.0.2"
27
- textx = "4.2.3"
27
+ textx = "4.4.0"
28
28
  requests-pkcs12 = "1.27"
29
29
  parsys-requests-unixsocket = "0.3.2"
30
30
  requests-aws4auth = "1.3.2"
31
31
  requests-ntlm = "1.3.0"
32
32
  restrictedpython = "8.5"
33
- faker = "40.21.0"
33
+ faker = "40.39.0"
34
34
  requests-hawk = "1.2.1"
35
35
  msal = "1.39.0"
36
36
  pyyaml = "6.0.3"
@@ -38,8 +38,8 @@ toml = "0.10.2"
38
38
  requests = "2.34.2"
39
39
  cryptography = "50.0.1"
40
40
  truststore = "0.10.4"
41
- urllib3 = "2.7.0"
42
- idna = "3.18"
41
+ urllib3 = "2.8.0"
42
+ idna = "3.20"
43
43
  xmltodict = "^1.0.2"
44
44
 
45
45
  [tool.poetry.group.dev.dependencies]