-
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.
Merge pull request #23 from CSE2102-Spring25/develop-prince
finished backend pipeline and testing
- Loading branch information
Showing
5 changed files
with
79 additions
and
13 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
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/ |
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,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.
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 |
---|---|---|
@@ -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 |