Skip to content

Commit

Permalink
more pylint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
IshayuR committed Oct 31, 2024
1 parent 97eeba9 commit 0c2e4ce
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 22 deletions.
3 changes: 1 addition & 2 deletions Backend/main.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
11 changes: 6 additions & 5 deletions Backend/pet_func.py
Original file line number Diff line number Diff line change
@@ -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
20 changes: 7 additions & 13 deletions Backend/test_main.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,36 @@
# 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

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")
4 changes: 2 additions & 2 deletions Backend/user_func.py
Original file line number Diff line number Diff line change
@@ -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."""
Expand Down

0 comments on commit 0c2e4ce

Please sign in to comment.