Repository: apache/airflow
File: airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_pools.py (Python)

Code before:
    def test_post_pool_allows_unlimited_slots(self, test_client, session):
        """POST /pools should accept slots = -1 (unlimited)."""
        self.create_pools()
        n_pools = session.scalar(select(func.count()).select_from(Pool))

        response = test_client.post(
            "/pools",
            json={
                "name": "unlimited_pool",
                "slots": -1,
                "description": "Unlimited pool",
                "include_deferred": False,
            },
        )

        assert response.status_code == 201
        body = response.json()
        assert body["name"] == "unlimited_pool"
        assert body["slots"] == -1
        assert body.get("open_slots") in (None, float("inf"),"Infinity")
        assert session.scalar(select(func.count()).select_from(Pool)) == n_pools + 1
        check_last_log(session, dag_id=None, event="post_pool", logical_date=None)


    def test_post_pool_accepts_infinity_string(self, test_client, session):
        """POST /pools should accept 'infinity' string for slots and coerce to -1."""
        self.create_pools()
        n_pools = session.scalar(select(func.count()).select_from(Pool))

        response = test_client.post(
            "/pools",
            json={
                "name": "infinite_pool",
                "slots": "infinity",
                "description": "Infinite pool",
                "include_deferred": False,
            },
        )

        assert response.status_code == 201
        assert response.json()["slots"] == -1
        assert session.scalar(select(func.count()).select_from(Pool)) == n_pools + 1
        check_last_log(session, dag_id=None, event="post_pool", logical_date=None)



    def test_should_respond_401(self, unauthenticated_test_client):
        response = unauthenticated_test_client.post("/pools", json={})
        assert response.status_code == 401

    def test_should_respond_403(self, unauthorized_test_client):

Review comment (suggestion):
We don't need to allow 'infinity'. User should pass '-1' for that and it should be documented in the endpoint spec.

Code after:
        self.create_pools()
        n_pools = session.scalar(select(func.count()).select_from(Pool))

        response = test_client.post(
            "/pools",
            json={
                "name": "unlimited_pool",
                "slots": -1,
                "description": "Unlimited pool",
                "include_deferred": False,
            },
        )

        assert response.status_code == 201
        body = response.json()
        assert body["name"] == "unlimited_pool"
        assert body["slots"] == -1
        assert body["open_slots"] == -1
        assert session.scalar(select(func.count()).select_from(Pool)) == n_pools + 1
        check_last_log(session, dag_id=None, event="post_pool", logical_date=None)

    def test_post_pool_rejects_infinity_string(self, test_client, session):
        response = test_client.post(
            "/pools",
            json={
                "name": "bad_pool",
                "slots": "infinity",
                "include_deferred": False,
            },
        )
        assert response.status_code == 422

    def test_should_respond_401(self, unauthenticated_test_client):
        response = unauthenticated_test_client.post("/pools", json={})
        assert response.status_code == 401

    def test_should_respond_403(self, unauthorized_test_client):
        response = unauthorized_test_client.post("/pools", json={})
        assert response.status_code == 403

    @pytest.mark.parametrize(
        (
            "body",
            "first_expected_status_code",
            "first_expected_response",
            "second_expected_status_code",
            "second_expected_response",
        ),
        [
            (
                {"name": "my_pool", "slots": 11},