Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_calls_evaluate(self, mocker, mock_evaluate):
request = RequestNode(
{"body": {"ghi": "jkl"}, "path": "http://foo.com", "name": "foo"},
endpoint=EndpointNode({"name": "foo", "requests": [{}]}),
)
request.body
calls = [mocker.call({"ghi": "jkl"})]
mock_evaluate.assert_has_calls(calls)
def test_when_parent_has_no_headers(self):
headers = {"abc": "def"}
node = EndpointNode(
{"headers": headers, "name": "node", "requests": []},
parent=EndpointNode({"name": "parent-node", "requests": []}),
)
assert node.headers == headers
def test_when_method_is_invalid(self):
request = RequestNode(
{"method": "xxx", "name": "foo", "path": "http:foo.com"},
endpoint=EndpointNode({"name": "foo", "requests": [{}]}),
)
with pytest.raises(HTTPMethodNotAllowedError) as excinfo:
request.http_method
assert (
str(excinfo.value) == "HTTP method not supported: XXX. "
"Supported methods: ('GET', 'POST', 'PUT', 'PATCH', 'DELETE')."
def test_when_endpoint_has_no_params(self):
params = {"abc": "def"}
request = RequestNode(
{"params": params, "path": "http://foo.com", "name": "foo"},
endpoint=EndpointNode({"name": "foo", "requests": [{}]}),
)
assert request.params == params
def test_when_parent_has_no_url(self):
base_path = "http://foo.com"
node = EndpointNode(
{"path": base_path, "name": "child-node", "requests": []},
parent=EndpointNode({"name": "parent-node", "requests": []}),
)
assert node.path == base_path
def test_when_request_has_no_method(self):
request = RequestNode(
{"name": "foo", "path": "http:foo.com"},
endpoint=EndpointNode({"name": "foo", "requests": [{}]}),
)
assert request.http_method == "GET"
def test_with_trailing_slashes(self):
endpoint = EndpointNode(
{"name": "foo", "requests": [{}], "path": "http://foo.com/"}
)
request = RequestNode({"name": "foo", "path": "/foo/"}, endpoint=endpoint)
assert request.full_url_path == "http://foo.com/foo/"
def test_when_request_has_name(self):
request = RequestNode(
{"name": "list-users", "path": "http:foo.com"},
endpoint=EndpointNode({"name": "foo", "requests": []}),
)
assert request.name == "list-users"
def test_when_parent_has_url(self):
base_path = "http://foo.com/api"
parent = EndpointNode(
{"path": base_path, "name": "parent-node", "requests": []}
)
node = EndpointNode(
{"path": "/foo", "name": "node", "requests": []}, parent=parent
)
assert node.path == f"http://foo.com/api/foo"
def test_calls_request(self, mock_request):
request = RequestNode(
{"path": "http://foo.com", "name": "foo"},
endpoint=EndpointNode({"name": "foo", "requests": [{}]}),
)
result = request.run()
mock_request.assert_called_once_with(
request.http_method,
request.full_url_path,
headers=request.headers,
params=request.params,
json=request.body,
allow_redirects=False,
)
assert result == {
"response": mock_request(),
"tests_results": [],
"no_failure": True,