diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index df6cb59..a433858 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -1,7 +1,7 @@ # This workflow will install Python dependencies, run tests and lint with a variety of Python versions # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python -name: Python package +name: Test Quart Application on: push: @@ -15,7 +15,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.10"] + python-version: ["3.10", "3.11"] steps: - uses: actions/checkout@v4 @@ -28,7 +28,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - python -m pip install flake8 pytest httpx hypercorn + python -m pip install flake8 pytest httpx hypercorn pytest-asyncio if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - name: Lint with flake8 @@ -38,7 +38,7 @@ jobs: - name: Start Hypercorn for tests run: | - nohup hypercorn -b 127.0.0.1:5000 app:app & + nohup hypercorn -b 127.0.0.1:8000 app:app & sleep 5 - name: Test application with pytest @@ -50,3 +50,4 @@ jobs: run: | pkill -f hypercorn + diff --git a/tests/test_app.py b/tests/test_app.py new file mode 100644 index 0000000..fdef7d8 --- /dev/null +++ b/tests/test_app.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright Hersel Giannella + +import pytest +import httpx + +BASE_URL = "http://127.0.0.1:5000" + +@pytest.mark.asyncio +async def test_home_route(): + """ + Testa la route principale del Blueprint `route_home`. + """ + async with httpx.AsyncClient(base_url=BASE_URL) as client: + response = await client.get("/") + assert response.status_code == 200 + assert "Welcome" in response.text + +@pytest.mark.asyncio +async def test_404_route(): + """ + Verifica la gestione di una route inesistente. + """ + async with httpx.AsyncClient(base_url=BASE_URL) as client: + response = await client.get("/nonexistent") + assert response.status_code == 404 +