From 796a8ff067662e50f571a5b0b3b037ce52c985ce Mon Sep 17 00:00:00 2001 From: prince rusweka Date: Sat, 26 Apr 2025 03:07:42 -0400 Subject: [PATCH] Committing local changes before pulling --- backend/main.py | 102 +++++++++--------- backend/pets.py | 9 +- backend/test_main.py | 14 ++- .../test_api.cpython-311-pytest-8.3.4.pyc | Bin 11731 -> 11731 bytes backend/tests/test_api.py | 32 +++--- 5 files changed, 90 insertions(+), 67 deletions(-) diff --git a/backend/main.py b/backend/main.py index c76f5db..cc08ed8 100644 --- a/backend/main.py +++ b/backend/main.py @@ -28,52 +28,53 @@ def init_db(): create_tables(conn) pets = [ - ( - "Buddy", - "Dog", - "Golden Retriever", - 3, - "Friendly", - "/images/buddy.jpg", - "Available", - ), - ( - "Whiskers", - "Cat", - "Siamese", - 2, - "Independent", - "/images/whiskers.jpg", - "Available", - ), - ( - "Rex", - "Dog", - "German Shepherd", - 4, - "Protective", - "/images/rex.jpg", - "Available", - ), - ( - "Max", - "Dog", - "Labrador Retriever", - 5, - "Playful", - "/images/max.jpg", - "Adopted", - ), - ( - "Mittens", - "Cat", - "Persian", - 1, - "Lazy", - "/images/mittens.jpg", - "Available", - ), - ("Bella", "Dog", "Bulldog", 2, "Gentle", "/images/bella.jpg", "Available"), + ("Buddy", + "Dog", + "Golden Retriever", + 3, + "Friendly", + "/images/buddy.jpg", + "Available", + ), + ("Whiskers", + "Cat", + "Siamese", + 2, + "Independent", + "/images/whiskers.jpg", + "Available", + ), + ("Rex", + "Dog", + "German Shepherd", + 4, + "Protective", + "/images/rex.jpg", + "Available", + ), + ("Max", + "Dog", + "Labrador Retriever", + 5, + "Playful", + "/images/max.jpg", + "Adopted", + ), + ("Mittens", + "Cat", + "Persian", + 1, + "Lazy", + "/images/mittens.jpg", + "Available", + ), + ("Bella", + "Dog", + "Bulldog", + 2, + "Gentle", + "/images/bella.jpg", + "Available"), ] cursor = conn.cursor() @@ -143,16 +144,19 @@ def add_pet(): for field in required_fields: if field not in pet_data: - return jsonify({"error": f"Missing required field: {field}"}), 400 + return jsonify( + {"error": f"Missing required field: {field}"}), 400 if not (0 < pet_data["age"] < 100): # adding validation - return jsonify({"error": "Invalid age. Must be between 1 and 99"}), 400 + return jsonify( + {"error": "Invalid age. Must be between 1 and 99"}), 400 conn = get_db() cursor = conn.cursor() # Check for duplicate pet name - cursor.execute("SELECT * FROM animals WHERE name = ?", (pet_data["name"],)) + cursor.execute("SELECT * FROM animals WHERE name = ?", + (pet_data["name"],)) existing = cursor.fetchone() if existing: return jsonify({"error": "Pet already exists"}), 409 diff --git a/backend/pets.py b/backend/pets.py index 9fc318c..47c9dae 100644 --- a/backend/pets.py +++ b/backend/pets.py @@ -126,7 +126,8 @@ def add_pet(pet_data): required_fields = ["name", "breed", "age", "temperament"] for field in required_fields: if field not in pet_data: - return jsonify({"error": f"Missing required field: {field}"}), 400 + return jsonify( + {"error": f"Missing required field: {field}"}), 400 # Generate a new ID (in a real app, the database would handle this) new_id = max(pet["id"] for pet in PETS) + 1 if PETS else 1 @@ -174,7 +175,8 @@ def update_pet(pet_id, pet_data): """ try: # Find the pet with the given ID - pet_index = next((i for i, p in enumerate(PETS) if p["id"] == pet_id), None) + pet_index = next( + (i for i, p in enumerate(PETS) if p["id"] == pet_id), None) if pet_index is None: return jsonify({"error": "Pet not found"}), 404 @@ -209,7 +211,8 @@ def delete_pet(pet_id): """ try: # Find the pet with the given ID - pet_index = next((i for i, p in enumerate(PETS) if p["id"] == pet_id), None) + pet_index = next( + (i for i, p in enumerate(PETS) if p["id"] == pet_id), None) if pet_index is None: return jsonify({"error": "Pet not found"}), 404 diff --git a/backend/test_main.py b/backend/test_main.py index 1c7b925..3d19653 100644 --- a/backend/test_main.py +++ b/backend/test_main.py @@ -56,7 +56,13 @@ def setup_test_database(): # Add test data cursor.execute( "INSERT INTO animals (name, species, breed, age, personality, image_path, adoption_status) VALUES (?, ?, ?, ?, ?, ?, ?)", - ("TestDog", "Dog", "Mixed", 2, "Friendly", "/images/test.jpg", "Available"), + ("TestDog", + "Dog", + "Mixed", + 2, + "Friendly", + "/images/test.jpg", + "Available"), ) conn.commit() @@ -106,8 +112,10 @@ def test_login_user(client): # Test login with incorrect password response = client.post( - "/api/login", json={"username": "testuser", "password": "WrongPassword"} - ) + "/api/login", + json={ + "username": "testuser", + "password": "WrongPassword"}) assert response.status_code == 401 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 index e97211f892327e8d0ece3dfc6bc30056870774d3..57e1ca4d2b25f26159e1617a49cbbd24819ec1f6 100644 GIT binary patch delta 114 zcmcZ{eL0$UIWI340}yOz;>oDm$m_?!$hkR&qnC@3fAcG$1U5#^$=;Igj1M+XmR!lo wXujE2em^Ip>*l{2wJdsU%#6Ap7~lktIHULn1~_5D&8YW*0ZzzFUZJZE08L*Xs{jB1 delta 114 zcmcZ{eL0$UIWI340}ylsaA)Lf