diff --git a/Backend/main.py b/Backend/main.py deleted file mode 100644 index d9f1042..0000000 --- a/Backend/main.py +++ /dev/null @@ -1,106 +0,0 @@ -""" -This module provides functions for HTTP communication and route functions. -""" -from flask import Flask, request, jsonify -from flasgger import Swagger -from petfuc import get_random_pet -from userfuc import add_user_faviorte, remove_user_faviorte, replace_user_location - -app = Flask(__name__) -Swagger(app) # Initialize Swagger - -# Get Random Pet information - For homepage -@app.route("/Get_Random_pet", methods=["GET"]) -def random_pet(): - """ - Retrieve a random pet's information for the homepage. - --- - responses: - 200: - description: Returns random pet information successfully. - schema: - type: object - properties: - name: - type: string - example: 'Rex' - breed: - type: string - example: 'Dog' - age: - type: integer - example: 5 - """ - return get_random_pet(), 200 - -# Favorites route. Add user favorite pet to database -@app.route("/Add_User_Faviorte", methods=["POST"]) -def adduserfaviorte(): - """ - Add a pet to the user's favorites in the database. - --- - parameters: - - in: body - name: pet - required: true - schema: - type: object - properties: - pet_id: - type: integer - example: 101 - responses: - 200: - description: Pet added to favorites successfully. - """ - json_data = request.get_json() - return jsonify(add_user_faviorte(json_data)), 200 - -# Unfavorite Route. Remove user favorite pet from their database -@app.route("/Remove_User_Faviorte", methods=["DELETE"]) -def removeuserfaviorte(): - """ - Remove a pet from the user's favorites in the database. - --- - parameters: - - in: body - name: pet - required: true - schema: - type: object - properties: - pet_id: - type: integer - example: 101 - responses: - 200: - description: Pet removed from favorites successfully. - """ - json_data = request.get_json() - return jsonify(remove_user_faviorte(json_data)), 200 - -# Change a User's account location -@app.route("/Change_User_Location", methods=["PUT"]) -def replace_user_information(): - """ - Change the location associated with a user's account. - --- - parameters: - - in: body - name: location - required: true - schema: - type: object - properties: - new_location: - type: string - example: 'New York, NY' - responses: - 200: - description: User location updated successfully. - """ - newlocation = request.get_json() - return jsonify(replace_user_location(newlocation)), 200 - -if __name__ == "__main__": - app.run(host="0.0.0.0", port=5000, debug=True) diff --git a/Backend/petfuc.py b/Backend/petfuc.py deleted file mode 100644 index 121085f..0000000 --- a/Backend/petfuc.py +++ /dev/null @@ -1,35 +0,0 @@ -""" -This module provides backend functions to manage pet-related data. -""" -from flask import jsonify - -def get_random_pet(): - """ - Generates a random ID and returns information associated with that ID. - This function simulates accessing a database to fetch pet information - based on a randomly generated pet ID. - - Returns: - dict: A dictionary containing pet data, suitable for JSON response. - - Example return: - { - "id": "9", - "name": "Sam", - "sex": "Male", - "Age": "8", - "location": "Connecticut", - "Breed": "Pug" - } - """ - random_int = "9" # API generates random integer that represents a PET ID - data = { - "id": random_int, - "name": "Sam", - "sex": "Male", - "Age": "8", - "location": "Connecticut", - "Breed": "Pug" - } - return data # Return pet information as a dictionary - diff --git a/Backend/requirements.txt b/Backend/requirements.txt deleted file mode 100644 index 8bbecc4..0000000 --- a/Backend/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -Flask==3.0.3 -requests==2.32.3 \ No newline at end of file diff --git a/Backend/test_main.py b/Backend/test_main.py deleted file mode 100644 index 6ff3eea..0000000 --- a/Backend/test_main.py +++ /dev/null @@ -1,157 +0,0 @@ -""" -Pytest for fake API -""" - -import requests - -def test_get_random_pet(): - """ - Test for http://localhost:5000/Get_Random_pet - """ - - url = "http://localhost:5000" - - response = requests.get((url + "/Get_Random_pet"), timeout=10) - - expected_response = { - "id": "9", - "name": "sam", - "sex": "male", - "Age": "8", - "location": "Connecticwut", - "Breed": "Pug" - } - - assert response.json() == expected_response - -# ----------------------------------------------------------------------------- - -def test_add_user_faviorte(): - """ - Test for http://localhost:5000/Add_User_Faviorte - """ - - url = "http://localhost:5000" - - faviortepet1 = { - "id": "9", - "name": "sam", - "sex": "male", - "Age": "8", - "location": "Connecticut", - "Breed": "Pug" - } - - - response = requests.post((url + "/Add_User_Faviorte"), json=faviortepet1, timeout=10) - - assert response.json() == [{'Age': '8', - 'Breed': 'Pug', - 'id': '9', - 'location': - 'Connecticut', - 'name': 'sam', - 'sex': 'male'}] - - faviortepet2 = { - "id": "90", - "name": "ben", - "sex": "male", - "Age": "2", - "location": "New York", - "Breed": "Husky" - } - - response = requests.post((url + "/Add_User_Faviorte"), json=faviortepet2, timeout=10) - - assert response.json() == [{'Age': '8', - 'Breed': 'Pug', - 'id': '9', - 'location': 'Connecticut', - 'name': 'sam', - 'sex': 'male'}, - {'Age': '2', - 'Breed': 'Husky', - 'id': '90', - 'location': 'New York', - 'name': 'ben', - 'sex': 'male'}] - -# ---------------------------------------------------------------------------------- - -def test_remove_user_faviorte(): - """ - Test for http://localhost:5000/Remove_User_Faviorte - """ - - url = "http://localhost:5000" - - faviortepet1 = { - "id": "9", - "name": "sam", - "sex": "male", - "Age": "8", - "location": "Connecticut", - "Breed": "Pug" - } - - - response = requests.delete((url + "/Remove_User_Faviorte"), json=faviortepet1, timeout=10) - - assert response.json() == [{'Age': '2', - 'Breed': 'Husky', - 'id': '90', - 'location': 'New York', - 'name': 'ben', - 'sex': 'male'}] - - faviortepet2 = { - "id": "90", - "name": "ben", - "sex": "male", - "Age": "2", - "location": "New York", - "Breed": "Husky" - } - - response = requests.delete((url + "/Remove_User_Faviorte"), json=faviortepet2, 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((url + "/Change_User_Location"), - json={"Location":"New York"}, - timeout=10) - - assert response.json() == {"Location": "New York", - "Name": "eric", - "Occupation": "Student", - "Password": "2020"} - - - response = requests.put((url + "/Change_User_Location"), - json={"Location":"Chicago"}, - timeout=10) - - assert response.json() == {"Location": "Chicago", - "Name": "eric", - "Occupation": "Student", - "Password": "2020"} - - response = requests.put((url + "/Change_User_Location"), - json={"Location":"Massachusetts"}, - timeout=10) - - assert response.json() == {"Location": "Massachusetts", - "Name": "eric", - "Occupation": "Student", - "Password": "2020"} diff --git a/Backend/userfuc.py b/Backend/userfuc.py deleted file mode 100644 index ef15a7c..0000000 --- a/Backend/userfuc.py +++ /dev/null @@ -1,39 +0,0 @@ -""" -This module provides functions for HTTP communication and -route functions -""" -UserFaviorteDataBase = [] # pretend this is a database - -UserAccInfo = {"Name":"eric", - "Password":"2020", - "Location":"connecticut", - "Occupation":"Student"} # example user information - -# add user faviorte pet to database -def add_user_faviorte(jsondata): - """ - add user to database and return database elements - """ - UserFaviorteDataBase.append(jsondata) - # accesses database and append post json in database - return UserFaviorteDataBase # return new user database - - -# Remove user faviorte pet to database -def remove_user_faviorte(jsondata): - """ - remove user from database and return database elements - """ - UserFaviorteDataBase.remove(jsondata) - # accesses database and append post json in database - return UserFaviorteDataBase # return new user database - - -# Change a Users account location -def replace_user_location(newlocation): - """ - Replace location associated with a user account - """ - newlocation = newlocation.get('Location') - UserAccInfo["Location"] = newlocation # Set location accosiated with user to new location - return UserAccInfo # retrun user account info