Skip to content

finished backend pipeline and testing #23

Merged
merged 1 commit into from
Apr 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions backend/.github/workflows/backend-ci.yml
Original file line number Diff line number Diff line change
@@ -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/
3 changes: 2 additions & 1 deletion backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,5 @@ def before_first_request():
init_db()

if __name__ == "__main__":
app.run(debug=True)
app.run(debug=True, use_reloader=False)

17 changes: 5 additions & 12 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
flask
flasgger
requests
pytest
pylint
Binary file not shown.
33 changes: 33 additions & 0 deletions backend/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -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