From 56ef2fa2e1e4f8cdfeb2fa4bcda21753c401a891 Mon Sep 17 00:00:00 2001 From: cedric05 Date: Sun, 29 Dec 2024 04:12:12 +0000 Subject: [PATCH] add coulple of tests --- dothttp/parse/__init__.py | 2 ++ test/core/var/.dothttp.json | 5 +++ test/core/var/override.http | 8 +++++ test/core/var/test_var.py | 72 ++++++++++++++++++++++++++++++------- 4 files changed, 74 insertions(+), 13 deletions(-) create mode 100644 test/core/var/.dothttp.json create mode 100644 test/core/var/override.http diff --git a/dothttp/parse/__init__.py b/dothttp/parse/__init__.py index 0587a57..7dbb65a 100644 --- a/dothttp/parse/__init__.py +++ b/dothttp/parse/__init__.py @@ -358,6 +358,8 @@ def _load_props_from_content(self, content, property_util: PropertyProvider): @staticmethod def load_properties_from_var(model, property_util): + ## this has to taken care by property util + ## but it will complicate the code for variable in model.variables: if variable.value: var_value = jsonmodel_to_json(variable.value) diff --git a/test/core/var/.dothttp.json b/test/core/var/.dothttp.json new file mode 100644 index 0000000..05aa211 --- /dev/null +++ b/test/core/var/.dothttp.json @@ -0,0 +1,5 @@ +{ + "test": { + "a": "b" + } +} \ No newline at end of file diff --git a/test/core/var/override.http b/test/core/var/override.http new file mode 100644 index 0000000..3c29d73 --- /dev/null +++ b/test/core/var/override.http @@ -0,0 +1,8 @@ +import "./par.http"; +var a = 10; + + +POST "https://httpbin.org/post" +json({ + "a": {{a}} +}) \ No newline at end of file diff --git a/test/core/var/test_var.py b/test/core/var/test_var.py index e1ac34b..c835547 100644 --- a/test/core/var/test_var.py +++ b/test/core/var/test_var.py @@ -12,7 +12,8 @@ class VarSubstitutionTest(TestBase): def test_substitution(self): req = self.get_request(f"{base_dir}/host.http") - self.assertEqual("https://httpbin.org/?a=10&b=20", req.url, "incorrect url") + self.assertEqual("https://httpbin.org/?a=10&b=20", + req.url, "incorrect url") def test_math(self): req = self.get_request(f"{base_dir}/math.http") @@ -22,21 +23,20 @@ def test_math(self): "incorrect body", ) - def test_json(self): req = self.get_request(f"{base_dir}/json.http") self.assertEqual( { 'jsonData': { - 'secInDay': 86400, + 'secInDay': 86400, 'secInHour': 3600, "true": True, "false": False, - "nested" : [ + "nested": [ 1, 2, 4.4, "string", True, False, None, { "key": "value" } - ], + ], "nestedObject": { "key": { "key": "value" @@ -46,29 +46,29 @@ def test_json(self): "okay": "okay", "nested": { 'jsonData': { - 'secInDay': 86400, + 'secInDay': 86400, 'secInHour': 3600, "true": True, "false": False, - "nested" : [ + "nested": [ 1, 2, 4.4, "string", True, False, None, { "key": "value" } - ], + ], "nestedObject": { "key": { "key": "value" } } - }, + }, "okay": "okay" } }, json.loads(req.body), "incorrect body", ) - + def test_import_sub(self): req = self.get_request(f"{base_dir}/child.http") self.assertEqual( @@ -78,7 +78,7 @@ def test_import_sub(self): "c": "c", "d": True, "d2": "True", - "jsonData":{ + "jsonData": { "secInDay": 86400, } }, @@ -86,7 +86,6 @@ def test_import_sub(self): "incorrect body", ) - def test_import_nested(self): req = self.get_request(f"{base_dir}/grand_child.http") self.assertEqual( @@ -96,7 +95,44 @@ def test_import_nested(self): "c": "c", "d": True, "d2": "True", - "jsonData":{ + "jsonData": { + "secInDay": 86400, + }, + "secInDay": '86400', + }, + json.loads(req.body), + "incorrect body", + ) + + def test_sub_external_command_properties(self): + req = self.get_request( + f"{base_dir}/grand_child.http", properties={"secInDay=0"}) + self.assertEqual( + { + "a": "a", + "b": "b", + "c": "c", + "d": True, + "d2": "True", + "jsonData": { + "secInDay": 86400, + }, + "secInDay": '0', + }, + json.loads(req.body), + "incorrect body", + ) + + def test_sub_external_env_properties(self): + req = self.get_request(f"{base_dir}/grand_child.http", env=["test"]) + self.assertEqual( + { + "a": "b", + "b": "b", + "c": "c", + "d": True, + "d2": "True", + "jsonData": { "secInDay": 86400, }, "secInDay": '86400', @@ -104,3 +140,13 @@ def test_import_nested(self): json.loads(req.body), "incorrect body", ) + + def test_override(self): + req = self.get_request(f"{base_dir}/override.http", ) + self.assertEqual( + { + "a": 10, + }, + json.loads(req.body), + "incorrect body", + )