From 06964c1bd3f8c5f1eab1dfa0a017903cc5a19766 Mon Sep 17 00:00:00 2001 From: Eric Asante Date: Wed, 30 Oct 2024 16:12:50 -0400 Subject: [PATCH 01/38] API STUB and TEST Complete --- Backend/PetFuc.py | 9 ++ Backend/UserFuc.py | 28 ++++ Backend/__pycache__/PetFuc.cpython-310.pyc | Bin 0 -> 468 bytes Backend/__pycache__/UserFuc.cpython-310.pyc | Bin 0 -> 804 bytes .../test_main.cpython-310-pytest-8.3.3.pyc | Bin 0 -> 2085 bytes Backend/main.py | 45 ++++++ Backend/test_main.py | 132 ++++++++++++++++++ 7 files changed, 214 insertions(+) create mode 100644 Backend/PetFuc.py create mode 100644 Backend/UserFuc.py create mode 100644 Backend/__pycache__/PetFuc.cpython-310.pyc create mode 100644 Backend/__pycache__/UserFuc.cpython-310.pyc create mode 100644 Backend/__pycache__/test_main.cpython-310-pytest-8.3.3.pyc create mode 100644 Backend/main.py create mode 100644 Backend/test_main.py diff --git a/Backend/PetFuc.py b/Backend/PetFuc.py new file mode 100644 index 0000000..bb0475a --- /dev/null +++ b/Backend/PetFuc.py @@ -0,0 +1,9 @@ +from flask import Flask, json, request, jsonify + + +def Get_Random_Pet(): + randomint = "9" # APi generates random interger that represents a PET ID + # Api accesses database and return information in data base + #Retrun information such as profile picture on the pet accosiated with the random ID + return jsonify({"id": randomint,"name":"sam","sex":"male","Age":"8", "location":"Connecticwut", "Breed": "Pug"}) # Return dog information + diff --git a/Backend/UserFuc.py b/Backend/UserFuc.py new file mode 100644 index 0000000..30dae00 --- /dev/null +++ b/Backend/UserFuc.py @@ -0,0 +1,28 @@ +from flask import Flask, request, json, jsonify + +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): + 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): + 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): + NewLocation = NewLocation.get('Location') + + UserAccInfo["Location"] = NewLocation # Set location accosiated with user to new location + return UserAccInfo # retrun user account info diff --git a/Backend/__pycache__/PetFuc.cpython-310.pyc b/Backend/__pycache__/PetFuc.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..67e63b8a4e8c0d9254cddac8fc0e272f6e17348b GIT binary patch literal 468 zcmYjNu}&N@5VhCdy9)xEBq&OWXts$16-ZGOIN&;T0;Smot?c2nu(rYWDj-1>J_A00 zpWs8LO~o%zWxNs+BhAyy`035__?499ZT$XP&U$(W@N?>qraT=Cr8M4P{hWfv`q)dw{dyuodca({ijbT=KZ1?VbL0t zuCYL5xJI$N0GxDQH>o8<I~B9@gRRnQ<*=R wLGm>bK2vc-Zp*WLt&r~>M25^5%ng*m(mVJ>uQ>T(z3DsnneR79eqqbvKZ$~LO8@`> literal 0 HcmV?d00001 diff --git a/Backend/__pycache__/UserFuc.cpython-310.pyc b/Backend/__pycache__/UserFuc.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4f147aa9c8ad1c8453254026b409d6f5e24c35d5 GIT binary patch literal 804 zcmZ`%OK;RL5VjNV#?3x>XbVM%3kRfJ$g<}O(FY4iXsNp5l1mlY-qp67IM`0BO6A6# zKfs|q?(g7V_{xbhH%`o?tW=O{$)CrW%s1bRNB4R$f%WX`)A{$1kRN!txms{}1>24R zB$0GU3YyU($burw!h&Utk~zs*GLWHUvL)N!Sk{)2OqoMBzU6x9?g{Ym6rmmK%bU?u- zd7(T%$gMroMtc5Ui`*@MCjKBqT{X6#nDFmH8!9Dxuz&Rd9J!%bex?5vZ62y>nG1C-Y5mt0kl8jsOnJbl zc>?AniG6E^^J4e&F zF3m%8?39j(rFCM{M(OMl+C=}ZIk9O=Iw$VLcxH$j5U-VFLijpZ9$FcJINH{P=%+m) zw0$<>D?P%55nt;lSTLeZJ1^}^#@MBE^g`(l2-r1QhaQcxHX+C4M?&XqV{E}~j~zM> z$ype!HM(#;flPFFbKc#Tve*oQB#)zHKNoWIRM?1i%K?lI-zD&zn* z%lU#cMqiOrb8E{dqwQVi`BMF~06M#@(%|<85Ck zk26u^nP6(3y(nNkjD}Me92ToM>Y=Qn+(fxO>O?{?F7>E*!>el(g1;xS;7eQ>NW15ypra$-e*E$a% za1PWuIL<)*6B-CAHD}=jG>J405Z(G^qa?KPvpF`US(+!-#K1aHng`YtTtK=8<6S*N z^QF5-0Ajmz0A{yz#lEyp9NH>ffVqu+4Rc4jCp8W8J&1cHqWKW4I$D5cN81Q9`T%DA zbO7o(jckoxpz~!-BkRcqM4P4e8rg*@vhZ{P+XcXOakTkgu)RxZi2D@YkDd*3E}0(0 zT}Tthq;V{B98<`#TC3(6nM282=x&3I7J@e>@`*m>zRTya+agK_WdUUlahKL2kd z7r#&-xwdm2fQ3ej{9^JA2#wx(f+aiNXYpZo8;VN8B-`xnAmP-XQ{J?;=ucEv!m1iA zR}}zi$1-Qn`9LyNKXc)KqV`n@(#dmn@jsK}-?iRxj(lM$ev1HI4E YoDLKAIf0 Date: Wed, 30 Oct 2024 16:15:24 -0400 Subject: [PATCH 02/38] API STUB and TEST Complete --- Frontend/index.html | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Frontend/index.html diff --git a/Frontend/index.html b/Frontend/index.html new file mode 100644 index 0000000..e69de29 From 7add32c8f4e0b61fd08ed27748400f76310ca585 Mon Sep 17 00:00:00 2001 From: Eric Asante Date: Thu, 31 Oct 2024 15:55:10 -0400 Subject: [PATCH 03/38] fix --- Backend/Dockerfile | 11 +++++++++++ Backend/main.py | 8 -------- Backend/requirements.txt | 2 ++ 3 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 Backend/Dockerfile create mode 100644 Backend/requirements.txt diff --git a/Backend/Dockerfile b/Backend/Dockerfile new file mode 100644 index 0000000..15c7bd8 --- /dev/null +++ b/Backend/Dockerfile @@ -0,0 +1,11 @@ +FROM python:3.9-slim +WORKDIR /Docker1 +COPY main.py main.py +COPY requirements.txt requirements.txt +COPY PetFuc.py PetFuc.py +COPY UserFuc.py UserFuc.py +COPY test_main.py test_main.py +RUN pip3 install -r requirements.txt +CMD [ "python3", "main.py" ] + + diff --git a/Backend/main.py b/Backend/main.py index bcb9f9f..9df3c8f 100644 --- a/Backend/main.py +++ b/Backend/main.py @@ -1,21 +1,14 @@ from flask import Flask, json, request, jsonify -import random from PetFuc import Get_Random_Pet from UserFuc import Add_User_Faviorte, Remove_User_Faviorte, Replace_User_Location - - app = Flask(__name__) - -UserAccInfo = {"Name":"eric","Location":"connecticut","Occupation":"Student"} # example user information - #Get Random Pet information - For homepage @app.route("/Get_Random_pet", methods=["GET"]) def get_random_pet(): return Get_Random_Pet(), 200 # Return dog information - # Faviortes route. add user faviorte pet to database @app.route("/Add_User_Faviorte", methods=["POST"]) def add_user_faviorte(): @@ -25,7 +18,6 @@ def add_user_faviorte(): #Retrun database with succses code return jsonify(Add_User_Faviorte(json_data)), 200 - # Un Faviote Route. remove user faviorte pet from there database @app.route("/Remove_User_Faviorte", methods=["DELETE"]) def remove_user_faviorte(): diff --git a/Backend/requirements.txt b/Backend/requirements.txt new file mode 100644 index 0000000..8bbecc4 --- /dev/null +++ b/Backend/requirements.txt @@ -0,0 +1,2 @@ +Flask==3.0.3 +requests==2.32.3 \ No newline at end of file From b14c59411f0959acc7d92bff520d6f6c7030bee2 Mon Sep 17 00:00:00 2001 From: Eric Asante Date: Thu, 31 Oct 2024 17:25:05 -0400 Subject: [PATCH 04/38] API complete --- .github/workflows/ms5.yaml | 64 +++++++++++++++ Backend/Docker | 11 +++ Backend/dockerfile | 30 +++++++ Backend/main.py | 8 ++ Backend/pet_func.py | 11 +++ Backend/test_main.py | 156 ++++++++----------------------------- Backend/user_func.py | 26 +++++++ Frontend/hi.txt | 1 + 8 files changed, 185 insertions(+), 122 deletions(-) create mode 100644 .github/workflows/ms5.yaml create mode 100644 Backend/Docker create mode 100644 Backend/dockerfile create mode 100644 Backend/pet_func.py create mode 100644 Backend/user_func.py create mode 100644 Frontend/hi.txt diff --git a/.github/workflows/ms5.yaml b/.github/workflows/ms5.yaml new file mode 100644 index 0000000..326c0ec --- /dev/null +++ b/.github/workflows/ms5.yaml @@ -0,0 +1,64 @@ +name: Pylint and API Testing + +on: + push: + branches: [Milestone-5_feature_branch] + +jobs: + test-and-lint: + runs-on: self-hosted # or ubuntu-latest + strategy: + matrix: + python-version: ["3.10"] + + steps: + #Checkout code + - uses: actions/checkout@v2 # Updated to correct version + + #Set up Python + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + #Install everything + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pylint flask flask_cors flasgger pytest + + #Run pylint on all Python files + - name: Analyze code with pylint, excluding main.py + run: | + pylint $(git ls-files '*.py') + + #Build Docker Image for API + - name: Build API Docker Image + run: | + docker build -t api-image -f Backend/dockerfile . + + + # Stop and Remove Existing Container (if any). this was the error + - name: Stop and Remove Existing API Container + run: | + docker stop api-container || true # Stop if running, ignore if not + sleep 10 + docker rm api-container || true # Remove if exists, ignore if not + sleep 1 + + #Start API Container + - name: Start API Container + run: | + docker run -d -p 5000:5000 --name api-container --memory=7g api-image # Start container on port 5000 + + #Run all Python tests in the directory + - name: Run the Python tests in directory + run: | + docker exec api-container python3 main.py # Execute main.py + #docker exec api-container pytest test_main.py # Execute test_main.py + + #Stop and Remove API Container after tests + - name: Stop and Remove API Container + run: | + docker stop api-container # Stop container after tests + docker rm api-container # Remove container after tests diff --git a/Backend/Docker b/Backend/Docker new file mode 100644 index 0000000..1021b0d --- /dev/null +++ b/Backend/Docker @@ -0,0 +1,11 @@ +FROM python:3.9-slim +WORKDIR /Docker1 +COPY main.py main.py +COPY PetFuc.py PetFuc.py +COPY UserFuc.py UserFuc.py +COPY test_main.py test_main.py +COPY requirements.txt requirements.txt +RUN pip3 install -r requirements.txt +CMD [ "python3", "main.py" ] + + diff --git a/Backend/dockerfile b/Backend/dockerfile new file mode 100644 index 0000000..fd397fc --- /dev/null +++ b/Backend/dockerfile @@ -0,0 +1,30 @@ +# Use Python as the base image +FROM python:3.8-slim-buster + +# Install pip and Python dependencies +RUN apt-get update && apt-get install -y python3 python3-pip + +# Keeps Python from generating .pyc files in the container +ENV PYTHONDONTWRITEBYTECODE=1 + +# Turns off buffering for easier container logging +ENV PYTHONUNBUFFERED=1 + + +# Set the working directory in the container +WORKDIR /app + + +# Install pip requirements +COPY Backend/requirements.txt . +RUN python3 -m pip install -r requirements.txt + +# Copy main application file +COPY Backend/main.py . + +# Set the port for the application +ENV PORT=5000 +EXPOSE 5000 + +# Command to run the application +CMD ["python3", "main.py"] diff --git a/Backend/main.py b/Backend/main.py index 9df3c8f..bcb9f9f 100644 --- a/Backend/main.py +++ b/Backend/main.py @@ -1,14 +1,21 @@ from flask import Flask, json, request, jsonify +import random from PetFuc import Get_Random_Pet from UserFuc import Add_User_Faviorte, Remove_User_Faviorte, Replace_User_Location + + app = Flask(__name__) + +UserAccInfo = {"Name":"eric","Location":"connecticut","Occupation":"Student"} # example user information + #Get Random Pet information - For homepage @app.route("/Get_Random_pet", methods=["GET"]) def get_random_pet(): return Get_Random_Pet(), 200 # Return dog information + # Faviortes route. add user faviorte pet to database @app.route("/Add_User_Faviorte", methods=["POST"]) def add_user_faviorte(): @@ -18,6 +25,7 @@ def add_user_faviorte(): #Retrun database with succses code return jsonify(Add_User_Faviorte(json_data)), 200 + # Un Faviote Route. remove user faviorte pet from there database @app.route("/Remove_User_Faviorte", methods=["DELETE"]) def remove_user_faviorte(): diff --git a/Backend/pet_func.py b/Backend/pet_func.py new file mode 100644 index 0000000..6638903 --- /dev/null +++ b/Backend/pet_func.py @@ -0,0 +1,11 @@ +""" This module handles pet-related functionalities, providing details about random pets. +It uses the Flask framework to return pet information in a JSON format. """ +from flask import jsonify + +def get_random_pet(): + """Return a random pet's 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 57becdf..ad27f16 100644 --- a/Backend/test_main.py +++ b/Backend/test_main.py @@ -1,132 +1,44 @@ +""" This module contains unit tests for the pet adoption web application, testing the functionality +of various endpoints. It uses the requests library to simulate HTTP requests. """ import requests -from flask import Flask, json, request, jsonify - -def test_Get_Random_pet(): - """ - Test for http://localhost:5000/Get_Random_pet - """ +def test_get_random_pet(): + """Test for http://localhost:5000/get_random_pet.""" url = "http://localhost:5000" - - response = requests.get(url + "/Get_Random_pet") - - expected_response = { - "id": "9", - "name": "sam", - "sex": "male", - "Age": "8", - "location": "Connecticwut", - "Breed": "Pug" - } - + 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_Faviorte(): - """ - Test for http://localhost:5000/Add_User_Faviorte - """ - +def test_add_user_favorite(): + """Test for http://localhost:5000/add_user_favorite.""" 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)) - - 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)) - - 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 - """ - + 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, 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, 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" - - FaviortePet1 = { - "id": "9", - "name": "sam", - "sex": "male", - "Age": "8", - "location": "Connecticut", - "Breed": "Pug" - } - - - response = requests.delete((url + "/Remove_User_Faviorte"), json=(FaviortePet1)) - - 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)) - + 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, timeout=10) + assert response.json() == [] + 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, timeout=10) assert response.json() == [] -# ---------------------------------------------------------------------------------- - - - -def test_Change_User_Location(): - """ - Test for http://localhost:5000/Change_User_Location - """ +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"}) - - assert response.json() == {"Location": "New York","Name": "eric","Occupation": "Student","Password": "2020"} - - - response = requests.put((url + "/Change_User_Location"), json={"Location":"Chicago"}) - - assert response.json() == {"Location": "Chicago","Name": "eric","Occupation": "Student","Password": "2020"} - - response = requests.put((url + "/Change_User_Location"), json={"Location":"Massachusetts"}) - - assert response.json() == {"Location": "Massachusetts","Name": "eric","Occupation": "Student","Password": "2020"} - - - - - - - - - -test_Get_Random_pet() -test_Add_User_Faviorte() -test_Remove_User_Faviorte() -test_Change_User_Location() -print("Test check Complete: Passed") + 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"} + \ No newline at end of file diff --git a/Backend/user_func.py b/Backend/user_func.py new file mode 100644 index 0000000..51ff4ad --- /dev/null +++ b/Backend/user_func.py @@ -0,0 +1,26 @@ +""" This module handles user-related functionalities such as +managing favorites and updating user information. """ + +user_favorite_database = [] # Simulate a database for user favorites +user_acc_info = { + "Name": "Eric", + "Password": "2020", + "Location": "Connecticut", + "Occupation": "Student" +} + +def add_user_favorite(json_data): + """Add user favorite pet to the database.""" + user_favorite_database.append(json_data) + return user_favorite_database # Return updated user favorites database + +def remove_user_favorite(json_data): + """Remove user favorite pet from the database.""" + user_favorite_database.remove(json_data) + return user_favorite_database # Return updated user favorites database + +def replace_user_location(new_location): + """Change the user account location.""" + new_location = new_location.get("Location") + user_acc_info["Location"] = new_location # Set new location associated with the user + return user_acc_info # Return updated user account information diff --git a/Frontend/hi.txt b/Frontend/hi.txt new file mode 100644 index 0000000..53a199a --- /dev/null +++ b/Frontend/hi.txt @@ -0,0 +1 @@ +I'm just testing the ci/cd :) \ No newline at end of file From 6de01dcb4c0afb56f98a6961d7ef521235872720 Mon Sep 17 00:00:00 2001 From: Eric Asante Date: Thu, 31 Oct 2024 17:39:21 -0400 Subject: [PATCH 05/38] API complete --- Backend/Dockerfile | 11 ----- Backend/__pycache__/PetFuc.cpython-310.pyc | Bin 468 -> 0 bytes Backend/__pycache__/UserFuc.cpython-310.pyc | Bin 804 -> 0 bytes .../test_main.cpython-310-pytest-8.3.3.pyc | Bin 2085 -> 0 bytes Backend/dockerfile | 30 ------------ Backend/pet_func.py | 11 ----- Backend/test_main.py | 44 ------------------ Backend/user_func.py | 26 ----------- 8 files changed, 122 deletions(-) delete mode 100644 Backend/Dockerfile delete mode 100644 Backend/__pycache__/PetFuc.cpython-310.pyc delete mode 100644 Backend/__pycache__/UserFuc.cpython-310.pyc delete mode 100644 Backend/__pycache__/test_main.cpython-310-pytest-8.3.3.pyc delete mode 100644 Backend/dockerfile delete mode 100644 Backend/pet_func.py delete mode 100644 Backend/test_main.py delete mode 100644 Backend/user_func.py diff --git a/Backend/Dockerfile b/Backend/Dockerfile deleted file mode 100644 index 15c7bd8..0000000 --- a/Backend/Dockerfile +++ /dev/null @@ -1,11 +0,0 @@ -FROM python:3.9-slim -WORKDIR /Docker1 -COPY main.py main.py -COPY requirements.txt requirements.txt -COPY PetFuc.py PetFuc.py -COPY UserFuc.py UserFuc.py -COPY test_main.py test_main.py -RUN pip3 install -r requirements.txt -CMD [ "python3", "main.py" ] - - diff --git a/Backend/__pycache__/PetFuc.cpython-310.pyc b/Backend/__pycache__/PetFuc.cpython-310.pyc deleted file mode 100644 index 67e63b8a4e8c0d9254cddac8fc0e272f6e17348b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 468 zcmYjNu}&N@5VhCdy9)xEBq&OWXts$16-ZGOIN&;T0;Smot?c2nu(rYWDj-1>J_A00 zpWs8LO~o%zWxNs+BhAyy`035__?499ZT$XP&U$(W@N?>qraT=Cr8M4P{hWfv`q)dw{dyuodca({ijbT=KZ1?VbL0t zuCYL5xJI$N0GxDQH>o8<I~B9@gRRnQ<*=R wLGm>bK2vc-Zp*WLt&r~>M25^5%ng*m(mVJ>uQ>T(z3DsnneR79eqqbvKZ$~LO8@`> diff --git a/Backend/__pycache__/UserFuc.cpython-310.pyc b/Backend/__pycache__/UserFuc.cpython-310.pyc deleted file mode 100644 index 4f147aa9c8ad1c8453254026b409d6f5e24c35d5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 804 zcmZ`%OK;RL5VjNV#?3x>XbVM%3kRfJ$g<}O(FY4iXsNp5l1mlY-qp67IM`0BO6A6# zKfs|q?(g7V_{xbhH%`o?tW=O{$)CrW%s1bRNB4R$f%WX`)A{$1kRN!txms{}1>24R zB$0GU3YyU($burw!h&Utk~zs*GLWHUvL)N!Sk{)2OqoMBzU6x9?g{Ym6rmmK%bU?u- zd7(T%$gMroMtc5Ui`*@MCjKBqT{X6#nDFmH8!9Dxuz&Rd9J!%bex?5vZ62y>nG1C-Y5mt0kl8jsOnJbl zc>?AniG6E^^J4e&F zF3m%8?39j(rFCM{M(OMl+C=}ZIk9O=Iw$VLcxH$j5U-VFLijpZ9$FcJINH{P=%+m) zw0$<>D?P%55nt;lSTLeZJ1^}^#@MBE^g`(l2-r1QhaQcxHX+C4M?&XqV{E}~j~zM> z$ype!HM(#;flPFFbKc#Tve*oQB#)zHKNoWIRM?1i%K?lI-zD&zn* z%lU#cMqiOrb8E{dqwQVi`BMF~06M#@(%|<85Ck zk26u^nP6(3y(nNkjD}Me92ToM>Y=Qn+(fxO>O?{?F7>E*!>el(g1;xS;7eQ>NW15ypra$-e*E$a% za1PWuIL<)*6B-CAHD}=jG>J405Z(G^qa?KPvpF`US(+!-#K1aHng`YtTtK=8<6S*N z^QF5-0Ajmz0A{yz#lEyp9NH>ffVqu+4Rc4jCp8W8J&1cHqWKW4I$D5cN81Q9`T%DA zbO7o(jckoxpz~!-BkRcqM4P4e8rg*@vhZ{P+XcXOakTkgu)RxZi2D@YkDd*3E}0(0 zT}Tthq;V{B98<`#TC3(6nM282=x&3I7J@e>@`*m>zRTya+agK_WdUUlahKL2kd z7r#&-xwdm2fQ3ej{9^JA2#wx(f+aiNXYpZo8;VN8B-`xnAmP-XQ{J?;=ucEv!m1iA zR}}zi$1-Qn`9LyNKXc)KqV`n@(#dmn@jsK}-?iRxj(lM$ev1HI4E YoDLKAIf0 Date: Thu, 31 Oct 2024 17:48:01 -0400 Subject: [PATCH 06/38] API complete --- Backend/main.py | 5 -- Backend/test_main.py | 132 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+), 5 deletions(-) create mode 100644 Backend/test_main.py diff --git a/Backend/main.py b/Backend/main.py index bcb9f9f..bb429fa 100644 --- a/Backend/main.py +++ b/Backend/main.py @@ -7,15 +7,11 @@ app = Flask(__name__) - -UserAccInfo = {"Name":"eric","Location":"connecticut","Occupation":"Student"} # example user information - #Get Random Pet information - For homepage @app.route("/Get_Random_pet", methods=["GET"]) def get_random_pet(): return Get_Random_Pet(), 200 # Return dog information - # Faviortes route. add user faviorte pet to database @app.route("/Add_User_Faviorte", methods=["POST"]) def add_user_faviorte(): @@ -25,7 +21,6 @@ def add_user_faviorte(): #Retrun database with succses code return jsonify(Add_User_Faviorte(json_data)), 200 - # Un Faviote Route. remove user faviorte pet from there database @app.route("/Remove_User_Faviorte", methods=["DELETE"]) def remove_user_faviorte(): diff --git a/Backend/test_main.py b/Backend/test_main.py new file mode 100644 index 0000000..57becdf --- /dev/null +++ b/Backend/test_main.py @@ -0,0 +1,132 @@ +import requests +from flask import Flask, json, request, jsonify + +def test_Get_Random_pet(): + """ + Test for http://localhost:5000/Get_Random_pet + """ + + url = "http://localhost:5000" + + response = requests.get(url + "/Get_Random_pet") + + 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)) + + 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)) + + 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)) + + 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)) + + 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"}) + + assert response.json() == {"Location": "New York","Name": "eric","Occupation": "Student","Password": "2020"} + + + response = requests.put((url + "/Change_User_Location"), json={"Location":"Chicago"}) + + assert response.json() == {"Location": "Chicago","Name": "eric","Occupation": "Student","Password": "2020"} + + response = requests.put((url + "/Change_User_Location"), json={"Location":"Massachusetts"}) + + assert response.json() == {"Location": "Massachusetts","Name": "eric","Occupation": "Student","Password": "2020"} + + + + + + + + + +test_Get_Random_pet() +test_Add_User_Faviorte() +test_Remove_User_Faviorte() +test_Change_User_Location() +print("Test check Complete: Passed") From bf23faaf9dd03331431265c0aec6ee82927d9f2c Mon Sep 17 00:00:00 2001 From: Eric O Asante Date: Thu, 31 Oct 2024 17:51:37 -0400 Subject: [PATCH 07/38] Update ms5.yaml eric --- .github/workflows/ms5.yaml | 87 +++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 49 deletions(-) diff --git a/.github/workflows/ms5.yaml b/.github/workflows/ms5.yaml index 326c0ec..a550af1 100644 --- a/.github/workflows/ms5.yaml +++ b/.github/workflows/ms5.yaml @@ -1,64 +1,53 @@ -name: Pylint and API Testing - -on: +name: API CI/CD +# This is a trigger for any push to the repo, and tells github when the actions have to be run +# Every time we do a push, the action will be executed +# The actions should be run only when there is a push from main and develop +on: push: - branches: [Milestone-5_feature_branch] + branches: + - MileStone5eric +#Tells github actions what to execute when trigger condition is met jobs: - test-and-lint: - runs-on: self-hosted # or ubuntu-latest + # Each job runs in parallel + tests: #This is the job name + + # runs-on indicates which GitHub "Runners" will run this CICD pipeline + # For all CSE-2102 repos, just use the following line as is + runs-on: self-hosted + # This next block allows you to run this ENTIRE job on different python versions strategy: matrix: - python-version: ["3.10"] + #python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] + python-version: ["3.8"] + # Steps are run in sequence in this job. If one step fails, the entire job fails. steps: - #Checkout code - - uses: actions/checkout@v2 # Updated to correct version - - #Set up Python + # Use this next line to pull your repo into the Docker container running the job + - uses: actions/checkout@v3 + # This block sets up the python version - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - - #Install everything - - name: Install dependencies + # Pylint is a static code analysis tool. Use this block as is to install pylint + # in the Docker container running the job + - name: Install pylint run: | python -m pip install --upgrade pip - pip install pylint flask flask_cors flasgger pytest - - #Run pylint on all Python files - - name: Analyze code with pylint, excluding main.py + pip install pylint + # Run pylint on your pulled code in the Docker container running the job + - name: Analysing the code with pylint run: | - pylint $(git ls-files '*.py') - - #Build Docker Image for API - - name: Build API Docker Image + pylint $(git ls-files 'hw002/*.py') + # Pytest is for unit testing your python code. Use this block as is to + # install pytest in the Docker container running the job + - name: Install pytest run: | - docker build -t api-image -f Backend/dockerfile . - - - # Stop and Remove Existing Container (if any). this was the error - - name: Stop and Remove Existing API Container - run: | - docker stop api-container || true # Stop if running, ignore if not - sleep 10 - docker rm api-container || true # Remove if exists, ignore if not - sleep 1 - - #Start API Container - - name: Start API Container - run: | - docker run -d -p 5000:5000 --name api-container --memory=7g api-image # Start container on port 5000 - - #Run all Python tests in the directory - - name: Run the Python tests in directory - run: | - docker exec api-container python3 main.py # Execute main.py - #docker exec api-container pytest test_main.py # Execute test_main.py - - #Stop and Remove API Container after tests - - name: Stop and Remove API Container + python -m pip install --upgrade pip + pip install pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + # Run pytest on your pulled codebase + - name: Test with pytest run: | - docker stop api-container # Stop container after tests - docker rm api-container # Remove container after tests + pytest From 790c0d93c00a9f715d267b60b63d48ad8dc7da1b Mon Sep 17 00:00:00 2001 From: Eric O Asante Date: Thu, 31 Oct 2024 17:52:59 -0400 Subject: [PATCH 08/38] Update ms5.yaml --- .github/workflows/ms5.yaml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ms5.yaml b/.github/workflows/ms5.yaml index a550af1..aa4840c 100644 --- a/.github/workflows/ms5.yaml +++ b/.github/workflows/ms5.yaml @@ -36,10 +36,8 @@ jobs: run: | python -m pip install --upgrade pip pip install pylint - # Run pylint on your pulled code in the Docker container running the job - - name: Analysing the code with pylint - run: | - pylint $(git ls-files 'hw002/*.py') + + # Pytest is for unit testing your python code. Use this block as is to # install pytest in the Docker container running the job - name: Install pytest From a7576bff7f10d5cc3c396b98f7451dae62ba099c Mon Sep 17 00:00:00 2001 From: Eric O Asante Date: Thu, 31 Oct 2024 18:00:42 -0400 Subject: [PATCH 09/38] Update ms5.yaml --- .github/workflows/ms5.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ms5.yaml b/.github/workflows/ms5.yaml index aa4840c..b6ba8f7 100644 --- a/.github/workflows/ms5.yaml +++ b/.github/workflows/ms5.yaml @@ -36,7 +36,7 @@ jobs: run: | python -m pip install --upgrade pip pip install pylint - + # Pytest is for unit testing your python code. Use this block as is to # install pytest in the Docker container running the job @@ -45,6 +45,12 @@ jobs: python -m pip install --upgrade pip pip install pytest if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + + - name: Build and Run Docker + run: | + docker build -f dockerfile -t doc . + docker run -d -p 5000:5000 doc + # Run pytest on your pulled codebase - name: Test with pytest run: | From 81ff191e052379fd00ac8eb55e35054bfd0be217 Mon Sep 17 00:00:00 2001 From: Eric O Asante Date: Thu, 31 Oct 2024 18:03:00 -0400 Subject: [PATCH 10/38] Update ms5.yaml --- .github/workflows/ms5.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ms5.yaml b/.github/workflows/ms5.yaml index b6ba8f7..b915b02 100644 --- a/.github/workflows/ms5.yaml +++ b/.github/workflows/ms5.yaml @@ -48,7 +48,7 @@ jobs: - name: Build and Run Docker run: | - docker build -f dockerfile -t doc . + docker build -f Backend/Docker -t doc . docker run -d -p 5000:5000 doc # Run pytest on your pulled codebase From 4531d69dbd671adefb9897f9b8b403336b1294b0 Mon Sep 17 00:00:00 2001 From: Eric O Asante Date: Thu, 31 Oct 2024 18:08:45 -0400 Subject: [PATCH 11/38] Update Docker From a0269728cf8e2a1c8edb8194c0484662ff91bec3 Mon Sep 17 00:00:00 2001 From: Eric O Asante Date: Thu, 31 Oct 2024 18:13:17 -0400 Subject: [PATCH 12/38] Update ms5.yaml --- .github/workflows/ms5.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ms5.yaml b/.github/workflows/ms5.yaml index b915b02..52e6d67 100644 --- a/.github/workflows/ms5.yaml +++ b/.github/workflows/ms5.yaml @@ -48,7 +48,7 @@ jobs: - name: Build and Run Docker run: | - docker build -f Backend/Docker -t doc . + docker build -f Backend/Docker -t doc cse2102-fall24-Team51/Backend/ docker run -d -p 5000:5000 doc # Run pytest on your pulled codebase From 0a6302ad089cc067247b86f44863e9b419c53a34 Mon Sep 17 00:00:00 2001 From: Eric O Asante Date: Thu, 31 Oct 2024 18:14:07 -0400 Subject: [PATCH 13/38] Update ms5.yaml --- .github/workflows/ms5.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ms5.yaml b/.github/workflows/ms5.yaml index 52e6d67..4f77eda 100644 --- a/.github/workflows/ms5.yaml +++ b/.github/workflows/ms5.yaml @@ -48,7 +48,7 @@ jobs: - name: Build and Run Docker run: | - docker build -f Backend/Docker -t doc cse2102-fall24-Team51/Backend/ + docker build -f Backend/Docker -t doc Backend/ docker run -d -p 5000:5000 doc # Run pytest on your pulled codebase From 8ab60fb513458f57a75dca43e0a962c93c28f4e8 Mon Sep 17 00:00:00 2001 From: Eric O Asante Date: Thu, 31 Oct 2024 18:17:15 -0400 Subject: [PATCH 14/38] Update ms5.yaml --- .github/workflows/ms5.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ms5.yaml b/.github/workflows/ms5.yaml index 4f77eda..f254fc0 100644 --- a/.github/workflows/ms5.yaml +++ b/.github/workflows/ms5.yaml @@ -46,9 +46,12 @@ jobs: pip install pytest if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - name: Build and Run Docker + - name: Build Docker run: | docker build -f Backend/Docker -t doc Backend/ + + - name: Run Docker + run: | docker run -d -p 5000:5000 doc # Run pytest on your pulled codebase From 9c2a83331eee8e1135e5ed6d3514ad6cdd14d3a3 Mon Sep 17 00:00:00 2001 From: Eric O Asante Date: Thu, 31 Oct 2024 18:19:43 -0400 Subject: [PATCH 15/38] Update ms5.yaml --- .github/workflows/ms5.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/ms5.yaml b/.github/workflows/ms5.yaml index f254fc0..4ac0781 100644 --- a/.github/workflows/ms5.yaml +++ b/.github/workflows/ms5.yaml @@ -46,6 +46,14 @@ jobs: pip install pytest if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Stop Docker + run: | + docker stop $(docker ps -q) + + - name: Remove Docker + run: | + docker rm $(docker ps -a -q) + - name: Build Docker run: | docker build -f Backend/Docker -t doc Backend/ From b6b002eb9eb6e793056c8a3a07b3f62adfb7677c Mon Sep 17 00:00:00 2001 From: Eric O Asante Date: Thu, 31 Oct 2024 18:34:55 -0400 Subject: [PATCH 16/38] Update ms5.yaml --- .github/workflows/ms5.yaml | 39 ++++++++------------------------------ 1 file changed, 8 insertions(+), 31 deletions(-) diff --git a/.github/workflows/ms5.yaml b/.github/workflows/ms5.yaml index 4ac0781..9391f05 100644 --- a/.github/workflows/ms5.yaml +++ b/.github/workflows/ms5.yaml @@ -1,16 +1,14 @@ -name: API CI/CD -# This is a trigger for any push to the repo, and tells github when the actions have to be run -# Every time we do a push, the action will be executed -# The actions should be run only when there is a push from main and develop -on: +name: API CI/CD + +# This is a trigger for any push to the repo +on: push: branches: - MileStone5eric -#Tells github actions what to execute when trigger condition is met jobs: # Each job runs in parallel - tests: #This is the job name + name_your_job_whatever_you_want: # runs-on indicates which GitHub "Runners" will run this CICD pipeline # For all CSE-2102 repos, just use the following line as is @@ -32,36 +30,15 @@ jobs: python-version: ${{ matrix.python-version }} # Pylint is a static code analysis tool. Use this block as is to install pylint # in the Docker container running the job - - name: Install pylint - run: | - python -m pip install --upgrade pip - pip install pylint - - + + # Pytest is for unit testing your python code. Use this block as is to # install pytest in the Docker container running the job - name: Install pytest run: | python -m pip install --upgrade pip pip install pytest - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - - name: Stop Docker - run: | - docker stop $(docker ps -q) - - - name: Remove Docker - run: | - docker rm $(docker ps -a -q) - - - name: Build Docker - run: | - docker build -f Backend/Docker -t doc Backend/ - - - name: Run Docker - run: | - docker run -d -p 5000:5000 doc - + if [ -f ./Backend/requirements.txt ]; then pip install -r ./Backend/requirements.txt; fi # Run pytest on your pulled codebase - name: Test with pytest run: | From 6e834250f679f35d915ffb3cf2b9b635e401a969 Mon Sep 17 00:00:00 2001 From: Eric O Asante Date: Thu, 31 Oct 2024 18:41:38 -0400 Subject: [PATCH 17/38] Update ms5.yaml --- .github/workflows/ms5.yaml | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ms5.yaml b/.github/workflows/ms5.yaml index 9391f05..9c31d29 100644 --- a/.github/workflows/ms5.yaml +++ b/.github/workflows/ms5.yaml @@ -1,22 +1,21 @@ -name: API CI/CD - -# This is a trigger for any push to the repo -on: +name: API CI/CD +# This is a trigger for any push to the repo, and tells github when the actions have to be run +# Every time we do a push, the action will be executed +# The actions should be run only when there is a push from main and develop +on: push: branches: - MileStone5eric +#Tells github actions what to execute when trigger condition is met jobs: - # Each job runs in parallel - name_your_job_whatever_you_want: - # runs-on indicates which GitHub "Runners" will run this CICD pipeline - # For all CSE-2102 repos, just use the following line as is + tests: #This is the job name runs-on: self-hosted - # This next block allows you to run this ENTIRE job on different python versions + strategy: matrix: - #python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] + python-version: ["3.8"] # Steps are run in sequence in this job. If one step fails, the entire job fails. @@ -30,15 +29,21 @@ jobs: python-version: ${{ matrix.python-version }} # Pylint is a static code analysis tool. Use this block as is to install pylint # in the Docker container running the job - - + - name: Install pylint + run: | + python -m pip install --upgrade pip + pip install pylint + + # Pytest is for unit testing your python code. Use this block as is to # install pytest in the Docker container running the job - name: Install pytest run: | python -m pip install --upgrade pip pip install pytest - if [ -f ./Backend/requirements.txt ]; then pip install -r ./Backend/requirements.txt; fi + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + + # Run pytest on your pulled codebase - name: Test with pytest run: | From 91f79c959ac30b42cdf44ee99f06dec9b5c799cf Mon Sep 17 00:00:00 2001 From: Eric O Asante Date: Thu, 31 Oct 2024 18:45:45 -0400 Subject: [PATCH 18/38] Update ms5.yaml --- .github/workflows/ms5.yaml | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ms5.yaml b/.github/workflows/ms5.yaml index 9c31d29..bcf6bb3 100644 --- a/.github/workflows/ms5.yaml +++ b/.github/workflows/ms5.yaml @@ -1,21 +1,22 @@ -name: API CI/CD -# This is a trigger for any push to the repo, and tells github when the actions have to be run -# Every time we do a push, the action will be executed -# The actions should be run only when there is a push from main and develop -on: +name: CI Pipeline + +# This is a trigger for any push to the repo +on: push: branches: - MileStone5eric -#Tells github actions what to execute when trigger condition is met jobs: + # Each job runs in parallel + name_your_job_whatever_you_want: - tests: #This is the job name + # runs-on indicates which GitHub "Runners" will run this CICD pipeline + # For all CSE-2102 repos, just use the following line as is runs-on: self-hosted - + # This next block allows you to run this ENTIRE job on different python versions strategy: matrix: - + #python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] python-version: ["3.8"] # Steps are run in sequence in this job. If one step fails, the entire job fails. @@ -33,17 +34,17 @@ jobs: run: | python -m pip install --upgrade pip pip install pylint - - + # Run pylint on your pulled code in the Docker container running the job + - name: Analysing the code with pylint + run: | + pylint $(git ls-files './backend/*.py') # Pytest is for unit testing your python code. Use this block as is to # install pytest in the Docker container running the job - name: Install pytest run: | python -m pip install --upgrade pip pip install pytest - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - + # Run pytest on your pulled codebase - name: Test with pytest run: | From 352af6fbb5e5917848965bbb0491f9ffc97a4f5c Mon Sep 17 00:00:00 2001 From: Eric O Asante Date: Thu, 31 Oct 2024 18:50:51 -0400 Subject: [PATCH 19/38] Update ms5.yaml --- .github/workflows/ms5.yaml | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ms5.yaml b/.github/workflows/ms5.yaml index bcf6bb3..1e43ac4 100644 --- a/.github/workflows/ms5.yaml +++ b/.github/workflows/ms5.yaml @@ -1,14 +1,16 @@ -name: CI Pipeline - -# This is a trigger for any push to the repo -on: +name: API CI/CD +# This is a trigger for any push to the repo, and tells github when the actions have to be run +# Every time we do a push, the action will be executed +# The actions should be run only when there is a push from main and develop +on: push: branches: - MileStone5eric +#Tells github actions what to execute when trigger condition is met jobs: # Each job runs in parallel - name_your_job_whatever_you_want: + tests: #This is the job name # runs-on indicates which GitHub "Runners" will run this CICD pipeline # For all CSE-2102 repos, just use the following line as is @@ -34,18 +36,20 @@ jobs: run: | python -m pip install --upgrade pip pip install pylint - # Run pylint on your pulled code in the Docker container running the job - - name: Analysing the code with pylint - run: | - pylint $(git ls-files './backend/*.py') + + # Pytest is for unit testing your python code. Use this block as is to # install pytest in the Docker container running the job - name: Install pytest run: | python -m pip install --upgrade pip pip install pytest - + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Run main.py + run: | + python3 Backend/main.py + # Run pytest on your pulled codebase - name: Test with pytest run: | - pytest + Backend/ pytest From 2daea5ff433690a5d3992f4e9fea78f480346d72 Mon Sep 17 00:00:00 2001 From: Eric O Asante Date: Thu, 31 Oct 2024 18:53:01 -0400 Subject: [PATCH 20/38] Update ms5.yaml --- .github/workflows/ms5.yaml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ms5.yaml b/.github/workflows/ms5.yaml index 1e43ac4..b458826 100644 --- a/.github/workflows/ms5.yaml +++ b/.github/workflows/ms5.yaml @@ -45,11 +45,9 @@ jobs: python -m pip install --upgrade pip pip install pytest if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - name: Run main.py - run: | - python3 Backend/main.py + # Run pytest on your pulled codebase - name: Test with pytest run: | - Backend/ pytest + pytest From 7e869ac385254c78eee8637ec7a039368addb8b9 Mon Sep 17 00:00:00 2001 From: Eric O Asante Date: Sat, 2 Nov 2024 06:16:26 -0400 Subject: [PATCH 21/38] Update ms5.yaml --- .github/workflows/ms5.yaml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/ms5.yaml b/.github/workflows/ms5.yaml index b458826..ad2e623 100644 --- a/.github/workflows/ms5.yaml +++ b/.github/workflows/ms5.yaml @@ -46,8 +46,4 @@ jobs: pip install pytest if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - # Run pytest on your pulled codebase - - name: Test with pytest - run: | - pytest + From 5975b638c52b7067e746432a260118fa212b01c5 Mon Sep 17 00:00:00 2001 From: Eric O Asante Date: Sat, 2 Nov 2024 06:20:43 -0400 Subject: [PATCH 22/38] n.yaml --- .github/workflows/ms5.yaml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ms5.yaml b/.github/workflows/ms5.yaml index ad2e623..b915b02 100644 --- a/.github/workflows/ms5.yaml +++ b/.github/workflows/ms5.yaml @@ -46,4 +46,12 @@ jobs: pip install pytest if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - + - name: Build and Run Docker + run: | + docker build -f Backend/Docker -t doc . + docker run -d -p 5000:5000 doc + + # Run pytest on your pulled codebase + - name: Test with pytest + run: | + pytest From c820265aecef9adfdf22040e810eb59bc9bd9696 Mon Sep 17 00:00:00 2001 From: Eric O Asante Date: Sat, 2 Nov 2024 06:24:25 -0400 Subject: [PATCH 23/38] nn.yaml --- .github/workflows/ms5.yaml | 56 ++++---------------------------------- 1 file changed, 6 insertions(+), 50 deletions(-) diff --git a/.github/workflows/ms5.yaml b/.github/workflows/ms5.yaml index b915b02..e4fc9d7 100644 --- a/.github/workflows/ms5.yaml +++ b/.github/workflows/ms5.yaml @@ -1,57 +1,13 @@ -name: API CI/CD -# This is a trigger for any push to the repo, and tells github when the actions have to be run -# Every time we do a push, the action will be executed -# The actions should be run only when there is a push from main and develop +name: Simple CI/CD Pipeline + on: push: branches: - MileStone5eric -#Tells github actions what to execute when trigger condition is met jobs: - # Each job runs in parallel - tests: #This is the job name - - # runs-on indicates which GitHub "Runners" will run this CICD pipeline - # For all CSE-2102 repos, just use the following line as is - runs-on: self-hosted - # This next block allows you to run this ENTIRE job on different python versions - strategy: - matrix: - #python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] - python-version: ["3.8"] - - # Steps are run in sequence in this job. If one step fails, the entire job fails. + do-nothing: + runs-on: ubuntu-latest steps: - # Use this next line to pull your repo into the Docker container running the job - - uses: actions/checkout@v3 - # This block sets up the python version - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - # Pylint is a static code analysis tool. Use this block as is to install pylint - # in the Docker container running the job - - name: Install pylint - run: | - python -m pip install --upgrade pip - pip install pylint - - - # Pytest is for unit testing your python code. Use this block as is to - # install pytest in the Docker container running the job - - name: Install pytest - run: | - python -m pip install --upgrade pip - pip install pytest - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - - name: Build and Run Docker - run: | - docker build -f Backend/Docker -t doc . - docker run -d -p 5000:5000 doc - - # Run pytest on your pulled codebase - - name: Test with pytest - run: | - pytest + - name: Do nothing + run: echo "This is a simple CI/CD pipeline that does nothing." From 3ceb7ee1ebdbb5b2444917a5448befdf65ed9326 Mon Sep 17 00:00:00 2001 From: Eric O Asante Date: Sat, 2 Nov 2024 06:27:03 -0400 Subject: [PATCH 24/38] Update ms5.yaml --- .github/workflows/ms5.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ms5.yaml b/.github/workflows/ms5.yaml index e4fc9d7..e12bbae 100644 --- a/.github/workflows/ms5.yaml +++ b/.github/workflows/ms5.yaml @@ -7,7 +7,7 @@ on: jobs: do-nothing: - runs-on: ubuntu-latest + runs-on: self-hosted steps: - name: Do nothing run: echo "This is a simple CI/CD pipeline that does nothing." From 312a94d3d18e856f6e12a3424eb10e619c2e0860 Mon Sep 17 00:00:00 2001 From: Eric O Asante Date: Sat, 2 Nov 2024 18:25:34 -0400 Subject: [PATCH 25/38] Update ms5.yaml --- .github/workflows/ms5.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ms5.yaml b/.github/workflows/ms5.yaml index e12bbae..3fb8f72 100644 --- a/.github/workflows/ms5.yaml +++ b/.github/workflows/ms5.yaml @@ -10,4 +10,4 @@ jobs: runs-on: self-hosted steps: - name: Do nothing - run: echo "This is a simple CI/CD pipeline that does nothing." + run: echo "This is a simple CI/CDk pipeline that does nothing." From 0c7a00a3380b781db408f934d79c92a7273faf8a Mon Sep 17 00:00:00 2001 From: Eric O Asante Date: Sat, 2 Nov 2024 18:26:43 -0400 Subject: [PATCH 26/38] Update ms5.yaml --- .github/workflows/ms5.yaml | 50 ++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ms5.yaml b/.github/workflows/ms5.yaml index 3fb8f72..a550af1 100644 --- a/.github/workflows/ms5.yaml +++ b/.github/workflows/ms5.yaml @@ -1,13 +1,53 @@ -name: Simple CI/CD Pipeline - +name: API CI/CD +# This is a trigger for any push to the repo, and tells github when the actions have to be run +# Every time we do a push, the action will be executed +# The actions should be run only when there is a push from main and develop on: push: branches: - MileStone5eric +#Tells github actions what to execute when trigger condition is met jobs: - do-nothing: + # Each job runs in parallel + tests: #This is the job name + + # runs-on indicates which GitHub "Runners" will run this CICD pipeline + # For all CSE-2102 repos, just use the following line as is runs-on: self-hosted + # This next block allows you to run this ENTIRE job on different python versions + strategy: + matrix: + #python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] + python-version: ["3.8"] + + # Steps are run in sequence in this job. If one step fails, the entire job fails. steps: - - name: Do nothing - run: echo "This is a simple CI/CDk pipeline that does nothing." + # Use this next line to pull your repo into the Docker container running the job + - uses: actions/checkout@v3 + # This block sets up the python version + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + # Pylint is a static code analysis tool. Use this block as is to install pylint + # in the Docker container running the job + - name: Install pylint + run: | + python -m pip install --upgrade pip + pip install pylint + # Run pylint on your pulled code in the Docker container running the job + - name: Analysing the code with pylint + run: | + pylint $(git ls-files 'hw002/*.py') + # Pytest is for unit testing your python code. Use this block as is to + # install pytest in the Docker container running the job + - name: Install pytest + run: | + python -m pip install --upgrade pip + pip install pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + # Run pytest on your pulled codebase + - name: Test with pytest + run: | + pytest From 38c7d37e02a9ca7e54beff6b9be906bdd9e7365b Mon Sep 17 00:00:00 2001 From: Eric O Asante Date: Mon, 4 Nov 2024 10:30:19 -0500 Subject: [PATCH 27/38] Update ms5.yaml --- .github/workflows/ms5.yaml | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/.github/workflows/ms5.yaml b/.github/workflows/ms5.yaml index a550af1..ce7aabd 100644 --- a/.github/workflows/ms5.yaml +++ b/.github/workflows/ms5.yaml @@ -36,18 +36,3 @@ jobs: run: | python -m pip install --upgrade pip pip install pylint - # Run pylint on your pulled code in the Docker container running the job - - name: Analysing the code with pylint - run: | - pylint $(git ls-files 'hw002/*.py') - # Pytest is for unit testing your python code. Use this block as is to - # install pytest in the Docker container running the job - - name: Install pytest - run: | - python -m pip install --upgrade pip - pip install pytest - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - # Run pytest on your pulled codebase - - name: Test with pytest - run: | - pytest From 8c651c7af3a27e6f296ed452bf393278cfa69043 Mon Sep 17 00:00:00 2001 From: Eric O Asante Date: Mon, 4 Nov 2024 10:32:38 -0500 Subject: [PATCH 28/38] Update ms5.yaml --- .github/workflows/ms5.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ms5.yaml b/.github/workflows/ms5.yaml index ce7aabd..658f6e4 100644 --- a/.github/workflows/ms5.yaml +++ b/.github/workflows/ms5.yaml @@ -36,3 +36,7 @@ jobs: run: | python -m pip install --upgrade pip pip install pylint + + - name: RUN Api + run: | + python3 Backend/main.py From 0005c6f8b0f18b458554f8544afadd646109000a Mon Sep 17 00:00:00 2001 From: Eric O Asante Date: Mon, 4 Nov 2024 10:38:36 -0500 Subject: [PATCH 29/38] Update ms5.yaml --- .github/workflows/ms5.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ms5.yaml b/.github/workflows/ms5.yaml index 658f6e4..2e53981 100644 --- a/.github/workflows/ms5.yaml +++ b/.github/workflows/ms5.yaml @@ -37,6 +37,8 @@ jobs: python -m pip install --upgrade pip pip install pylint - - name: RUN Api + - name: Install pytest run: | - python3 Backend/main.py + python -m pip install --upgrade pip + pip install pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi From fda943e158d21f787865fcf37e9e5f9d90b6959c Mon Sep 17 00:00:00 2001 From: Eric O Asante Date: Mon, 4 Nov 2024 11:26:03 -0500 Subject: [PATCH 30/38] Update ms5.yaml --- .github/workflows/ms5.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/ms5.yaml b/.github/workflows/ms5.yaml index 2e53981..9458f15 100644 --- a/.github/workflows/ms5.yaml +++ b/.github/workflows/ms5.yaml @@ -42,3 +42,13 @@ jobs: python -m pip install --upgrade pip pip install pytest if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + + - name: Run Api + run: | + python3 main.py + + + - name: pytest + run: | + pytest + From a1e1b51a5c2398bc28e3a00577c7116a3e1c6d09 Mon Sep 17 00:00:00 2001 From: Eric O Asante Date: Mon, 4 Nov 2024 11:27:38 -0500 Subject: [PATCH 31/38] Update ms5.yaml --- .github/workflows/ms5.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ms5.yaml b/.github/workflows/ms5.yaml index 9458f15..7f610f1 100644 --- a/.github/workflows/ms5.yaml +++ b/.github/workflows/ms5.yaml @@ -45,7 +45,7 @@ jobs: - name: Run Api run: | - python3 main.py + python3 Backend/main.py - name: pytest From b6942feae8058c86fe034782d66ea3b73a0f277d Mon Sep 17 00:00:00 2001 From: Eric O Asante Date: Mon, 4 Nov 2024 11:31:40 -0500 Subject: [PATCH 32/38] Update ms5.yaml --- .github/workflows/ms5.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ms5.yaml b/.github/workflows/ms5.yaml index 7f610f1..17c8e23 100644 --- a/.github/workflows/ms5.yaml +++ b/.github/workflows/ms5.yaml @@ -45,7 +45,7 @@ jobs: - name: Run Api run: | - python3 Backend/main.py + python3 Backend/main.py & - name: pytest From 73a2381727e2010be5bacf7d2809bbb7b0744761 Mon Sep 17 00:00:00 2001 From: Eric Asante Date: Mon, 4 Nov 2024 14:11:37 -0500 Subject: [PATCH 33/38] pylint complete --- Backend/PetFuc.py | 9 --- Backend/UserFuc.py | 28 --------- Backend/main.py | 40 ------------- Backend/test_main.py | 132 ------------------------------------------- 4 files changed, 209 deletions(-) delete mode 100644 Backend/PetFuc.py delete mode 100644 Backend/UserFuc.py delete mode 100644 Backend/main.py delete mode 100644 Backend/test_main.py diff --git a/Backend/PetFuc.py b/Backend/PetFuc.py deleted file mode 100644 index bb0475a..0000000 --- a/Backend/PetFuc.py +++ /dev/null @@ -1,9 +0,0 @@ -from flask import Flask, json, request, jsonify - - -def Get_Random_Pet(): - randomint = "9" # APi generates random interger that represents a PET ID - # Api accesses database and return information in data base - #Retrun information such as profile picture on the pet accosiated with the random ID - return jsonify({"id": randomint,"name":"sam","sex":"male","Age":"8", "location":"Connecticwut", "Breed": "Pug"}) # Return dog information - diff --git a/Backend/UserFuc.py b/Backend/UserFuc.py deleted file mode 100644 index 30dae00..0000000 --- a/Backend/UserFuc.py +++ /dev/null @@ -1,28 +0,0 @@ -from flask import Flask, request, json, jsonify - -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): - 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): - 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): - NewLocation = NewLocation.get('Location') - - UserAccInfo["Location"] = NewLocation # Set location accosiated with user to new location - return UserAccInfo # retrun user account info diff --git a/Backend/main.py b/Backend/main.py deleted file mode 100644 index bb429fa..0000000 --- a/Backend/main.py +++ /dev/null @@ -1,40 +0,0 @@ -from flask import Flask, json, request, jsonify -import random -from PetFuc import Get_Random_Pet -from UserFuc import Add_User_Faviorte, Remove_User_Faviorte, Replace_User_Location - - - -app = Flask(__name__) - -#Get Random Pet information - For homepage -@app.route("/Get_Random_pet", methods=["GET"]) -def get_random_pet(): - return Get_Random_Pet(), 200 # Return dog information - -# Faviortes route. add user faviorte pet to database -@app.route("/Add_User_Faviorte", methods=["POST"]) -def add_user_faviorte(): - json_data = request.get_json() - - # Api accesses database and append post json in database - #Retrun database with succses code - return jsonify(Add_User_Faviorte(json_data)), 200 - -# Un Faviote Route. remove user faviorte pet from there database -@app.route("/Remove_User_Faviorte", methods=["DELETE"]) -def remove_user_faviorte(): - json_data = request.get_json() - - # Api accesses database and append post json in database - #Retrun database with succses code - return jsonify(Remove_User_Faviorte(json_data)), 200 # return new user database - -# Change a Users account location -@app.route("/Change_User_Location", methods=["PUT"]) -def replace_user_information(): - NewLocation = request.get_json() # Get new location from post request - return jsonify(Replace_User_Location(NewLocation)) # retrun user account info - -if __name__ == "__main__": - app.run(host="0.0.0.0", port=5000, debug=True) diff --git a/Backend/test_main.py b/Backend/test_main.py deleted file mode 100644 index 57becdf..0000000 --- a/Backend/test_main.py +++ /dev/null @@ -1,132 +0,0 @@ -import requests -from flask import Flask, json, request, jsonify - -def test_Get_Random_pet(): - """ - Test for http://localhost:5000/Get_Random_pet - """ - - url = "http://localhost:5000" - - response = requests.get(url + "/Get_Random_pet") - - 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)) - - 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)) - - 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)) - - 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)) - - 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"}) - - assert response.json() == {"Location": "New York","Name": "eric","Occupation": "Student","Password": "2020"} - - - response = requests.put((url + "/Change_User_Location"), json={"Location":"Chicago"}) - - assert response.json() == {"Location": "Chicago","Name": "eric","Occupation": "Student","Password": "2020"} - - response = requests.put((url + "/Change_User_Location"), json={"Location":"Massachusetts"}) - - assert response.json() == {"Location": "Massachusetts","Name": "eric","Occupation": "Student","Password": "2020"} - - - - - - - - - -test_Get_Random_pet() -test_Add_User_Faviorte() -test_Remove_User_Faviorte() -test_Change_User_Location() -print("Test check Complete: Passed") From 7dd29ad24a62ea8ade1d2f59b1c1149fb40e149d Mon Sep 17 00:00:00 2001 From: Eric Asante Date: Mon, 4 Nov 2024 14:14:43 -0500 Subject: [PATCH 34/38] Complete MILESTONE5 --- Backend/main.py | 54 +++++++++++++++ Backend/petfuc.py | 22 ++++++ Backend/test_main.py | 157 +++++++++++++++++++++++++++++++++++++++++++ Backend/userfuc.py | 39 +++++++++++ 4 files changed, 272 insertions(+) create mode 100644 Backend/main.py create mode 100644 Backend/petfuc.py create mode 100644 Backend/test_main.py create mode 100644 Backend/userfuc.py diff --git a/Backend/main.py b/Backend/main.py new file mode 100644 index 0000000..0728623 --- /dev/null +++ b/Backend/main.py @@ -0,0 +1,54 @@ +""" +This module provides functions for HTTP communication and +route functions +""" +from flask import Flask, request, jsonify +from petfuc import get_random_pet +from userfuc import add_user_faviorte, remove_user_faviorte, replace_user_location + +app = Flask(__name__) + +#Get Random Pet information - For homepage +@app.route("/Get_Random_pet", methods=["GET"]) +def random_pet(): + """ + Function to extract random pet information + """ + return get_random_pet(), 200 # Return dog information + +# Faviortes route. add user faviorte pet to database +@app.route("/Add_User_Faviorte", methods=["POST"]) +def adduserfaviorte(): + """ + Function to add user from database + """ + json_data = request.get_json() + + # Api accesses database and append post json in database + #Retrun database with succses code + return jsonify(add_user_faviorte(json_data)), 200 + +# Un Faviote Route. remove user faviorte pet from there database +@app.route("/Remove_User_Faviorte", methods=["DELETE"]) +def removeuserfaviorte(): + """ + Function to remove user from database + """ + json_data = request.get_json() + + # Api accesses database and append post json in database + #Retrun database with succses code + return jsonify(remove_user_faviorte(json_data)), 200 # return new user database + +# Change a Users account location +@app.route("/Change_User_Location", methods=["PUT"]) +def replace_user_information(): + """ + Function to change the location associated with + an account + """ + newlocation = request.get_json() # Get new location from post request + return jsonify(replace_user_location(newlocation)) # retrun user account info + +if __name__ == "__main__": + app.run(host="0.0.0.0", port=5000, debug=True) diff --git a/Backend/petfuc.py b/Backend/petfuc.py new file mode 100644 index 0000000..5e60700 --- /dev/null +++ b/Backend/petfuc.py @@ -0,0 +1,22 @@ +""" +This module provides functions for HTTP communication and +route functions +""" +from flask import jsonify + + +def get_random_pet(): + """ + Function to generate random ID and return pet + asscoieted with that ID + """ + randomint = "9" # APi generates random interger that represents a PET ID + # Api accesses database and return information in data base + #Retrun information such as profile picture on the pet accosiated with the random ID + data = {"id": randomint, + "name":"sam", + "sex":"male", + "Age":"8", + "location":"Connecticwut", + "Breed": "Pug"} + return jsonify(data) # Return dog information diff --git a/Backend/test_main.py b/Backend/test_main.py new file mode 100644 index 0000000..6ff3eea --- /dev/null +++ b/Backend/test_main.py @@ -0,0 +1,157 @@ +""" +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 new file mode 100644 index 0000000..42f2470 --- /dev/null +++ b/Backend/userfuc.py @@ -0,0 +1,39 @@ +""" +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 \ No newline at end of file From 40057942f19a757eae5bdde121cf709d58a831f5 Mon Sep 17 00:00:00 2001 From: Eric O Asante Date: Mon, 4 Nov 2024 14:21:57 -0500 Subject: [PATCH 35/38] Update ms5.yaml --- .github/workflows/ms5.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ms5.yaml b/.github/workflows/ms5.yaml index 17c8e23..3005fe5 100644 --- a/.github/workflows/ms5.yaml +++ b/.github/workflows/ms5.yaml @@ -48,7 +48,12 @@ jobs: python3 Backend/main.py & - - name: pytest + - name: Run Pytest run: | pytest + + - name: Run Pylint + run: | + find ./Backend -name "*.py" | xargs pylint + From 36d9a74f15078fbac64b1480611ca64db9997739 Mon Sep 17 00:00:00 2001 From: Eric Asante Date: Mon, 4 Nov 2024 14:23:34 -0500 Subject: [PATCH 36/38] Complete MILESTONE5 --- Backend/userfuc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Backend/userfuc.py b/Backend/userfuc.py index 42f2470..f983add 100644 --- a/Backend/userfuc.py +++ b/Backend/userfuc.py @@ -36,4 +36,5 @@ def replace_user_location(newlocation): """ newlocation = newlocation.get('Location') UserAccInfo["Location"] = newlocation # Set location accosiated with user to new location - return UserAccInfo # retrun user account info \ No newline at end of file + return UserAccInfo # retrun user account info + From 7cec6aed0a664e29922c4b0f802c655528995793 Mon Sep 17 00:00:00 2001 From: Eric O Asante Date: Mon, 4 Nov 2024 14:29:58 -0500 Subject: [PATCH 37/38] Update userfuc.py --- Backend/userfuc.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Backend/userfuc.py b/Backend/userfuc.py index f983add..ef15a7c 100644 --- a/Backend/userfuc.py +++ b/Backend/userfuc.py @@ -37,4 +37,3 @@ def replace_user_location(newlocation): newlocation = newlocation.get('Location') UserAccInfo["Location"] = newlocation # Set location accosiated with user to new location return UserAccInfo # retrun user account info - From 37a3bbd365c70d98cba372ed43f2840203b6602e Mon Sep 17 00:00:00 2001 From: Eric O Asante Date: Mon, 4 Nov 2024 14:32:19 -0500 Subject: [PATCH 38/38] Update ms5.yaml --- .github/workflows/ms5.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ms5.yaml b/.github/workflows/ms5.yaml index 3005fe5..47c0c77 100644 --- a/.github/workflows/ms5.yaml +++ b/.github/workflows/ms5.yaml @@ -5,7 +5,8 @@ name: API CI/CD on: push: branches: - - MileStone5eric + - main + - develop #Tells github actions what to execute when trigger condition is met jobs: