-
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
IshayuR
committed
Oct 31, 2024
1 parent
97eeba9
commit 0c2e4ce
Showing
4 changed files
with
16 additions
and
22 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,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 |
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,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") |
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