From 0c2e4ce586cee0abd2b7ed185e139e3a4ea83839 Mon Sep 17 00:00:00 2001 From: IshayuR Date: Wed, 30 Oct 2024 22:35:55 -0400 Subject: [PATCH] more pylint fixes --- Backend/main.py | 3 +-- Backend/pet_func.py | 11 ++++++----- Backend/test_main.py | 20 +++++++------------- Backend/user_func.py | 4 ++-- 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/Backend/main.py b/Backend/main.py index 980ab9b..641896e 100644 --- a/Backend/main.py +++ b/Backend/main.py @@ -1,7 +1,6 @@ # Module main.py -# This module is the main entry point for the pet adoption web application. +# This module is the main entry point for the pet adoption web application. It defines routes and their functions. from flask import Flask, request, jsonify -import random from pet_func import get_random_pet from user_func import add_user_favorite, remove_user_favorite, replace_user_location diff --git a/Backend/pet_func.py b/Backend/pet_func.py index b83d5bd..891fcf7 100644 --- a/Backend/pet_func.py +++ b/Backend/pet_func.py @@ -1,10 +1,11 @@ # Module pet_func.py -# This module handles pet-related functionalities. +# This module handles pet-related functionalities, providing details about random pets. from flask import jsonify def get_random_pet(): """Return a random pet's information.""" - randomint = "9" # API generates random integer that represents a PET ID - # Api accesses database and returns information in database - # Return information such as profile picture associated with the random ID - return jsonify({"id": randomint, "name": "Sam", "sex": "Male", "Age": "8", "location": "Connecticut", "Breed": "Pug"}) # Return dog information + randomint = "9" # API generates a random integer representing a PET ID + # API accesses database and returns information associated with the random ID + # Returns information such as profile picture of the pet + return jsonify({"id": randomint, "name": "Sam", "sex": "Male", "Age": "8", + "location": "Connecticut", "Breed": "Pug"}) # Return pet details diff --git a/Backend/test_main.py b/Backend/test_main.py index edef240..57d1d38 100644 --- a/Backend/test_main.py +++ b/Backend/test_main.py @@ -1,11 +1,11 @@ # Module test_main.py -# This module contains unit tests for the pet adoption web application. +# This module contains unit tests for the pet adoption web application, testing the functionality of various endpoints. import requests def test_get_random_pet(): """Test for http://localhost:5000/get_random_pet.""" url = "http://localhost:5000" - response = requests.get(f"{url}/get_random_pet") + response = requests.get(f"{url}/get_random_pet", timeout=10) expected_response = {"id": "9", "name": "Sam", "sex": "Male", "Age": "8", "location": "Connecticut", "Breed": "Pug"} assert response.json() == expected_response @@ -13,30 +13,24 @@ def test_add_user_favorite(): """Test for http://localhost:5000/add_user_favorite.""" url = "http://localhost:5000" favorite_pet1 = {"id": "9", "name": "Sam", "sex": "Male", "Age": "8", "location": "Connecticut", "Breed": "Pug"} - response = requests.post(f"{url}/add_user_favorite", json=favorite_pet1) + response = requests.post(f"{url}/add_user_favorite", json=favorite_pet1, timeout=10) assert response.json() == [favorite_pet1] favorite_pet2 = {"id": "90", "name": "Ben", "sex": "Male", "Age": "2", "location": "New York", "Breed": "Husky"} - response = requests.post(f"{url}/add_user_favorite", json=favorite_pet2) + response = requests.post(f"{url}/add_user_favorite", json=favorite_pet2, timeout=10) assert response.json() == [favorite_pet1, favorite_pet2] def test_remove_user_favorite(): """Test for http://localhost:5000/remove_user_favorite.""" url = "http://localhost:5000" favorite_pet1 = {"id": "9", "name": "Sam", "sex": "Male", "Age": "8", "location": "Connecticut", "Breed": "Pug"} - response = requests.delete(f"{url}/remove_user_favorite", json=favorite_pet1) + response = requests.delete(f"{url}/remove_user_favorite", json=favorite_pet1, timeout=10) assert response.json() == [] # Assuming the database is modified accordingly favorite_pet2 = {"id": "90", "name": "Ben", "sex": "Male", "Age": "2", "location": "New York", "Breed": "Husky"} - response = requests.delete(f"{url}/remove_user_favorite", json=favorite_pet2) + response = requests.delete(f"{url}/remove_user_favorite", json=favorite_pet2, timeout=10) assert response.json() == [] def test_change_user_location(): """Test for http://localhost:5000/change_user_location.""" url = "http://localhost:5000" - response = requests.put(f"{url}/change_user_location", json={"Location": "New York"}) + response = requests.put(f"{url}/change_user_location", json={"Location": "New York"}, timeout=10) assert response.json() == {"Location": "New York", "Name": "Eric", "Occupation": "Student", "Password": "2020"} - -test_get_random_pet() -test_add_user_favorite() -test_remove_user_favorite() -test_change_user_location() -print("Test check Complete: Passed") diff --git a/Backend/user_func.py b/Backend/user_func.py index f5f4a81..41db0a0 100644 --- a/Backend/user_func.py +++ b/Backend/user_func.py @@ -1,9 +1,9 @@ # Module user_func.py -# This module handles user-related functionalities such as managing favorite pets and user account information. +# This module handles user-related functionalities, including managing favorites and user information. from flask import jsonify user_favorite_database = [] # Simulate a database for user favorites -user_acc_info = {"Name": "Eric", "Password": "2020", "Location": "Connecticut", "Occupation": "Student"} # Example user account information +user_acc_info = {"Name": "Eric", "Password": "2020", "Location": "Connecticut", "Occupation": "Student"} def add_user_favorite(json_data): """Add user favorite pet to the database."""