From 18e19a282fd5e45ad6adff4a99e4a70a095da08b Mon Sep 17 00:00:00 2001 From: Lars Holmberg Date: Mon, 11 Mar 2024 14:57:55 +0100 Subject: [PATCH 1/7] Add methodignore plugin (ignores OPTIONS by default, for more fine-grained control you can specify a .methodignore file --- har2locust/default_plugins/2_methodignore.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 har2locust/default_plugins/2_methodignore.py diff --git a/har2locust/default_plugins/2_methodignore.py b/har2locust/default_plugins/2_methodignore.py new file mode 100644 index 0000000..4de8c19 --- /dev/null +++ b/har2locust/default_plugins/2_methodignore.py @@ -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 + + entries[:] = [e for e in entries if e["request"]["method"] not in filters] From ddee464a95de15bd344fee0e596197643c84d720 Mon Sep 17 00:00:00 2001 From: Lars Holmberg Date: Mon, 11 Mar 2024 14:59:32 +0100 Subject: [PATCH 2/7] ruff --- har2locust/default_plugins/rest.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/har2locust/default_plugins/rest.py b/har2locust/default_plugins/rest.py index 601dca4..ea767a3 100644 --- a/har2locust/default_plugins/rest.py +++ b/har2locust/default_plugins/rest.py @@ -1,5 +1,3 @@ -import logging - from har2locust.plugin import entriesprocessor From e93f0f31d0c7daf26df754e06ceced17678ee82e Mon Sep 17 00:00:00 2001 From: Lars Holmberg Date: Mon, 11 Mar 2024 15:01:52 +0100 Subject: [PATCH 3/7] fix test case, sort imports (unrelated to other stuff in this branch) --- tests/test_har2locust.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/test_har2locust.py b/tests/test_har2locust.py index 4568af8..8e3b78a 100644 --- a/tests/test_har2locust.py +++ b/tests/test_har2locust.py @@ -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" @@ -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 From 3f7ab76891b520abc7d2de28154f4a2b3109e9db Mon Sep 17 00:00:00 2001 From: Lars Holmberg Date: Mon, 11 Mar 2024 15:05:06 +0100 Subject: [PATCH 4/7] fix bad commit --- har2locust/extra_plugins/plugin_example.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/har2locust/extra_plugins/plugin_example.py b/har2locust/extra_plugins/plugin_example.py index 4488209..5a1423d 100644 --- a/har2locust/extra_plugins/plugin_example.py +++ b/har2locust/extra_plugins/plugin_example.py @@ -76,11 +76,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) From 6fe819d606756194c61fdb71db33076b7c9d8a11 Mon Sep 17 00:00:00 2001 From: Lars Holmberg Date: Mon, 11 Mar 2024 15:06:27 +0100 Subject: [PATCH 5/7] debug log when values are removed from default headers (fix another partial commit) --- har2locust/default_plugins/default_headers.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/har2locust/default_plugins/default_headers.py b/har2locust/default_plugins/default_headers.py index 0031458..6622bb5 100644 --- a/har2locust/default_plugins/default_headers.py +++ b/har2locust/default_plugins/default_headers.py @@ -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 = [] From a5ae2a39108e6221ec4930c8e47a4f2277f6e741 Mon Sep 17 00:00:00 2001 From: Lars Holmberg Date: Mon, 11 Mar 2024 15:17:34 +0100 Subject: [PATCH 6/7] skip improting pathlib for now... --- har2locust/extra_plugins/plugin_example.py | 1 - 1 file changed, 1 deletion(-) diff --git a/har2locust/extra_plugins/plugin_example.py b/har2locust/extra_plugins/plugin_example.py index 5a1423d..74eb6bc 100644 --- a/har2locust/extra_plugins/plugin_example.py +++ b/har2locust/extra_plugins/plugin_example.py @@ -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 From 24778875ce91c38ebe367a1296a4e348f48603fe Mon Sep 17 00:00:00 2001 From: Lars Holmberg Date: Mon, 11 Mar 2024 15:25:38 +0100 Subject: [PATCH 7/7] fix test --- tests/test_har2locust.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_har2locust.py b/tests/test_har2locust.py index 8e3b78a..9ec512e 100644 --- a/tests/test_har2locust.py +++ b/tests/test_har2locust.py @@ -44,7 +44,8 @@ def test_invalid_resource_types(): "inputs/login.har", ) _stdout, stderr = proc.communicate() - assert proc.returncode == 1, f"Unexpected return code {proc.returncode}, stderr: {stderr}" + # it is just supposed to be a warning, so return code should still be ok + assert proc.returncode == 0, f"Unexpected return code {proc.returncode}, stderr: {stderr}" assert "unsupported resource type" in stderr