|
| 1 | +import pytest |
| 2 | +from flask import jsonify |
| 3 | +from flask import request |
| 4 | + |
| 5 | +from flask_utils import is_it_true |
| 6 | + |
| 7 | + |
| 8 | +class TestIsItTrueFunction: |
| 9 | + def test_string_true(self): |
| 10 | + assert is_it_true("true") is True |
| 11 | + |
| 12 | + def test_string_true_uppercase(self): |
| 13 | + assert is_it_true("TRUE") is True |
| 14 | + |
| 15 | + def test_string_true_yes(self): |
| 16 | + assert is_it_true("yes") is True |
| 17 | + |
| 18 | + def test_string_true_yes_uppercase(self): |
| 19 | + assert is_it_true("YES") is True |
| 20 | + |
| 21 | + def test_string_true_one(self): |
| 22 | + assert is_it_true("1") is True |
| 23 | + |
| 24 | + def test_string_false(self): |
| 25 | + assert is_it_true("false") is False |
| 26 | + |
| 27 | + def test_string_false_no(self): |
| 28 | + assert is_it_true("no") is False |
| 29 | + |
| 30 | + def test_string_false_zero(self): |
| 31 | + assert is_it_true("0") is False |
| 32 | + |
| 33 | + |
| 34 | +class TestIsItTrueInFlask: |
| 35 | + @pytest.fixture(autouse=True) |
| 36 | + def setup(self, flask_client): |
| 37 | + @flask_client.route("/example", methods=["GET"]) |
| 38 | + def example(): |
| 39 | + is_ordered = request.args.get("is_ordered", type=is_it_true, default=False) |
| 40 | + return jsonify(is_ordered) |
| 41 | + |
| 42 | + def test_is_ordered_true(self, client): |
| 43 | + response = client.get("example?is_ordered=true") |
| 44 | + assert response.json is True |
| 45 | + |
| 46 | + def test_is_ordered_true_uppercase(self, client): |
| 47 | + response = client.get("example?is_ordered=TRUE") |
| 48 | + assert response.json is True |
| 49 | + |
| 50 | + def test_is_ordered_true_yes(self, client): |
| 51 | + response = client.get("example?is_ordered=yes") |
| 52 | + assert response.json is True |
| 53 | + |
| 54 | + def test_is_ordered_true_yes_uppercase(self, client): |
| 55 | + response = client.get("example?is_ordered=YES") |
| 56 | + assert response.json is True |
| 57 | + |
| 58 | + def test_is_ordered_true_one(self, client): |
| 59 | + response = client.get("example?is_ordered=1") |
| 60 | + assert response.json is True |
| 61 | + |
| 62 | + def test_is_ordered_false(self, client): |
| 63 | + response = client.get("example?is_ordered=false") |
| 64 | + assert response.json is False |
| 65 | + |
| 66 | + def test_is_ordered_false_no(self, client): |
| 67 | + response = client.get("example?is_ordered=no") |
| 68 | + assert response.json is False |
| 69 | + |
| 70 | + def test_is_ordered_false_zero(self, client): |
| 71 | + response = client.get("example?is_ordered=0") |
| 72 | + assert response.json is False |
| 73 | + |
| 74 | + def test_is_ordered_default(self, client): |
| 75 | + response = client.get("example") |
| 76 | + assert response.json is False |
0 commit comments