From 424f76f38bb976370b199db2d8ff22832cd5f587 Mon Sep 17 00:00:00 2001 From: prince rusweka Date: Thu, 17 Apr 2025 23:44:29 -0400 Subject: [PATCH] finished backend pipeline and testing --- backend/.github/workflows/backend-ci.yml | 39 ++++++++++++++++++ backend/main.py | 3 +- backend/requirements.txt | 17 +++----- .../test_api.cpython-311-pytest-8.3.4.pyc | Bin 0 -> 5750 bytes backend/tests/test_api.py | 33 +++++++++++++++ 5 files changed, 79 insertions(+), 13 deletions(-) create mode 100644 backend/.github/workflows/backend-ci.yml create mode 100644 backend/tests/__pycache__/test_api.cpython-311-pytest-8.3.4.pyc create mode 100644 backend/tests/test_api.py diff --git a/backend/.github/workflows/backend-ci.yml b/backend/.github/workflows/backend-ci.yml new file mode 100644 index 0000000..93a0191 --- /dev/null +++ b/backend/.github/workflows/backend-ci.yml @@ -0,0 +1,39 @@ +name: Backend CI + +on: + push: + paths: + - 'backend/**' + pull_request: + paths: + - 'backend/**' + +jobs: + backend-ci: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.11' + + - name: Install dependencies + working-directory: ./backend + run: | + pip install -r requirements.txt + + - name: Run pylint on backend + working-directory: ./backend + run: | + pylint main.py db.py init_db.py + + - name: Run Pytest + working-directory: ./backend + run: | + python main.py & # Run server + sleep 5 # Give it time to start + pytest tests/ diff --git a/backend/main.py b/backend/main.py index ad707dd..91ce44f 100644 --- a/backend/main.py +++ b/backend/main.py @@ -229,4 +229,5 @@ def before_first_request(): init_db() if __name__ == "__main__": - app.run(debug=True) + app.run(debug=True, use_reloader=False) + diff --git a/backend/requirements.txt b/backend/requirements.txt index a9f380d..5de15b1 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -1,12 +1,5 @@ -Flask==3.1.1 -Flask-Cors==5.0.2 -flasgger==0.9.7.1 -Werkzeug==3.1.3 -Jinja2==3.1.5 -itsdangerous==2.2.0 -MarkupSafe==3.0.2 -click==8.1.8 -blinker==1.9.0 -PyYAML==6.0.2 -mistune==3.1.2 -jsonschema==4.24.0 \ No newline at end of file +flask +flasgger +requests +pytest +pylint \ No newline at end of file diff --git a/backend/tests/__pycache__/test_api.cpython-311-pytest-8.3.4.pyc b/backend/tests/__pycache__/test_api.cpython-311-pytest-8.3.4.pyc new file mode 100644 index 0000000000000000000000000000000000000000..db01062431c303ac86638ea76663f205edb383bd GIT binary patch literal 5750 zcmd^CUu@gP87C=uy)Y2i9Uk|Kbcf{=BzEmsoN zJ8DTZ3e|!F%~BWfhF~$U1n^5!q#5?yhdu0ZeUkjE6#|%n-9_DYjP@D^fAwIPvOrB z3Op8|4u4kWVo3a)n~S3$$Zo`6;gZq|+B936}WIw49;gVKkp{hO=)GkdP4WWm%*TZ@A7mZrRlhXls?{8*8P!UYt6h5&-uLR5h`PQJGoU+_XIftNafkz@mF9?sp&r{bI3L4Q?4~Qnz(jSBJ zv{m7L!I3`S*x^=_$@!ziew-UmJFdWkXSWqRySmByN9=%V%MOwr2Feo0RYVj*VN=ZV zb}eY^Zbiy*zLDJNV+Q^H{I%OKMQ`#I9{vHyH@ECgs){6VrsU64MKJbl`7;G$|5nXE z%_<=?w91oV6hZP1-@t$`e)kO+uXud;rZ)EXa5LPw2fP*ee{e=f{&(WbgZorw`;1V2 zWL~}RZfAMz*aPyabcj0Se>T+hP_k!kcn32#?C{D{sQyn3BM_vIrD@sr`|YPyfvOA@-H1FaV9~v(IgorM%pM5HKQX zjMHcNw4@OOLS57hD?D}X%C!37?WDU(icAWJA@(oIVd*MIoKntcXg|3mP54ik-6)memW>80*;T zRTp%ePaCRsvzSX4(gw6xB7I=o4YA`M5XlIp)8A64TbA1~Z{@hRl42D$>V&s)(hD2+ zRwli$Q-nH8w94k&@0`B=A-rUAy@<1g%=HY>#>Ym-j}cm396xdFs+P`=PhOu-XFkyi z=sL|Cv84)gaJYEO>akM^=~ihX>7>L%;DRn~eb`!E+Ey%)5yt_;pF5TLi07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0XB*;dO`L5;d+(`t)q3B!(Y6A`~6?dd_Gg1c|I^$69?~1to79tstIM`_E%wi+N!FsEKA>1l}nB~rd zYujdUL2G?32yCD;AFgB;=+A~=7zoJQ%LO-;p4C@ZP63Ht3#|tq#z47qYAyDk&j%C% zKrgGmbIMy=i+R~P=z#WK%mM^|=NzAP$H!p8Cwr`L>)dEB1J;1bPMX8)TnDGWVXWQ2 zumD&Q*JOnp8(T!^@`BHTumqjhD-0|)u)@N*QO_2v5XxeEc@C@ULN=$VDn3Vh&@-3) z={@1>VC>IyGyJo>j!HT0Eqo2yfjDvGOAs3Yp68qNY}VlyuiC#R7pvO8CKsvNzvs$p z)o@epS~+rW=FyZ`_I literal 0 HcmV?d00001 diff --git a/backend/tests/test_api.py b/backend/tests/test_api.py new file mode 100644 index 0000000..851f2d5 --- /dev/null +++ b/backend/tests/test_api.py @@ -0,0 +1,33 @@ +import requests +import sqlite3 +import os + +BASE_URL = "http://127.0.0.1:5000" +DB_PATH = os.path.join(os.path.dirname(__file__), '../animal_shelter.db') + +def test_get_all_pets(): + response = requests.get(f"{BASE_URL}/api/pets") + assert response.status_code == 200 + assert isinstance(response.json(), list) + +def test_add_pet_boundary_age(): + new_pet = { + "name": "Oldy", + "species": "Turtle", + "breed": "Galapagos", + "age": 150, + "personality": "Wise elder", + "image_path": "/images/oldy.jpg" + } + response = requests.post(f"{BASE_URL}/api/pets", json=new_pet) + assert response.status_code == 201 + + # Check if it's actually in the DB + conn = sqlite3.connect(DB_PATH) + cursor = conn.cursor() + cursor.execute("SELECT * FROM animals WHERE name = ?", (new_pet['name'],)) + result = cursor.fetchone() + conn.close() + + assert result is not None + assert result[4] == new_pet["age"] # age