Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix @uplink.*Map to not throw error if converter is None #231

Merged
merged 1 commit into from
Aug 3, 2021
Merged
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
4 changes: 4 additions & 0 deletions tests/integration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ def headers(self):
def data(self):
return self._extras.get("data", None)

@property
def files(self):
return self._extras.get("files", None)

@property
def json(self):
return self._extras.get("json", None)
Expand Down
23 changes: 23 additions & 0 deletions tests/integration/test_form_url_encoded.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Local imports
from uplink import Consumer, form_url_encoded, put, FieldMap

# Constants
BASE_URL = "https://example.com/"


def test_without_converter(mock_response, mock_client):
class Calendar(Consumer):
@form_url_encoded
@put("/user/repos")
def add_event(self, **event_data: FieldMap):
pass

mock_client.with_response(mock_response)
calendar = Calendar(base_url=BASE_URL, client=mock_client)

# Run
calendar.add_event(name="Weekly Stand-up", public=True)

# Assertions: should not convert if converter is None
request = mock_client.history[0]
assert request.data == {"name": "Weekly Stand-up", "public": True}
24 changes: 24 additions & 0 deletions tests/integration/test_multipart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Local imports
from uplink import Consumer, PartMap, post, multipart

# Constants
BASE_URL = "https://example.com/"


def test_without_converter(mock_response, mock_client):
class Calendar(Consumer):
@multipart
@post("/attachments")
def upload_attachments(self, **files: PartMap):
pass

mock_client.with_response(mock_response)
calendar = Calendar(base_url=BASE_URL, client=mock_client)
file = object()

# Run
calendar.upload_attachments(file=file)

# Assertion: should not convert if converter is None
request = mock_client.history[0]
assert request.files == {"file": file}
2 changes: 2 additions & 0 deletions uplink/converters/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def __call__(self, converter_registry):

def factory_wrapper(*args, **kwargs):
converter = factory(*args, **kwargs)
if not converter:
return None
return functools.partial(self.convert, converter)

return factory_wrapper
Expand Down