Skip to content
This repository was archived by the owner on Nov 18, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion klarnacheckout/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ def apply(self, method, resource, options=None):
if method == 'POST':
req.add_header('Content-Type', content_type)
data = options.get('data') or resource.marshal()
req.data = json.dumps(data).encode('utf-8')
if isinstance(data, (list, tuple, dict)):
# data which is iterable must be serialized
req.data = json.dumps(data).encode('utf-8')
else:
req.data = data.encode('utf-8')

return self.handle_response(resource, self.opener.open(req))

Expand Down
9 changes: 9 additions & 0 deletions tests/unit/test_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ def test_create(self):
self._connector.apply.assert_called_once_with(
"POST", self._order, {"url": location, "data": data})

def test_create_json(self):
location = "http://stub"
self._order.base_uri = location
data = '{"foo": "boo"}'
self._order.create(data)

self._connector.apply.assert_called_once_with(
"POST", self._order, {"url": location, "data": data})

def test_fetch(self):
location = "http://stub"
self._order.location = location
Expand Down