Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit ef9babd

Browse files
committed
Added test for is_allow_empty
1 parent 5d8b75d commit ef9babd

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

flask_utils/decorators.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ def _is_allow_empty(value: Any, type_hint: Type) -> bool: # type: ignore
8686
.. versionadded:: 0.2.0
8787
"""
8888
if not value:
89-
# TODO: Find a test for this
9089
# Check if type is explicitly Optional or allow_empty is True
9190
if _is_optional(type_hint):
9291
return True

tests/test_validate_params.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import pytest
99
from flask import Flask
10+
from flask import jsonify
1011

1112
from flask_utils import validate_params
1213

@@ -579,3 +580,22 @@ def test_valid_request(self, client):
579580
response = client.post("/users/123", json={"user_id": 456})
580581
assert response.status_code == 200
581582
assert response.text == "456"
583+
584+
585+
class TestEmptyValues:
586+
@pytest.fixture(autouse=True)
587+
def setup_routes(self, flask_client):
588+
@flask_client.route("/empty", methods=["POST"])
589+
@validate_params()
590+
def empty_route(name: Optional[str]):
591+
return jsonify({"name": name})
592+
593+
def test_empty_value_optional(self, client):
594+
response = client.post("/empty", json={})
595+
assert response.status_code == 200
596+
assert response.get_json() == {"name": None}
597+
598+
# Testing with 'name' as empty string
599+
response = client.post("/empty", json={"name": ""})
600+
assert response.status_code == 200
601+
assert response.get_json() == {"name": ""}

0 commit comments

Comments
 (0)