Skip to content

Develop->Main #24

Merged
merged 11 commits into from
Apr 18, 2025
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/
Binary file added backend/__pycache__/pets.cpython-310.pyc
Binary file not shown.
43 changes: 43 additions & 0 deletions backend/db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import sqlite3
import os

def init_db():
"""Initialize the database, creating tables and inserting initial data."""
db_path = os.path.join(os.path.dirname(__file__), 'animal_shelter.db')

if os.path.exists(db_path):
print("Database already initialized.")
return

# Connect to SQLite database (it will create the file if it doesn't exist)
conn = sqlite3.connect(db_path)
cursor = conn.cursor()

# Create tables
cursor.execute('''CREATE TABLE IF NOT EXISTS animals (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
species TEXT NOT NULL,
breed TEXT,
age INTEGER,
personality TEXT,
image_path TEXT,
adoption_status TEXT DEFAULT 'Available'
)''')

cursor.execute('''CREATE TABLE IF NOT EXISTS adopters (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT UNIQUE NOT NULL,
password TEXT NOT NULL,
email TEXT UNIQUE,
join_date TEXT DEFAULT CURRENT_TIMESTAMP
)''')

# Insert initial data (e.g., a test animal)
cursor.execute('''INSERT INTO animals (name, species, breed, age, personality, image_path)
VALUES (?, ?, ?, ?, ?, ?)''',
('TestDog', 'Dog', 'Mixed', 2, 'Friendly', '/images/test.jpg'))

conn.commit()
conn.close()
print("Database initialized and initial data inserted.")
2 changes: 1 addition & 1 deletion backend/init_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def populate_initial_data(conn):
conn.commit()

if __name__ == "__main__":
print("Initializing adoption database...")
print("Initializing pet adoption database...")
conn = sqlite3.connect('animal_shelter.db')
create_database_tables(conn)
populate_initial_data(conn)
Expand Down
Loading
Loading