Skip to content

Commit

Permalink
Added test for is_allow_empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Seluj78 committed Sep 22, 2024
1 parent 5d8b75d commit ef9babd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 0 additions & 1 deletion flask_utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ def _is_allow_empty(value: Any, type_hint: Type) -> bool: # type: ignore
.. versionadded:: 0.2.0
"""
if not value:
# TODO: Find a test for this
# Check if type is explicitly Optional or allow_empty is True
if _is_optional(type_hint):
return True
Expand Down
20 changes: 20 additions & 0 deletions tests/test_validate_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import pytest
from flask import Flask
from flask import jsonify

from flask_utils import validate_params

Expand Down Expand Up @@ -579,3 +580,22 @@ def test_valid_request(self, client):
response = client.post("/users/123", json={"user_id": 456})
assert response.status_code == 200
assert response.text == "456"


class TestEmptyValues:
@pytest.fixture(autouse=True)
def setup_routes(self, flask_client):
@flask_client.route("/empty", methods=["POST"])
@validate_params()
def empty_route(name: Optional[str]):
return jsonify({"name": name})

def test_empty_value_optional(self, client):
response = client.post("/empty", json={})
assert response.status_code == 200
assert response.get_json() == {"name": None}

# Testing with 'name' as empty string
response = client.post("/empty", json={"name": ""})
assert response.status_code == 200
assert response.get_json() == {"name": ""}

0 comments on commit ef9babd

Please sign in to comment.