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

Add methodignore plugin #12

Merged
merged 7 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions har2locust/default_plugins/2_methodignore.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pathlib

from har2locust.plugin import entriesprocessor


@entriesprocessor
def methodignore(entries: list[dict]):
methodignore_path = pathlib.Path(".methodignore")
filters = []
if methodignore_path.is_file():
with open(methodignore_path) as f:
filters = f.readlines()
filters = [line.rstrip() for line in filters if line.strip() and not line.strip().startswith("#")]
else:
filters = ["OPTIONS"] # nobody likes you, OPTIONS
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hahah true


entries[:] = [e for e in entries if e["request"]["method"] not in filters]
6 changes: 6 additions & 0 deletions har2locust/default_plugins/default_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ def default_headers(entries: list[dict], _args):
for h in headers:
if dh["name"] == h["name"]:
if dh["value"] != h["value"]:
logging.debug(
f"removed default header {dh['name']} with value {dh['value']} from default headers because it has different value in {e['request']['url']}"
)
default_headers.remove(dh) # header has different value
break
break
else:
logging.debug(
f"removed default header {dh['name']} with value {dh['value']} from default headers because it was not present in {e['request']['url']}"
)
default_headers.remove(dh) # header not present
if default_headers is None:
default_headers = []
Expand Down
2 changes: 0 additions & 2 deletions har2locust/default_plugins/rest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import logging

from har2locust.plugin import entriesprocessor


Expand Down
6 changes: 0 additions & 6 deletions har2locust/extra_plugins/plugin_example.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# This file has some advanced examples of how to massage your recording
# Use it as inspiration for the techniques, not as a recommendation for exactly what to do
import ast
import pathlib
import re
import typing

Expand Down Expand Up @@ -76,11 +75,6 @@ def visit_Call(self, node: ast.Call) -> ast.Call:
self.generic_visit(node)
return node

T().visit(tree)

self.generic_visit(node)
return node

T().visit(tree)


Expand Down
5 changes: 2 additions & 3 deletions tests/test_har2locust.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

import pytest

from har2locust.__main__ import __main__, load_plugins, process, render
from har2locust.argument_parser import get_parser
from har2locust.__main__ import __main__

inputs_dir = pathlib.Path(__file__).parents[0] / "inputs"
outputs_dir = pathlib.Path(__file__).parents[0] / "outputs"
Expand Down Expand Up @@ -45,7 +44,7 @@ def test_invalid_resource_types():
"inputs/login.har",
)
_stdout, stderr = proc.communicate()
assert proc.returncode == 0, f"Unexpected return code {proc.returncode}, stderr: {stderr}"
assert proc.returncode == 1, f"Unexpected return code {proc.returncode}, stderr: {stderr}"
assert "unsupported resource type" in stderr


Expand Down
Loading