Skip to content

Commit

Permalink
target is only known beforehand
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric05 committed Jan 1, 2025
1 parent f4073ca commit 182946f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
12 changes: 11 additions & 1 deletion dotextensions/server/handlers/basic_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
license = "MIT"
Expand Down
45 changes: 45 additions & 0 deletions test/extensions/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 182946f

Please sign in to comment.