Skip to content

Commit

Permalink
don't cast None parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
gdoumenc committed May 17, 2024
1 parent 962a71f commit 45292c0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion coworks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def get_typed_value(name: str, parameter_type, val):
return {arg(v) for v in val}
return {arg(val)}
if origin is None:
if not parameter_type or parameter_type is Signature.empty:
if val is None or not parameter_type or parameter_type is Signature.empty:
return val
if isinstance(val, list):
msg = f"Multiple values for '{name}' query parameters are not allowed"
Expand Down
19 changes: 18 additions & 1 deletion tests/coworks/tech/test_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def get(self, i: int):
def get_(self, i: int = 0):
return ("ok", 200) if type(i) is int else ("not ok", 400)

@entry
def post_str(self, s: str = None):
return s

@entry
def get_bool(self, i: bool):
if type(i) is bool:
Expand Down Expand Up @@ -63,6 +67,20 @@ def test_base_type(self):
response = c.post('/', json={'i': 'abc'})
assert response.status_code == 422

def test_str(self):
app = TypedMS()

with app.test_client() as c:
response = c.post('/str')
assert response.status_code == 204

response = c.post('/str', json={'s': None})
assert response.status_code == 204

response = c.post('/str', json={'s': ''})
assert response.status_code == 200
assert response.get_data(as_text=True) == ""

def test_bool(self):
app = TypedMS()

Expand Down Expand Up @@ -99,7 +117,6 @@ def test_bool(self):
assert response.status_code == 200
assert response.get_data(as_text=True) == "false"


def test_union_type(self):
app = TypedMS()

Expand Down
2 changes: 0 additions & 2 deletions tests/cws/test_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ def test_run_prod_stage(self, example_dir, unused_tcp_port):
assert response.text == "Value of environment variable test is : test prod environment variable."
server.terminate()

import pytest
@pytest.mark.wip
def test_load_env(self):
variables = load_dotenv("dev")
assert True
Expand Down

0 comments on commit 45292c0

Please sign in to comment.