Skip to content

Commit

Permalink
release 0.0.14 (#62)
Browse files Browse the repository at this point in the history
- [x] multiline curl
- [x] suggest mimetype from file_extension
- [x] fix failing tests errantly
  • Loading branch information
cedric05 authored Apr 26, 2021
1 parent 60f16f3 commit 62fb23e
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 23 deletions.
23 changes: 11 additions & 12 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions dothttp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from io import IOBase
from typing import Union, List, Optional, Dict, DefaultDict, Tuple, BinaryIO
from urllib.parse import urlencode
import mimetypes

try:
import jstyleson as json
Expand Down Expand Up @@ -421,9 +422,10 @@ def get_mimetype_from_file(filename, mimetype: Optional[str]) -> Optional[str]:
if mimetype:
return mimetype
if magic:
return magic.from_file(filename, mime=True)
else:
return None
mimetype = magic.from_file(filename, mime=True)
elif mimetypes:
mimetype = mimetypes.guess_type(filename, strict=False)[0]
return mimetype

@staticmethod
def get_mimetype_from_buffer(data, mimetype: Optional[str]) -> Optional[str]:
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.13'
__version__ = '0.0.14'
5 changes: 5 additions & 0 deletions dothttp/request_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

class RequestBase(HttpDefBase):
global_session = Session()

def __init__(self, args: Config):
super().__init__(args)
self._cookie: Union[LWPCookieJar, None] = None
Expand Down Expand Up @@ -143,6 +144,10 @@ def get_curl_output(self):
parts.append(('--form', file[0] + "=" + file[1][1]))
else:
parts.append(('--form', file[0] + "=@" + file[1][1].name))
elif self.http.payload.json:
dumps = json.dumps(payload.json, indent=4)
prep.headers["content-type"] = "application/json"
prep.prepare_body(data=dumps, files=None)
else:
prep.prepare_body(data=payload.data, json=payload.json, files=payload.files)
curl_req = to_curl(prep, parts)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ idna==2.10; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.
jsonschema==3.2.0
jstyleson==0.0.2
pyrsistent==0.17.3; python_version >= '3.5'
python-magic==0.4.18
python-magic==0.4.22
requests==2.25.1
six==1.15.0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
textx==2.3.0
Expand Down
7 changes: 4 additions & 3 deletions test/core/test_random_substition.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ class SubstitutionTest(TestBase):
def test_basic(self):
int_request: PreparedRequest = self.get_request(file=f'{base_dir}/random.http', target='int')
int_payload = json.loads(int_request.body)
intValue = int(int_payload['test'])
self.assertTrue(100 <= intValue < 1000, f'value is {intValue}')
int_value = int(int_payload['test'])
print(f'int_value {int_value} and int_payload {int_payload}')
self.assertTrue(100 <= int_value < 1000, f'value is {int_value}')
self.assertTrue(int(int_payload['test2']))

bool_request: PreparedRequest = self.get_request(file=f'{base_dir}/random.http', target=2)
Expand All @@ -47,7 +48,7 @@ def test_basic(self):
str_request: PreparedRequest = self.get_request(file=f'{base_dir}/random.http', target='str')
data = json.loads(str_request.body)
self.assertTrue(10 == len(data['test']), f'this is skeptical {str_request.body}')
self.assertTrue(1 < len(data['test2']) <= 10, data['test2'])
self.assertTrue(1 <= len(data['test2']) <= 10, data['test2'])

float_request: PreparedRequest = self.get_request(file=f'{base_dir}/random.http', target='float')
request_data = json.loads(float_request.body)
Expand Down
8 changes: 5 additions & 3 deletions test/core/test_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,11 @@ def test_multiline_curl_linux(self):

# with json out
self.assertEqual('''curl -X POST \\
-H 'Content-Length: 13' \\
-H 'Content-Type: application/json' \\
-d '{"hi": "hi2"}' \\
-H 'Content-Length: 19' \\
-H 'content-type: application/json' \\
-d '{
"hi": "hi2"
}' \\
https://httpbin.org/post''', self.get_curl_out(f, 3))

def get_curl_out(self, f, target=1):
Expand Down

0 comments on commit 62fb23e

Please sign in to comment.