Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric05 committed Dec 29, 2024
1 parent 2b5d792 commit e94b029
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
12 changes: 9 additions & 3 deletions dothttp/parse/request_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
8 changes: 4 additions & 4 deletions test/core/var/test_var.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_import_sub(self):
"b": "b",
"c": "c",
"d": True,
"d2": "True",
"d2": "true",
"jsonData": {
"secInDay": 86400,
}
Expand All @@ -92,7 +92,7 @@ def test_import_nested(self):
"b": "b",
"c": "c",
"d": True,
"d2": "True",
"d2": "true",
"jsonData": {
"secInDay": 86400,
},
Expand All @@ -111,7 +111,7 @@ def test_sub_external_command_properties(self):
"b": "b",
"c": "c",
"d": True,
"d2": "True",
"d2": "true",
"jsonData": {
"secInDay": 86400,
},
Expand All @@ -129,7 +129,7 @@ def test_sub_external_env_properties(self):
"b": "b",
"c": "c",
"d": True,
"d2": "True",
"d2": "true",
"jsonData": {
"secInDay": 86400,
},
Expand Down
29 changes: 22 additions & 7 deletions test/extensions/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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")
Expand Down Expand Up @@ -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}")
Expand All @@ -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/"
Expand All @@ -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")
Expand Down

0 comments on commit e94b029

Please sign in to comment.