Skip to content

Commit 27e87e1

Browse files
committed
Remove duplicate call
1 parent f0d7a8c commit 27e87e1

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

ctfcli/core/api.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,19 @@ def request(self, method, url, data=None, files=None, *args, **kwargs):
7474
**kwargs,
7575
)
7676

77-
# If data or files are not key/value pairs, then send the raw values
78-
if data is not None or files is not None:
79-
return super(API, self).request(
80-
method,
81-
url,
82-
data=data,
83-
files=files,
84-
*args,
85-
**kwargs,
86-
)
87-
8877
# otherwise set the content-type to application/json for all API requests
8978
# modify the headers here instead of using self.headers because we don't want to
9079
# override the multipart/form-data case above
91-
if kwargs.get("headers", None) is None:
92-
kwargs["headers"] = {}
93-
94-
kwargs["headers"]["Content-Type"] = "application/json"
95-
return super(API, self).request(method, url, *args, **kwargs)
80+
if data is None and files is None:
81+
if kwargs.get("headers", None) is None:
82+
kwargs["headers"] = {}
83+
kwargs["headers"]["Content-Type"] = "application/json"
84+
85+
return super(API, self).request(
86+
method,
87+
url,
88+
data=data,
89+
files=files,
90+
*args,
91+
**kwargs,
92+
)

tests/core/test_api.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,20 @@ def test_api_object_request_strips_preceding_slash_from_url_path(self, mock_requ
4646

4747
mock_request.assert_has_calls(
4848
[
49-
call("GET", "https://example.com/test/path", headers={"Content-Type": "application/json"}),
50-
call("GET", "https://example.com/test/path", headers={"Content-Type": "application/json"}),
49+
call(
50+
"GET",
51+
"https://example.com/test/path",
52+
headers={"Content-Type": "application/json"},
53+
data=None,
54+
files=None,
55+
),
56+
call(
57+
"GET",
58+
"https://example.com/test/path",
59+
headers={"Content-Type": "application/json"},
60+
data=None,
61+
files=None,
62+
),
5163
]
5264
)
5365

@@ -60,7 +72,7 @@ def test_api_object_request_assigns_prefix_url(self, mock_request: MagicMock, *a
6072
api = API()
6173
api.request("GET", "path")
6274
mock_request.assert_called_once_with(
63-
"GET", "https://example.com/test/path", headers={"Content-Type": "application/json"}
75+
"GET", "https://example.com/test/path", headers={"Content-Type": "application/json"}, data=None, files=None
6476
)
6577

6678
def test_api_object_assigns_ssl_verify(self, *args, **kwargs):

0 commit comments

Comments
 (0)