Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support to head and options methods #350

Merged
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added flake8 check workflow on pull_request event [#321](https://github.com/scanapi/scanapi/pull/321)
- Hide sensitive information in the URL Query Params [#304](https://github.com/scanapi/scanapi/pull/325)
- Add anchor link for each request in the report to make it easily shareable. [#317](https://github.com/scanapi/scanapi/pull/317)
- Update black version on pre-commit configurations to avoid conflicts with flake8 [#346](https://github.com/scanapi/scanapi/pull/346)
- Added support to HTTP methods HEAD and OPTIONS [#350](https://github.com/scanapi/scanapi/pull/350)

### Changed
- Updated poetry-publish version to v1.3 [#311](https://github.com/scanapi/scanapi/pull/311)
Expand Down
2 changes: 1 addition & 1 deletion scanapi/hide_utils.py
Expand Up @@ -23,7 +23,7 @@ def hide_sensitive_info(response):


def _hide(http_msg, hide_settings):
""" Private method that finds all sensitive information attributes and calls _override_info
"""Private method that finds all sensitive information attributes and calls _override_info
to have sensitive data replaced
"""
for http_attr in hide_settings:
Expand Down
5 changes: 2 additions & 3 deletions scanapi/reporter.py
Expand Up @@ -17,8 +17,7 @@ def __init__(self, output_path=None, template=None):
self.template = template

def write(self, results):
""" Part of the Reporter instance that is responsible for writing scanapi-report.html.
"""
"""Part of the Reporter instance that is responsible for writing scanapi-report.html."""
logger.info("Writing documentation")

template_path = self.template if self.template else "report.html"
Expand All @@ -35,7 +34,7 @@ def write(self, results):

@staticmethod
def _build_context(results):
""" Private method of Reporter returns dict containing keys datetime,
"""Private method of Reporter returns dict containing keys datetime,
project_name, results and session and their corresponding values.
"""
return {
Expand Down
2 changes: 1 addition & 1 deletion scanapi/scan.py
Expand Up @@ -58,7 +58,7 @@ def scan():


def write_report(results):
""" Constructs a Reporter object and calls the write method of Reporter to push
"""Constructs a Reporter object and calls the write method of Reporter to push
the results to a file.
"""
reporter = Reporter(settings["output_path"], settings["template"])
Expand Down
10 changes: 9 additions & 1 deletion scanapi/tree/request_node.py
Expand Up @@ -37,7 +37,15 @@ class RequestNode:
DELAY_KEY,
RETRY_KEY,
)
ALLOWED_HTTP_METHODS = ("GET", "POST", "PUT", "PATCH", "DELETE")
ALLOWED_HTTP_METHODS = (
"GET",
"POST",
"PUT",
"PATCH",
"DELETE",
"HEAD",
"OPTIONS",
)
REQUIRED_KEYS = (NAME_KEY,)

def __init__(self, spec, endpoint):
Expand Down
4 changes: 2 additions & 2 deletions scanapi/utils.py
Expand Up @@ -7,7 +7,7 @@


def join_urls(first_url, second_url):
""" Function that returns one url if two aren't given else joins the two urls and
"""Function that returns one url if two aren't given else joins the two urls and
returns them.
"""
if not first_url:
Expand Down Expand Up @@ -43,7 +43,7 @@ def _validate_required_keys(keys, required_keys, scope):


def session_with_retry(retry_configuration):
""" Instantiate a requests session with the retry configuration if provided by
"""Instantiate a requests session with the retry configuration if provided by
instantiating an HTTPAdapter mounting it into the mounting it into the
`requests.Session`.
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/evaluators/test_spec_evaluator.py
Expand Up @@ -53,7 +53,7 @@ def test_return_evaluated_dict(
):
mock_string_evaluate.side_effect = ["foo", "bar"]
assert spec_evaluator.evaluate(
{"app_id": "foo", "token": "bar",}
{"app_id": "foo", "token": "bar"}
) == {"app_id": "foo", "token": "bar",}

mock_string_evaluate.assert_has_calls(
Expand Down
9 changes: 5 additions & 4 deletions tests/unit/tree/test_request_node.py
Expand Up @@ -50,16 +50,17 @@ def test_when_request_has_no_method(self):

def test_when_method_is_invalid(self):
request = RequestNode(
{"method": "xxx", "name": "foo", "path": "http:foo.com"},
{"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')."
expected = (
f"HTTP method not supported: {request.spec.get('method')}."
f" Supported methods: {request.ALLOWED_HTTP_METHODS}."
)
assert str(excinfo.value) == expected

class TestName:
def test_when_request_has_name(self):
Expand Down