From e94b029b2cee72a9bf7e8f0a6cc4c0e6ff5e160d Mon Sep 17 00:00:00 2001 From: cedric05 Date: Sun, 29 Dec 2024 18:45:21 +0000 Subject: [PATCH] fix tests --- dothttp/parse/request_base.py | 12 +++++++++--- test/core/var/test_var.py | 8 ++++---- test/extensions/test_commands.py | 29 ++++++++++++++++++++++------- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/dothttp/parse/request_base.py b/dothttp/parse/request_base.py index f057b87..3f4ec66 100644 --- a/dothttp/parse/request_base.py +++ b/dothttp/parse/request_base.py @@ -277,11 +277,17 @@ def format_http(http: Http, property_util: Optional[PropertyProvider]=None): for key, value in total_props.items(): if isinstance(value, Property): if value.value: - output_str += f" var {key} = {value.value} ;" + if isinstance(value.value, str): + output_str += f"var {key} = '{value.value}' ;" + else: + output_str += f"var {key} = {value.value} ;" else: - output_str += f" var {key} ;" + output_str += f"var {key} ;" else: - output_str += f" var {key} = {value}{new_line} ;" + if isinstance(value, str): + output_str += f"var {key} = '{value}' ;" + else: + output_str += f"var {key} = {value} ;" output_str += new_line if getattr(http, "description", None): for line in http.description.splitlines(): diff --git a/test/core/var/test_var.py b/test/core/var/test_var.py index 577912c..537d0ab 100644 --- a/test/core/var/test_var.py +++ b/test/core/var/test_var.py @@ -75,7 +75,7 @@ def test_import_sub(self): "b": "b", "c": "c", "d": True, - "d2": "True", + "d2": "true", "jsonData": { "secInDay": 86400, } @@ -92,7 +92,7 @@ def test_import_nested(self): "b": "b", "c": "c", "d": True, - "d2": "True", + "d2": "true", "jsonData": { "secInDay": 86400, }, @@ -111,7 +111,7 @@ def test_sub_external_command_properties(self): "b": "b", "c": "c", "d": True, - "d2": "True", + "d2": "true", "jsonData": { "secInDay": 86400, }, @@ -129,7 +129,7 @@ def test_sub_external_env_properties(self): "b": "b", "c": "c", "d": True, - "d2": "True", + "d2": "true", "jsonData": { "secInDay": 86400, }, diff --git a/test/extensions/test_commands.py b/test/extensions/test_commands.py index df47008..49b379f 100644 --- a/test/extensions/test_commands.py +++ b/test/extensions/test_commands.py @@ -137,7 +137,8 @@ def test_complex_file(self): self.assertTrue("headers" in result.result) self.assertEqual("http://localhost:8000/post?startusing=dothttp", body["url"]) self.assertEqual( - """@name("2") + """var host = 'localhost:8000' ; +@name("2") POST "http://localhost:8000/post" ? "startusing"= "dothttp" @@ -163,7 +164,8 @@ def test_complex_file(self): self.assertTrue("headers" in result2.result) self.assertEqual("http://localhost:8000/post?startusing=dothttp", body["url"]) self.assertEqual( - """@name("2") + """var host = 'req.dothttp.dev' ; +@name("2") POST "http://req.dothttp.dev/post" ? "startusing"= "dothttp" @@ -185,7 +187,8 @@ def test_complex_file(self): ) ) self.assertEqual( - """@name("3") + """var host = 'localhost:8000' ; +@name("3") POST "http://localhost:8000/POST" ? "startusing"= "dothttp" @@ -209,7 +212,8 @@ def test_complex_file(self): ) self.assertEqual(200, result4.result["status"]) self.assertEqual( - """@name("4") + """var host = 'localhost:8000' ; +@name("4") GET "http://localhost:8000/get" basicauth("username", "password") @@ -288,7 +292,11 @@ def test_cert_with_no_key(self): ) self.assertEqual(200, req_comp_success.result["status"]) self.assertEqual( - f"""@name("no-password") + f"""var cert = '/workspaces/dothttp/test/core/root_cert/certs/no-password.pem' ; +var key ; +var p12 ; +var file = '' ; +@name("no-password") GET "https://client.badssl.com/" certificate(cert="{cert_file}") @@ -313,7 +321,10 @@ def test_cert_key(self): ) self.assertEqual(200, req_comp2.result["status"]) self.assertEqual( - f"""@name("with-key-and-cert") + f"""var cert = '/workspaces/dothttp/test/core/root_cert/certs/cert.crt' ; +var key = '/workspaces/dothttp/test/core/root_cert/certs/key.key' ; +var p12 ; +@name("with-key-and-cert") @clear @insecure GET "https://client.badssl.com/" @@ -339,7 +350,11 @@ def test_p12(self): ) self.assertEqual(200, result.result["status"]) self.assertEqual( - f"""@name("with-p12") + f"""var cert ; +var key ; +var p12 = '/workspaces/dothttp/test/core/root_cert/certs/badssl.com-client.p12' ; +var password = 'badssl.com' ; +@name("with-p12") @clear GET "https://client.badssl.com/" p12(file="{p12}", password="badssl.com")