From 182946f5b503b8000119d083b1f91b7d779224dd Mon Sep 17 00:00:00 2001 From: cedric05 Date: Wed, 1 Jan 2025 02:11:50 +0000 Subject: [PATCH] target is only known beforehand --- .../server/handlers/basic_handlers.py | 12 ++++- pyproject.toml | 2 +- test/extensions/test_commands.py | 45 +++++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/dotextensions/server/handlers/basic_handlers.py b/dotextensions/server/handlers/basic_handlers.py index b69b07e..8ade655 100644 --- a/dotextensions/server/handlers/basic_handlers.py +++ b/dotextensions/server/handlers/basic_handlers.py @@ -303,11 +303,21 @@ def run(self, command: Command) -> Result: class ResolveBase(): def get_resolved(self, command: Command) -> Result: + filename = command.params.get('filename') + content = command.params.get('content') pos = command.params.get('position') + if filename: + model: MultidefHttp = dothttp_model.model_from_file(filename) + else: + model: MultidefHttp = dothttp_model.model_from_str(content) + type_dict = TypeFromPos.figure_n_get(model, pos) + if "target" not in type_dict: + command.params["target"] = 1 + else: + command.params["target"] = type_dict["target"] config = self.get_config(command) comp: RequestCompiler = self.get_request_comp(config) comp.load_def() - type_dict = TypeFromPos.figure_n_get(comp.model, pos) type_type = type_dict['type'] if type_type == DothttpTypes.URL.value: type_dict["resolved"] = comp.httpdef.url diff --git a/pyproject.toml b/pyproject.toml index 8921839..ae1e637 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "dothttp-req" -version = "0.0.44a5" +version = "0.0.44a6" description = "Dothttp is Simple http client for testing and development" authors = ["Prasanth "] license = "MIT" diff --git a/test/extensions/test_commands.py b/test/extensions/test_commands.py index 2f07f61..0d0f4c3 100644 --- a/test/extensions/test_commands.py +++ b/test/extensions/test_commands.py @@ -216,6 +216,51 @@ def test_hover_context_content(self): self.assertEquals(expected, result.result["resolved"]) + + def test_hover_context_with_no_target(self): + resolve_handler = GetHoveredResolvedParamContentHandler() + contexts = ["""@name('test3') +GET "https://httpbin.org/get" +"""] + content = """ + var numOfHours = 3; + var numOfSeconds = (numOfHours * 60 * 60); + @name("my-test"): "test3" + POST "/ram" + json({ + "totalSeconds" : {{numOfSeconds}} + }) + + @name("my-test2"): "test3" + POST "/ranga" + json({ + "totalSeconds" : {{numOfSeconds}}, + "rama": "ranga", + }) + """ + index = content.find("ranga") + result = resolve_handler.run( + Command( + method=resolve_handler.name, + params={"content": content, "position": index, "contexts": contexts}, + id=1, + ) + ) + expected = "https://httpbin.org/get/ranga" + self.assertEquals(expected, result.result["resolved"]) + + index = content.find("rama") + result = resolve_handler.run( + Command( + method=resolve_handler.name, + params={"content": content, "position": index, "contexts": contexts}, + id=1, + ) + ) + expected = {"totalSeconds": 10800, "rama": "ranga"} + self.assertEquals(expected, result.result["resolved"]) + + class FileExecute(TestBase): def setUp(self) -> None: self.execute_handler = RunHttpFileHandler()