Files
auto-reverse/tests/test_models.py
T

37 lines
1.2 KiB
Python
Raw Normal View History

from auto_reverse.models import CapturedFlow, Signature, status_class
def test_status_class_buckets():
assert status_class(200) == "2xx"
assert status_class(201) == "2xx"
assert status_class(404) == "4xx"
assert status_class(503) == "5xx"
def test_signature_is_hashable_and_equal():
a = Signature("GET", "ex.com", "/api/users/{id}", "2xx")
b = Signature("GET", "ex.com", "/api/users/{id}", "2xx")
assert a == b
assert {a, b} == {a}
def test_captured_flow_json_body_parsing():
flow = CapturedFlow(
method="POST", host="ex.com", path="/api/x", query={},
req_headers={"content-type": "application/json"}, req_body=b'{"a": 1}',
status=201, resp_headers={"content-type": "application/json"},
resp_body=b'{"ok": true}', timestamp=0.0,
)
assert flow.request_json() == {"a": 1}
assert flow.response_json() == {"ok": True}
def test_captured_flow_non_json_body_returns_none():
flow = CapturedFlow(
method="GET", host="ex.com", path="/x", query={},
req_headers={}, req_body=None, status=200,
resp_headers={"content-type": "text/html"}, resp_body=b"<html>",
timestamp=0.0,
)
assert flow.response_json() is None