Skip to content

Commit

Permalink
0.0.16 release (#71)
Browse files Browse the repository at this point in the history
- triple quote string in json
- randomStr subs bug fix
- 0.0.15 regression
  • Loading branch information
cedric05 authored May 14, 2021
1 parent 5b77e07 commit 35ec08c
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 8 deletions.
7 changes: 6 additions & 1 deletion dotextensions/server/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ def get_request_result(self, command, comp):
"headers":
{key: value for key, value in resp.headers.items()},
"body": resp.text, # for binary out, it will fail, check for alternatives
"status": resp.status_code, "url": resp.url}
"status": resp.status_code,
"method": resp.request.method,
"url": resp.url}
}
# will be used for response
data = {}
Expand Down Expand Up @@ -236,6 +238,9 @@ def parse_n_get(self, http_data):
class ContentNameReferencesHandler(GetNameReferencesHandler):
name = "/content/names"

def get_method(self):
return ContentNameReferencesHandler.name

def execute(self, command, filename):
http_data = command.params.get("content", "")
all_names, all_urls = self.parse_n_get(http_data)
Expand Down
2 changes: 1 addition & 1 deletion dothttp/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.0.15'
__version__ = '0.0.16'
7 changes: 6 additions & 1 deletion dothttp/dsl_jsonparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@ def json_or_array_to_json(model, update_content_func) -> Union[Dict, List]:
def get_key(member, update_content_func):
if member.key:
return update_content_func(member.key)
return update_content_func(member.var)
elif member.var:
return update_content_func(member.var)
else:
return update_content_func(member.multi[3:-3])


def jsonmodel_to_json(model, update_content_func):
if str_value := model.str:
return update_content_func(str_value.value)
elif var_value := model.var:
return get_json_data(var_value, update_content_func)
elif multi_value := model.multi:
return get_json_data(multi_value[3:-3], update_content_func)
elif flt := model.flt:
return flt.value
elif bl := model.bl:
Expand Down
5 changes: 3 additions & 2 deletions dothttp/http.tx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Array:
;

Value:
str=String | var=VarString | flt=Float | bl=Bool | object=Object | array=Array | null="null"
multi=MULTILINE_STRING | str=String | var=VarString | flt=Float | bl=Bool | object=Object | array=Array | null="null"
;


Expand All @@ -98,6 +98,7 @@ Object:
;

Member:
(multi=MULTILINE_STRING ':' value=Value) |
(key=STRING ':' value=Value) |
(var=VarString ':' value=Value)
;
Expand Down Expand Up @@ -125,7 +126,7 @@ DotString:
// allow only alphanumeric or string in double/single quotes

MULTILINE_STRING:
/"""[\S\s]*"""/ | /'''[\S\s]*'''/
/"""[\S\s]*?"""/ | /'''[\S\s]*?'''/

;

Expand Down
2 changes: 1 addition & 1 deletion dothttp/property_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class PropertyProvider:
random = Random()
var_regex = re.compile(r'{{(?P<var>.*?)}}', re.DOTALL)
random_string_regex = re.compile(
r'(?P<category>\$randomStr|\$randomInt|\$randomBool|\$randomFloat)(?P<length>:\d*)?')
r'.*?(?P<category>\$randomStr|\$randomInt|\$randomBool|\$randomFloat)(?P<length>:\d*)?')

rand_map = {
'$randomStr': get_random_str,
Expand Down
40 changes: 40 additions & 0 deletions test/core/payload/multilinejson.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
@name("simple1")
POST https://httpbin.org/post
json({
"simple": """test"""
})

@name("simple2")
POST https://httpbin.org/post
json({
"simple": '''test'''
})


@name("withquotes")
POST https://httpbin.org/post
json({
"simple": '''
test
"simple 1"
'simple 2'
''simple 3''
""simple 4""

'''
})



@name("withquoteskey")
POST https://httpbin.org/post
json({
"""simple""": '''
test
"simple 1"
'simple 2'
''simple 3''
""simple 4""

'''
})
14 changes: 12 additions & 2 deletions test/core/test_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,26 @@ def test_multipart_payload(self):
loadfile.close()
os.unlink(loadfile.name)

def test_data_json_payload(self):
def test_data_multi_payload(self):
req = self.get_request(f"{base_dir}/quoted.http")
self.assertEqual("""
"'this can have quotes with escape sequence'"
""", req.body)

def test_data_json_payload(self):
def test_data_multi2_payload(self):
req = self.get_request(f"{base_dir}/quoted2.http")
self.assertEqual("""
"'this can have quotes with escape sequence'"
""", req.body)

def test_multi_in_json_payload(self):
self.assertEqual(b'{"simple": "test"}', self.get_request(f"{base_dir}/multilinejson.http", target='1').body)
self.assertEqual(b'{"simple": "test"}', self.get_request(f"{base_dir}/multilinejson.http", target="2").body)
self.assertEqual(b'{"simple": "\\ntest\\n\\"simple 1\\"\\n\'simple 2\'\\n\'\'simple 3\'\'\\n'
b'\\"\\"simple 4\\"\\"\\n\\n"}',
self.get_request(f"{base_dir}/multilinejson.http", target="3").body)
self.assertEqual(b'{"simple": "\\ntest\\n\\"simple 1\\"\\n\'simple 2\'\\n\'\'simple 3\'\'\\n'
b'\\"\\"simple 4\\"\\"\\n\\n"}',
self.get_request(f"{base_dir}/multilinejson.http", target="4").body)

0 comments on commit 35ec08c

Please sign in to comment.