-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
162 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,74 @@ | ||
name: Backend CI | ||
name: Backend CI Pipeline | ||
|
||
on: | ||
push: | ||
paths: | ||
- 'backend/**' | ||
branches: | ||
- develop | ||
- main | ||
pull_request: | ||
paths: | ||
- 'backend/**' | ||
branches: | ||
- develop | ||
- main | ||
|
||
jobs: | ||
backend-ci: | ||
runs-on: ubuntu-latest | ||
lint: | ||
runs-on: self-hosted | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.11' | ||
|
||
- name: Install dependencies | ||
working-directory: ./backend | ||
run: | | ||
pip install -r requirements.txt | ||
python -m venv venv | ||
source venv/bin/activate | ||
pip install -r backend/requirements.txt | ||
- name: Run pylint on backend | ||
working-directory: ./backend | ||
- name: Run pylint on Python code | ||
run: | | ||
pylint main.py db.py init_db.py | ||
source venv/bin/activate | ||
pylint backend/main.py backend/db.py backend/init_db.py | ||
- name: Run Pytest | ||
working-directory: ./backend | ||
test: | ||
runs-on: self-hosted | ||
needs: lint # Ensure this job runs after linting | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.11' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m venv venv | ||
source venv/bin/activate | ||
pip install -r backend/requirements.txt | ||
- name: Start the API server | ||
run: | | ||
nohup python backend/main.py & # Start the API server in the background | ||
# Wait for the server to be ready | ||
for i in {1..10}; do | ||
if curl --silent --fail http://127.0.0.1:5000/; then | ||
echo "Server is up and running." | ||
break | ||
fi | ||
echo "Waiting for server to start... Attempt $i/10" | ||
sleep 3 | ||
done | ||
- name: Run tests with pytest | ||
env: | ||
BASE_URL: http://127.0.0.1:5000 # Assuming your API is running on this address | ||
run: | | ||
python main.py & # Run server | ||
sleep 5 # Give it time to start | ||
pytest tests/ | ||
source venv/bin/activate | ||
pytest backend/tests --maxfail=1 --disable-warnings -q |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,42 @@ | ||
"""Script to initialize the database and populate it with initial data.""" | ||
|
||
import sqlite3 | ||
import random | ||
import os | ||
from utils import create_tables | ||
|
||
def create_database_tables(conn): | ||
cursor = conn.cursor() | ||
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 | ||
) | ||
''') | ||
conn.commit() | ||
# Constants | ||
DB_PATH = os.path.join(os.path.dirname(__file__), 'animal_shelter.db') | ||
|
||
def populate_initial_data(conn): | ||
"""Populate the database with initial data for testing.""" | ||
cursor = conn.cursor() | ||
|
||
# Sample animals data | ||
|
||
animals = [ | ||
('Luna', 'Dog', 'Labrador Mix', 2, 'Playful and energetic', '/images/luna.jpg', 'Available'), | ||
('Oliver', 'Cat', 'Tabby', 4, 'Independent but affectionate', '/images/oliver.jpg', 'Available'), | ||
('Max', 'Dog', 'German Shepherd', 3, 'Loyal and intelligent', '/images/max.jpg', 'Available') | ||
('Luna', 'Dog', 'Labrador Mix', 2, | ||
'Playful and energetic', '/images/luna.jpg', | ||
'Available'), | ||
('Oliver', 'Cat', 'Tabby', 4, | ||
'Independent but affectionate', '/images/oliver.jpg', | ||
'Available'), | ||
('Max', 'Dog', 'German Shepherd', 3, | ||
'Loyal and intelligent', '/images/max.jpg', | ||
'Available') | ||
] | ||
|
||
for animal in animals: | ||
cursor.execute(''' | ||
INSERT INTO animals (name, species, breed, age, personality, image_path, adoption_status) | ||
VALUES (?, ?, ?, ?, ?, ?, ?) | ||
''', animal) | ||
|
||
INSERT INTO animals (name, species, breed, age, personality, image_path, adoption_status) | ||
VALUES (?, ?, ?, ?, ?, ?, ?)''', animal) | ||
|
||
conn.commit() | ||
|
||
if __name__ == "__main__": | ||
print("Initializing pet adoption database...") | ||
conn = sqlite3.connect('animal_shelter.db') | ||
create_database_tables(conn) | ||
def initialize_database(db_path): | ||
"""Initialize the database by creating tables and populating initial data.""" | ||
conn = sqlite3.connect(db_path) | ||
create_tables(conn) | ||
populate_initial_data(conn) | ||
print("Database setup complete!") | ||
conn.close() | ||
print("Database initialized successfully with initial data.") | ||
|
||
if __name__ == "__main__": | ||
initialize_database(DB_PATH) |
Oops, something went wrong.