Skip to content

Commit

Permalink
add coulple of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric05 committed Dec 29, 2024
1 parent 6dc6104 commit 56ef2fa
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 13 deletions.
2 changes: 2 additions & 0 deletions dothttp/parse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions test/core/var/.dothttp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"test": {
"a": "b"
}
}
8 changes: 8 additions & 0 deletions test/core/var/override.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import "./par.http";
var a = 10;


POST "https://httpbin.org/post"
json({
"a": {{a}}
})
72 changes: 59 additions & 13 deletions test/core/var/test_var.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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"
Expand All @@ -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(
Expand All @@ -78,15 +78,14 @@ def test_import_sub(self):
"c": "c",
"d": True,
"d2": "True",
"jsonData":{
"jsonData": {
"secInDay": 86400,
}
},
json.loads(req.body),
"incorrect body",
)


def test_import_nested(self):
req = self.get_request(f"{base_dir}/grand_child.http")
self.assertEqual(
Expand All @@ -96,11 +95,58 @@ 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',
},
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",
)

0 comments on commit 56ef2fa

Please sign in to comment.