Skip to content

Commit

Permalink
Fixed a bug on the creation curl with json request
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammadsheikhian committed Apr 18, 2019
1 parent 6a10410 commit e6934cf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion bddrest/documentary/curl.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import io
import json


class CURL:

def __init__(self, url, form, query, authorization, verb='GET',
content_type='text/plain', headers=[], nerds_readable=None, multipart=None):
content_type='text/plain', headers=[], nerds_readable=None,
multipart=None, json=None):

self._url = url
self._query = query
Expand All @@ -15,6 +17,7 @@ def __init__(self, url, form, query, authorization, verb='GET',
self.content_type = content_type
self.authorization = authorization
self.nerds_readable = nerds_readable
self._json = json

def __repr__(self):
return ' '.join(self.parts)
Expand All @@ -40,6 +43,11 @@ def form(self):

return ' '.join(form_parts)

@property
def json(self):
if self._json:
return f'--data {json.dumps(self._json)}'

@property
def multipart(self):
multipart_parts = []
Expand Down Expand Up @@ -81,6 +89,9 @@ def parts(self):
if self.multipart:
parts.append(self.multipart)

if self.json:
parts.append(self.json)

if self.headers:
parts.append(self.headers)

Expand Down Expand Up @@ -111,6 +122,7 @@ def from_call(cls, call):
authorization=call.authorization,
headers=[f'{k}: {v}' for k, v in call.headers or []],
multipart=call.multipart,
json=call.json,
)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion bddrest/tests/test_json_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_update_json_fields():
### CURL
```bash
curl -X POST -- "$URL/?"
curl -X POST --data {"a": 1, "b": null, "c": false} -- "$URL/?"
```
### Response: 200 OK
Expand Down

0 comments on commit e6934cf

Please sign in to comment.