From 9510edafd59c84532f9d9997883fb25a0d7b249a Mon Sep 17 00:00:00 2001 From: dlingle1 Date: Sun, 5 Nov 2023 20:52:12 -0500 Subject: [PATCH 01/24] Add login and sign-up functionality to web-app --- Selenium Lab/website/__init__.py | 17 +++++ Selenium Lab/website/auth.py | 71 ++++++++++++++++++ Selenium Lab/website/templates/home.html | 2 + Selenium Lab/website/templates/login.html | 64 ++++++++++++++++ Selenium Lab/website/templates/sign_up.html | 82 +++++++++++++++++++++ 5 files changed, 236 insertions(+) create mode 100644 Selenium Lab/website/auth.py create mode 100644 Selenium Lab/website/templates/login.html create mode 100644 Selenium Lab/website/templates/sign_up.html diff --git a/Selenium Lab/website/__init__.py b/Selenium Lab/website/__init__.py index fcb0b93..f068f18 100644 --- a/Selenium Lab/website/__init__.py +++ b/Selenium Lab/website/__init__.py @@ -1,4 +1,6 @@ from flask import Flask +from flask_login import LoginManager +import json def create_app(): app = Flask(__name__) @@ -7,9 +9,24 @@ def create_app(): from .views import views from .movies import movie from .checkout import checkout + from .auth import auth app.register_blueprint(views, url_prefix='/') + app.register_blueprint(auth, url_prefix='/') app.register_blueprint(movie, url_prefix="/") app.register_blueprint(checkout, url_previs="/") + login_manager = LoginManager() + login_manager.login_view = 'auth.login' + login_manager.init_app(app) + + @login_manager.user_loader + def load_user(email): + file = open("user_data.json", 'r') + user_data = json.load(file) + file.close() + return user_data + + return app + return app diff --git a/Selenium Lab/website/auth.py b/Selenium Lab/website/auth.py new file mode 100644 index 0000000..d646cf9 --- /dev/null +++ b/Selenium Lab/website/auth.py @@ -0,0 +1,71 @@ +from flask import Blueprint, render_template, jsonify, request, flash, redirect, url_for +import json +import os +from flask_login import login_user, login_required, logout_user, current_user + +auth = Blueprint('auth', __name__) + + +@auth.route('/sign-up', methods=['GET', 'POST']) +def sign_up(): + if request.method == 'POST': + email = request.form.get('email') + first_name = request.form.get('firstName') + password1 = request.form.get('password1') + password2 = request.form.get('password2') + + if os.path.exists('user_data.json'): + file = open("user_data.json", 'r') + user_data = json.load(file) + file.close() + else: + user_data = {} + + if email in user_data: + flash('Email already exists.', category='error') + elif password1 != password2: + flash('Passwords don\'t match.', category='error') + else: + user = {'email': email, 'name': first_name, 'password': password1} + user_data[email] = user + file = open("user_data.json", 'w') + file.write(json.dumps(user_data, indent=4)) + file.close() + login_user(user, remember=True) + flash('Account created!', category='success') + return redirect(url_for('views.home')) + return render_template("sign_up.html", user=current_user) + + +@auth.route('/login', methods=['GET', 'POST']) +def login(): + if request.method == 'POST': + email = request.form.get('email') + password = request.form.get('password') + + if os.path.exists('user_data.json'): + file = open("user_data.json", 'r') + user_data = json.load(file) + file.close() + else: + user_data = {} + + if email in user_data: + user = user_data.get(email) + if user['password'] == password: + flash('Logged in successfully!', category='success') + login_user(user, remember=True) + return redirect(url_for('views.home')) + else: + flash('Incorrect password, try again.', category='error') + else: + flash('Email does not exist.', category='error') + + return render_template("login.html", user=current_user) + + +@auth.route('/logout') +@login_required +def logout(): + logout_user() + return redirect(url_for('views.home')) diff --git a/Selenium Lab/website/templates/home.html b/Selenium Lab/website/templates/home.html index c61d7b8..f35abb2 100644 --- a/Selenium Lab/website/templates/home.html +++ b/Selenium Lab/website/templates/home.html @@ -14,6 +14,8 @@

Mockbuster Video Rentals

  • Home
  • Search
  • Cart
  • +
  • Login
  • +
  • Sign-up
  • About Us
  • diff --git a/Selenium Lab/website/templates/login.html b/Selenium Lab/website/templates/login.html new file mode 100644 index 0000000..48e6b34 --- /dev/null +++ b/Selenium Lab/website/templates/login.html @@ -0,0 +1,64 @@ + + + + + + Sign-up + + + +
    +

    Mockbuster Video Rentals

    + +
    + +
    +
    +

    Login

    +
    + + +
    +
    + + +
    +
    + +
    +
    + + + + diff --git a/Selenium Lab/website/templates/sign_up.html b/Selenium Lab/website/templates/sign_up.html new file mode 100644 index 0000000..0bae446 --- /dev/null +++ b/Selenium Lab/website/templates/sign_up.html @@ -0,0 +1,82 @@ + + + + + + Sign-up + + + +
    +

    Mockbuster Video Rentals

    + +
    + +
    +
    +

    Sign Up

    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + +
    +
    + + + + From aef07076927f83a753583fa27c275c3827cc39ae Mon Sep 17 00:00:00 2001 From: dlingle1 Date: Wed, 8 Nov 2023 17:22:56 -0500 Subject: [PATCH 02/24] Revert "Add login and sign-up functionality to web-app" This reverts commit 9510edaf --- Selenium Lab/website/__init__.py | 17 ----- Selenium Lab/website/auth.py | 71 ------------------ Selenium Lab/website/templates/home.html | 2 - Selenium Lab/website/templates/login.html | 64 ---------------- Selenium Lab/website/templates/sign_up.html | 82 --------------------- 5 files changed, 236 deletions(-) delete mode 100644 Selenium Lab/website/auth.py delete mode 100644 Selenium Lab/website/templates/login.html delete mode 100644 Selenium Lab/website/templates/sign_up.html diff --git a/Selenium Lab/website/__init__.py b/Selenium Lab/website/__init__.py index f068f18..fcb0b93 100644 --- a/Selenium Lab/website/__init__.py +++ b/Selenium Lab/website/__init__.py @@ -1,6 +1,4 @@ from flask import Flask -from flask_login import LoginManager -import json def create_app(): app = Flask(__name__) @@ -9,24 +7,9 @@ def create_app(): from .views import views from .movies import movie from .checkout import checkout - from .auth import auth app.register_blueprint(views, url_prefix='/') - app.register_blueprint(auth, url_prefix='/') app.register_blueprint(movie, url_prefix="/") app.register_blueprint(checkout, url_previs="/") - login_manager = LoginManager() - login_manager.login_view = 'auth.login' - login_manager.init_app(app) - - @login_manager.user_loader - def load_user(email): - file = open("user_data.json", 'r') - user_data = json.load(file) - file.close() - return user_data - - return app - return app diff --git a/Selenium Lab/website/auth.py b/Selenium Lab/website/auth.py deleted file mode 100644 index d646cf9..0000000 --- a/Selenium Lab/website/auth.py +++ /dev/null @@ -1,71 +0,0 @@ -from flask import Blueprint, render_template, jsonify, request, flash, redirect, url_for -import json -import os -from flask_login import login_user, login_required, logout_user, current_user - -auth = Blueprint('auth', __name__) - - -@auth.route('/sign-up', methods=['GET', 'POST']) -def sign_up(): - if request.method == 'POST': - email = request.form.get('email') - first_name = request.form.get('firstName') - password1 = request.form.get('password1') - password2 = request.form.get('password2') - - if os.path.exists('user_data.json'): - file = open("user_data.json", 'r') - user_data = json.load(file) - file.close() - else: - user_data = {} - - if email in user_data: - flash('Email already exists.', category='error') - elif password1 != password2: - flash('Passwords don\'t match.', category='error') - else: - user = {'email': email, 'name': first_name, 'password': password1} - user_data[email] = user - file = open("user_data.json", 'w') - file.write(json.dumps(user_data, indent=4)) - file.close() - login_user(user, remember=True) - flash('Account created!', category='success') - return redirect(url_for('views.home')) - return render_template("sign_up.html", user=current_user) - - -@auth.route('/login', methods=['GET', 'POST']) -def login(): - if request.method == 'POST': - email = request.form.get('email') - password = request.form.get('password') - - if os.path.exists('user_data.json'): - file = open("user_data.json", 'r') - user_data = json.load(file) - file.close() - else: - user_data = {} - - if email in user_data: - user = user_data.get(email) - if user['password'] == password: - flash('Logged in successfully!', category='success') - login_user(user, remember=True) - return redirect(url_for('views.home')) - else: - flash('Incorrect password, try again.', category='error') - else: - flash('Email does not exist.', category='error') - - return render_template("login.html", user=current_user) - - -@auth.route('/logout') -@login_required -def logout(): - logout_user() - return redirect(url_for('views.home')) diff --git a/Selenium Lab/website/templates/home.html b/Selenium Lab/website/templates/home.html index f35abb2..c61d7b8 100644 --- a/Selenium Lab/website/templates/home.html +++ b/Selenium Lab/website/templates/home.html @@ -14,8 +14,6 @@

    Mockbuster Video Rentals

  • Home
  • Search
  • Cart
  • -
  • Login
  • -
  • Sign-up
  • About Us
  • diff --git a/Selenium Lab/website/templates/login.html b/Selenium Lab/website/templates/login.html deleted file mode 100644 index 48e6b34..0000000 --- a/Selenium Lab/website/templates/login.html +++ /dev/null @@ -1,64 +0,0 @@ - - - - - - Sign-up - - - -
    -

    Mockbuster Video Rentals

    - -
    - -
    -
    -

    Login

    -
    - - -
    -
    - - -
    -
    - -
    -
    - -
    -
    -

    Contact Information

    -

    Email: info@mockbusterrental.com

    -

    Phone: 123-456-7890

    -
    - -
    - - diff --git a/Selenium Lab/website/templates/sign_up.html b/Selenium Lab/website/templates/sign_up.html deleted file mode 100644 index 0bae446..0000000 --- a/Selenium Lab/website/templates/sign_up.html +++ /dev/null @@ -1,82 +0,0 @@ - - - - - - Sign-up - - - -
    -

    Mockbuster Video Rentals

    - -
    - -
    -
    -

    Sign Up

    -
    - - -
    -
    - - -
    -
    - - -
    -
    - - -
    -
    - -
    -
    - -
    -
    -

    Contact Information

    -

    Email: info@mockbusterrental.com

    -

    Phone: 123-456-7890

    -
    - -
    - - From 74967c2c7b166e76920c864ee1ae9a6b9f628f25 Mon Sep 17 00:00:00 2001 From: dlingle1 Date: Wed, 8 Nov 2023 21:40:24 -0500 Subject: [PATCH 03/24] Initial commit for API and API tests, only get and put work at the moment --- API Testing Lab/main.py | 22 ++++++++++++++++++++++ API Testing Lab/test.py | 10 ++++++++++ 2 files changed, 32 insertions(+) create mode 100644 API Testing Lab/main.py create mode 100644 API Testing Lab/test.py diff --git a/API Testing Lab/main.py b/API Testing Lab/main.py new file mode 100644 index 0000000..94c914e --- /dev/null +++ b/API Testing Lab/main.py @@ -0,0 +1,22 @@ +from flask import Flask, request +from flask_restful import Api, Resource + +app = Flask(__name__) +api = Api(app) + +iceCream = {1: "Vanilla", 2: "Chocolate", 3: "Strawberry", 4: "Cotton Candy", 5: "Mint Chocolate Chip"} + + +class IceCream(Resource): + def get(self, ice_cream_id): + return {ice_cream_id: iceCream[ice_cream_id]} + + def put(self, ice_cream_id): + iceCream[ice_cream_id] = request.form['name'] + return {ice_cream_id: iceCream[ice_cream_id]} + + +api.add_resource(IceCream, "/iceCream/") + +if __name__ == "__main__": + app.run(debug=True) diff --git a/API Testing Lab/test.py b/API Testing Lab/test.py new file mode 100644 index 0000000..d0dd7e0 --- /dev/null +++ b/API Testing Lab/test.py @@ -0,0 +1,10 @@ +import requests + +base = "http://127.0.0.1:5000/" + +response = requests.get(base + "iceCream/4") +print(response.json()) +response = requests.put(base + "iceCream/4", data={"name": "Cookies and Creme"}) +print(response.json()) +response = requests.get(base + "iceCream/4") +print(response.json()) From 5ea19bd899cefe1207b83fbad1c8e68e6a65dc29 Mon Sep 17 00:00:00 2001 From: dlingle1 Date: Sun, 12 Nov 2023 23:48:51 -0500 Subject: [PATCH 04/24] Add post and delete request methods to api, some validation, and expand and fix tests for proper output --- API Testing Lab/main.py | 33 +++++++++++++++++++++++++++++++-- API Testing Lab/test.py | 13 ++++++++++++- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/API Testing Lab/main.py b/API Testing Lab/main.py index 94c914e..ef0e643 100644 --- a/API Testing Lab/main.py +++ b/API Testing Lab/main.py @@ -1,22 +1,51 @@ from flask import Flask, request -from flask_restful import Api, Resource +from flask_restful import Api, Resource, abort +# Create app and api app = Flask(__name__) api = Api(app) +# Ice cream menu dictionary iceCream = {1: "Vanilla", 2: "Chocolate", 3: "Strawberry", 4: "Cotton Candy", 5: "Mint Chocolate Chip"} +# Validate whether ice cream already exists +def abort_if_id_exists(ice_cream_id): + if ice_cream_id in iceCream: + abort(409, message="ID already exists") + + +# Validate whether ice cream does not exist +def abort_if_id_does_not_exists(ice_cream_id): + if ice_cream_id not in iceCream: + abort(404, message="ID is invalid") + + +# Api resource for ice cream menu class IceCream(Resource): def get(self, ice_cream_id): + abort_if_id_does_not_exists(ice_cream_id) return {ice_cream_id: iceCream[ice_cream_id]} + def post(self, ice_cream_id): + abort_if_id_exists(ice_cream_id) + iceCream[ice_cream_id] = request.form['name'] + return {ice_cream_id: iceCream[ice_cream_id]}, 201 + def put(self, ice_cream_id): + abort_if_id_does_not_exists(ice_cream_id) iceCream[ice_cream_id] = request.form['name'] - return {ice_cream_id: iceCream[ice_cream_id]} + return {ice_cream_id: iceCream[ice_cream_id]}, 202 + + def delete(self, ice_cream_id): + abort_if_id_does_not_exists(ice_cream_id) + del iceCream[ice_cream_id] + return '', 203 +# Add resource to api api.add_resource(IceCream, "/iceCream/") +# Run main if __name__ == "__main__": app.run(debug=True) diff --git a/API Testing Lab/test.py b/API Testing Lab/test.py index d0dd7e0..4eb25dc 100644 --- a/API Testing Lab/test.py +++ b/API Testing Lab/test.py @@ -1,10 +1,21 @@ import requests +# Base url base = "http://127.0.0.1:5000/" +# Change flavor test response = requests.get(base + "iceCream/4") print(response.json()) response = requests.put(base + "iceCream/4", data={"name": "Cookies and Creme"}) print(response.json()) -response = requests.get(base + "iceCream/4") + +# Delete flavor test +response = requests.get(base + "iceCream/5") +print(response.json()) +requests.delete(base + "iceCream/5") +response = requests.get(base + "iceCream/5") +print(response.json()) + +# Add flavor test +response = requests.post(base + "iceCream/5", data={"name": "Chocolate Chip Cookie Dough"}) print(response.json()) From e5f07b6e2a2afb35bc407313b919bd5998e89339 Mon Sep 17 00:00:00 2001 From: dlingle1 Date: Wed, 15 Nov 2023 16:11:15 -0500 Subject: [PATCH 05/24] Conform test.py to pytest unit tests and ensure all methods have response codes --- .idea/Group7-repo-projects.iml | 6 ++++ API Testing Lab/main.py | 9 ++--- API Testing Lab/test.py | 61 +++++++++++++++++++++++++--------- 3 files changed, 56 insertions(+), 20 deletions(-) diff --git a/.idea/Group7-repo-projects.iml b/.idea/Group7-repo-projects.iml index 74d515a..151e724 100644 --- a/.idea/Group7-repo-projects.iml +++ b/.idea/Group7-repo-projects.iml @@ -7,4 +7,10 @@ + + + + \ No newline at end of file diff --git a/API Testing Lab/main.py b/API Testing Lab/main.py index ef0e643..9eb960f 100644 --- a/API Testing Lab/main.py +++ b/API Testing Lab/main.py @@ -23,24 +23,25 @@ def abort_if_id_does_not_exists(ice_cream_id): # Api resource for ice cream menu class IceCream(Resource): + def get(self, ice_cream_id): abort_if_id_does_not_exists(ice_cream_id) - return {ice_cream_id: iceCream[ice_cream_id]} + return {ice_cream_id: iceCream[ice_cream_id]}, 201 def post(self, ice_cream_id): abort_if_id_exists(ice_cream_id) iceCream[ice_cream_id] = request.form['name'] - return {ice_cream_id: iceCream[ice_cream_id]}, 201 + return {ice_cream_id: iceCream[ice_cream_id]}, 202 def put(self, ice_cream_id): abort_if_id_does_not_exists(ice_cream_id) iceCream[ice_cream_id] = request.form['name'] - return {ice_cream_id: iceCream[ice_cream_id]}, 202 + return {ice_cream_id: iceCream[ice_cream_id]}, 203 def delete(self, ice_cream_id): abort_if_id_does_not_exists(ice_cream_id) del iceCream[ice_cream_id] - return '', 203 + return '', 204 # Add resource to api diff --git a/API Testing Lab/test.py b/API Testing Lab/test.py index 4eb25dc..0eb57f9 100644 --- a/API Testing Lab/test.py +++ b/API Testing Lab/test.py @@ -3,19 +3,48 @@ # Base url base = "http://127.0.0.1:5000/" -# Change flavor test -response = requests.get(base + "iceCream/4") -print(response.json()) -response = requests.put(base + "iceCream/4", data={"name": "Cookies and Creme"}) -print(response.json()) - -# Delete flavor test -response = requests.get(base + "iceCream/5") -print(response.json()) -requests.delete(base + "iceCream/5") -response = requests.get(base + "iceCream/5") -print(response.json()) - -# Add flavor test -response = requests.post(base + "iceCream/5", data={"name": "Chocolate Chip Cookie Dough"}) -print(response.json()) + +def test_get(): + response = requests.get(base + "iceCream/4") + print(response.json()) + assert response.status_code == 201 + + +def test_get_no_id(): + response = requests.get(base + "iceCream/6") + print(response.json()) + assert response.status_code != 201 + + +def test_put(): + response = requests.put(base + "iceCream/4", data={"name": "Cookies and Creme"}) + print(response.json()) + assert response.status_code == 203 + + +def test_put_no_id(): + response = requests.put(base + "iceCream/6", data={"name": "Cookies and Creme"}) + print(response.json()) + assert response.status_code != 203 + + +def test_delete(): + response = requests.delete(base + "iceCream/5") + assert response.status_code == 204 + + +def test_delete_no_id(): + response = requests.delete(base + "iceCream/5") + assert response.status_code != 204 + + +def test_post(): + response = requests.post(base + "iceCream/5", data={"name": "Chocolate Chip Cookie Dough"}) + print(response.json()) + assert response.status_code == 202 + + +def test_post_existing_id(): + response = requests.post(base + "iceCream/3", data={"name": "Chocolate Chip Cookie Dough"}) + print(response.json()) + assert response.status_code != 202 From a506d27b1b9f98e87e8baa9910a2ef5b716ab4f2 Mon Sep 17 00:00:00 2001 From: Caleb Luce <142257447+CalebLuce@users.noreply.github.com> Date: Thu, 16 Nov 2023 16:19:06 -0500 Subject: [PATCH 06/24] API Testing Tutorial Test Draft To be renamed and set into the proper file location once reviewed and corrected of errors or flaws. --- API Testing Lab/api_tutorial_sample.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 API Testing Lab/api_tutorial_sample.md diff --git a/API Testing Lab/api_tutorial_sample.md b/API Testing Lab/api_tutorial_sample.md new file mode 100644 index 0000000..e0a819a --- /dev/null +++ b/API Testing Lab/api_tutorial_sample.md @@ -0,0 +1,14 @@ +# API Testing Tutorial +## What Is API Testing? +API Testing, unlike most tests, focuses specifically on Application Programming Interfaces (APIs). APIs serve as a link between different software applications, facilitating communication. They establish rules and tools for seamless data exchange. API Testing involves creating and executing tests that validate various aspects of APIs to ensure their proper functionality. This includes observing and recording status codes, automated validation of API endpoints, and making seamless HTTP requests. API Testing is crucial for ensuring not only a functional API but also a reliable software system. + +## What Will We Use to Test? +For this tutorial, we will use Pytest as our testing tool. Pytest is an efficient framework that simplifies API Testing. To get started, make sure to install the required packages by entering 'pip install pytest requests' into the Command Terminal. When creating your test file, follow the Pytest convention by naming it with a 'test_' prefix. Ensure that the file includes 'import requests' and 'import pytest' before generating any tests. + +## Additional Information +Note that this tutorial does not cover all available options for API testing, and not every type of test is included as an example. Feel free to explore the provided code for additional insights and information that may not be explicitly covered in this tutorial. Good luck! + + + + + From bb9bf7d846e8ce486a2f11e78edd0e7e12764b36 Mon Sep 17 00:00:00 2001 From: Taylor Sanderson Date: Thu, 16 Nov 2023 16:55:23 -0500 Subject: [PATCH 07/24] minor fixes --- API Testing Lab/api_tutorial_sample.md | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/API Testing Lab/api_tutorial_sample.md b/API Testing Lab/api_tutorial_sample.md index e0a819a..b497562 100644 --- a/API Testing Lab/api_tutorial_sample.md +++ b/API Testing Lab/api_tutorial_sample.md @@ -1,12 +1,23 @@ # API Testing Tutorial ## What Is API Testing? -API Testing, unlike most tests, focuses specifically on Application Programming Interfaces (APIs). APIs serve as a link between different software applications, facilitating communication. They establish rules and tools for seamless data exchange. API Testing involves creating and executing tests that validate various aspects of APIs to ensure their proper functionality. This includes observing and recording status codes, automated validation of API endpoints, and making seamless HTTP requests. API Testing is crucial for ensuring not only a functional API but also a reliable software system. +API Testing, unlike most tests, focuses specifically on Application Programming Interfaces (APIs). +APIs serve as a link between different software applications, facilitating communication. +They establish rules and tools for seamless data exchange. +API Testing involves creating and executing tests that validate various aspects of APIs to ensure their proper functionality. +This includes observing and recording status codes, automated validation of API endpoints, and making seamless HTTP requests. +API Testing is crucial for ensuring not only a functional API but also a reliable software system. ## What Will We Use to Test? -For this tutorial, we will use Pytest as our testing tool. Pytest is an efficient framework that simplifies API Testing. To get started, make sure to install the required packages by entering 'pip install pytest requests' into the Command Terminal. When creating your test file, follow the Pytest convention by naming it with a 'test_' prefix. Ensure that the file includes 'import requests' and 'import pytest' before generating any tests. +For this tutorial, we will use Pytest as our testing tool. +Pytest is an efficient framework that simplifies API Testing. +To get started, make sure to install the required packages by entering `pip install pytest requests` into your terminal. +When creating your test file, follow the Pytest convention by naming it with a `test_` prefix, and that any methods within are also begun with `test_`. +Ensure that the code file includes `import requests` and `import pytest` before generating any tests. ## Additional Information -Note that this tutorial does not cover all available options for API testing, and not every type of test is included as an example. Feel free to explore the provided code for additional insights and information that may not be explicitly covered in this tutorial. Good luck! +Note that this tutorial does not cover all available options for API testing, and not every type of test is included as an example. +Feel free to explore the provided code for additional insights and information that may not be explicitly covered in this tutorial. +Good luck! From 9e2539fbe5d210fb7f87965d64923bc4d20cb07b Mon Sep 17 00:00:00 2001 From: Caleb Luce <142257447+CalebLuce@users.noreply.github.com> Date: Mon, 20 Nov 2023 11:34:11 -0500 Subject: [PATCH 08/24] Add files via upload --- API Testing Lab/api_test_examples.md | 43 ++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 API Testing Lab/api_test_examples.md diff --git a/API Testing Lab/api_test_examples.md b/API Testing Lab/api_test_examples.md new file mode 100644 index 0000000..a806db8 --- /dev/null +++ b/API Testing Lab/api_test_examples.md @@ -0,0 +1,43 @@ +# API Test Examples + +When performing API testing, it is always crucial to include imports for requests. Importing requests allows the following test examples to work, and thereby is defining GET, PUT, DELETE, and POST test attempts. In this test file, we have a base URL to work with as well, which is also attached toward the top of the file. +```py +import requests + +base = "http://127.0.0.1:5000/" +``` +## Example 1: GET +```py +def test_get(): + response = requests.get(base + "iceCream/4") + print(response.json()) + assert response.status_code == 201 +``` +This test makes an HTTP GET request to a constructed endpoint. `iceCream/4` is appended to the base URL, the JSON content is printed, and an assert statement is made. Once the GET request is made, the server response is stored in the `response` variable. The print statement for `response.json()` is parsed under the assumption of JSON format due to `.json()`. The assertion statement for this and all tests presented asserts the HTTP status code, and passes if the statement returns True. Otherwise, an exception is raised and indicates test failure. The terminal output for this test is shown below: + +![Successful Print Statement](https://i.imgur.com/X5yBKqA.png) +![test_get Successful](https://i.imgur.com/QnCPDNM.png) + +## Example 2: DELETE +```py +def test_delete(): + response = requests.delete(base + "iceCream/5") + assert response.status_code == 204 +``` +This test makes an HTTP DELETE request to an endpoint made by appending `iceCream/5` to the base URL, then stores the server response in the `response` variable. There is no print statement for this test, and an assert statement is made to verify a successful deletion. Terminal output displayed below: + +![test_delete Successful](https://i.imgur.com/5l1Z9lo.png) + +Within the test file, every successful test has an alternative test to ensure a failed GET, PUT, DELETE, or POST test is validated. The next and last test example will be for an intended failure. + +## Example 3: DELETE (Intended Failure) +```py +def test_delete_no_id(): + response = requests.delete(base + "iceCream/5") + assert response.status_code != 204 +``` +This test is performing the same actions as the test within Example 2, though the result is meant to be very different. When the assert statement is made, any `status_code` that is not equal to the intended successful status code will result in a success. Should the test succeed in the DELETE request, an exception is thrown and the test fails. Terminal output is displayed below: + +![test_delete_no_id Successful](https://i.imgur.com/CYoOXQU.png) + +With these examples, you should have a better understanding of API Testing. As mentioned prior; GET, PUT, DELETE, and POST all have alternate intended failure tests. More examples are presented within the `test.py` file, which you may view at your own will. \ No newline at end of file From 68ceb31a1f434ef83406e059fa03f773c4e85b12 Mon Sep 17 00:00:00 2001 From: Taylor Sanderson Date: Mon, 20 Nov 2023 12:35:01 -0500 Subject: [PATCH 09/24] some edits to the documentation --- ...torial_sample.md => 1 API Introduction.md} | 50 ++++++++--------- API Testing Lab/2 API test examples.md | 56 +++++++++++++++++++ API Testing Lab/api_test_examples.md | 43 -------------- 3 files changed, 81 insertions(+), 68 deletions(-) rename API Testing Lab/{api_tutorial_sample.md => 1 API Introduction.md} (98%) create mode 100644 API Testing Lab/2 API test examples.md delete mode 100644 API Testing Lab/api_test_examples.md diff --git a/API Testing Lab/api_tutorial_sample.md b/API Testing Lab/1 API Introduction.md similarity index 98% rename from API Testing Lab/api_tutorial_sample.md rename to API Testing Lab/1 API Introduction.md index b497562..f07d346 100644 --- a/API Testing Lab/api_tutorial_sample.md +++ b/API Testing Lab/1 API Introduction.md @@ -1,25 +1,25 @@ -# API Testing Tutorial -## What Is API Testing? -API Testing, unlike most tests, focuses specifically on Application Programming Interfaces (APIs). -APIs serve as a link between different software applications, facilitating communication. -They establish rules and tools for seamless data exchange. -API Testing involves creating and executing tests that validate various aspects of APIs to ensure their proper functionality. -This includes observing and recording status codes, automated validation of API endpoints, and making seamless HTTP requests. -API Testing is crucial for ensuring not only a functional API but also a reliable software system. - -## What Will We Use to Test? -For this tutorial, we will use Pytest as our testing tool. -Pytest is an efficient framework that simplifies API Testing. -To get started, make sure to install the required packages by entering `pip install pytest requests` into your terminal. -When creating your test file, follow the Pytest convention by naming it with a `test_` prefix, and that any methods within are also begun with `test_`. -Ensure that the code file includes `import requests` and `import pytest` before generating any tests. - -## Additional Information -Note that this tutorial does not cover all available options for API testing, and not every type of test is included as an example. -Feel free to explore the provided code for additional insights and information that may not be explicitly covered in this tutorial. -Good luck! - - - - - +# API Testing Tutorial +## What Is API Testing? +API Testing, unlike most tests, focuses specifically on Application Programming Interfaces (APIs). +APIs serve as a link between different software applications, facilitating communication. +They establish rules and tools for seamless data exchange. +API Testing involves creating and executing tests that validate various aspects of APIs to ensure their proper functionality. +This includes observing and recording status codes, automated validation of API endpoints, and making seamless HTTP requests. +API Testing is crucial for ensuring not only a functional API but also a reliable software system. + +## What Will We Use to Test? +For this tutorial, we will use Pytest as our testing tool. +Pytest is an efficient framework that simplifies API Testing. +To get started, make sure to install the required packages by entering `pip install pytest requests` into your terminal. +When creating your test file, follow the Pytest convention by naming it with a `test_` prefix, and that any methods within are also begun with `test_`. +Ensure that the code file includes `import requests` and `import pytest` before generating any tests. + +## Additional Information +Note that this tutorial does not cover all available options for API testing, and not every type of test is included as an example. +Feel free to explore the provided code for additional insights and information that may not be explicitly covered in this tutorial. +Good luck! + + + + + diff --git a/API Testing Lab/2 API test examples.md b/API Testing Lab/2 API test examples.md new file mode 100644 index 0000000..7cf3d66 --- /dev/null +++ b/API Testing Lab/2 API test examples.md @@ -0,0 +1,56 @@ +# API Test Examples + +When performing API testing, it is always crucial to include imports for requests. +Importing requests allows the following test examples to work, and thereby is defining GET, PUT, DELETE, and POST test attempts. +In this test file, we have a base URL to work with as well, which is also attached toward the top of the file. +If you were using someone else's server to test your API calls against, a variable like this would be where you would put that URL. +```py +import requests + +base = "http://127.0.0.1:5000/" +``` +## Example 1: GET +```py +def test_get(): + response = requests.get(base + "iceCream/4") + assert response.status_code == 201 +``` +This test makes an HTTP GET request to a constructed endpoint. +`iceCream/4` is appended to the base URL, the JSON content is printed, and an assert statement is made. +Once the GET request is made, the server response is stored in the `response` variable. +The assertion statement for this and all tests presented asserts the HTTP status code, and passes if the statement returns True. +Otherwise, an exception is raised and indicates test failure. The terminal output for this test is shown below: + +![Successful Print Statement](https://i.imgur.com/X5yBKqA.png) +![test_get Successful](https://i.imgur.com/QnCPDNM.png) + +## Example 2: DELETE +```py +def test_delete(): + response = requests.delete(base + "iceCream/5") + assert response.status_code == 204 +``` +This test makes an HTTP DELETE request to an endpoint made by appending `iceCream/5` to the base URL, then stores the server response in the `response` variable. +There is no print statement for this test, and an assert statement is made to verify a successful deletion. +Terminal output displayed below: + +![test_delete Successful](https://i.imgur.com/5l1Z9lo.png) + +Within the test file, every successful test has an alternative test to ensure a failed GET, PUT, DELETE, or POST test is validated. +The next and last test example will be for an intended failure. + +## Example 3: DELETE (Intended Failure) +```py +def test_delete_no_id(): + response = requests.delete(base + "iceCream/5") + assert response.status_code != 204 +``` +This test is performing the same actions as the test within Example 2, though the result is meant to be very different. +When the assert statement is made, any `status_code` that is not equal to the intended successful status code will result in a success. +Should the test succeed in the DELETE request, an exception is thrown and the test fails. Terminal output is displayed below: + +![test_delete_no_id Successful](https://i.imgur.com/CYoOXQU.png) + +With these examples, you should have a better understanding of API Testing. +As mentioned prior; GET, PUT, DELETE, and POST all have alternate intended failure tests. +More examples are presented within the `test.py` file, which you may view at your own will. \ No newline at end of file diff --git a/API Testing Lab/api_test_examples.md b/API Testing Lab/api_test_examples.md deleted file mode 100644 index a806db8..0000000 --- a/API Testing Lab/api_test_examples.md +++ /dev/null @@ -1,43 +0,0 @@ -# API Test Examples - -When performing API testing, it is always crucial to include imports for requests. Importing requests allows the following test examples to work, and thereby is defining GET, PUT, DELETE, and POST test attempts. In this test file, we have a base URL to work with as well, which is also attached toward the top of the file. -```py -import requests - -base = "http://127.0.0.1:5000/" -``` -## Example 1: GET -```py -def test_get(): - response = requests.get(base + "iceCream/4") - print(response.json()) - assert response.status_code == 201 -``` -This test makes an HTTP GET request to a constructed endpoint. `iceCream/4` is appended to the base URL, the JSON content is printed, and an assert statement is made. Once the GET request is made, the server response is stored in the `response` variable. The print statement for `response.json()` is parsed under the assumption of JSON format due to `.json()`. The assertion statement for this and all tests presented asserts the HTTP status code, and passes if the statement returns True. Otherwise, an exception is raised and indicates test failure. The terminal output for this test is shown below: - -![Successful Print Statement](https://i.imgur.com/X5yBKqA.png) -![test_get Successful](https://i.imgur.com/QnCPDNM.png) - -## Example 2: DELETE -```py -def test_delete(): - response = requests.delete(base + "iceCream/5") - assert response.status_code == 204 -``` -This test makes an HTTP DELETE request to an endpoint made by appending `iceCream/5` to the base URL, then stores the server response in the `response` variable. There is no print statement for this test, and an assert statement is made to verify a successful deletion. Terminal output displayed below: - -![test_delete Successful](https://i.imgur.com/5l1Z9lo.png) - -Within the test file, every successful test has an alternative test to ensure a failed GET, PUT, DELETE, or POST test is validated. The next and last test example will be for an intended failure. - -## Example 3: DELETE (Intended Failure) -```py -def test_delete_no_id(): - response = requests.delete(base + "iceCream/5") - assert response.status_code != 204 -``` -This test is performing the same actions as the test within Example 2, though the result is meant to be very different. When the assert statement is made, any `status_code` that is not equal to the intended successful status code will result in a success. Should the test succeed in the DELETE request, an exception is thrown and the test fails. Terminal output is displayed below: - -![test_delete_no_id Successful](https://i.imgur.com/CYoOXQU.png) - -With these examples, you should have a better understanding of API Testing. As mentioned prior; GET, PUT, DELETE, and POST all have alternate intended failure tests. More examples are presented within the `test.py` file, which you may view at your own will. \ No newline at end of file From 619eb3b4e29e63bf40926482750e32a4560876e9 Mon Sep 17 00:00:00 2001 From: Taylor Sanderson Date: Mon, 20 Nov 2023 12:35:29 -0500 Subject: [PATCH 10/24] never print when using pytest. Use asserts. --- API Testing Lab/test.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/API Testing Lab/test.py b/API Testing Lab/test.py index 0eb57f9..65fada6 100644 --- a/API Testing Lab/test.py +++ b/API Testing Lab/test.py @@ -6,25 +6,21 @@ def test_get(): response = requests.get(base + "iceCream/4") - print(response.json()) assert response.status_code == 201 def test_get_no_id(): response = requests.get(base + "iceCream/6") - print(response.json()) assert response.status_code != 201 def test_put(): response = requests.put(base + "iceCream/4", data={"name": "Cookies and Creme"}) - print(response.json()) assert response.status_code == 203 def test_put_no_id(): response = requests.put(base + "iceCream/6", data={"name": "Cookies and Creme"}) - print(response.json()) assert response.status_code != 203 @@ -40,11 +36,9 @@ def test_delete_no_id(): def test_post(): response = requests.post(base + "iceCream/5", data={"name": "Chocolate Chip Cookie Dough"}) - print(response.json()) assert response.status_code == 202 def test_post_existing_id(): response = requests.post(base + "iceCream/3", data={"name": "Chocolate Chip Cookie Dough"}) - print(response.json()) assert response.status_code != 202 From 047cebbcfa3390a06abaaf373b3e134fc000a6ea Mon Sep 17 00:00:00 2001 From: dlingle1 Date: Mon, 20 Nov 2023 13:35:22 -0500 Subject: [PATCH 11/24] Create and move requirements.txt for all current labs --- .../requirements.txt => requirements.txt | 11 +++++++++++ 1 file changed, 11 insertions(+) rename Selenium Lab/Lab Documentation/requirements.txt => requirements.txt (69%) diff --git a/Selenium Lab/Lab Documentation/requirements.txt b/requirements.txt similarity index 69% rename from Selenium Lab/Lab Documentation/requirements.txt rename to requirements.txt index 24e1eb3..a32d84e 100644 --- a/Selenium Lab/Lab Documentation/requirements.txt +++ b/requirements.txt @@ -1,23 +1,34 @@ +aniso8601==9.0.1 attrs==23.1.0 blinker==1.6.3 certifi==2023.7.22 cffi==1.16.0 +charset-normalizer==3.3.2 click==8.1.7 colorama==0.4.6 exceptiongroup==1.1.3 Flask==3.0.0 +Flask-RESTful==0.3.10 h11==0.14.0 idna==3.4 importlib-metadata==6.8.0 +iniconfig==2.0.0 itsdangerous==2.1.2 Jinja2==3.1.2 MarkupSafe==2.1.3 outcome==1.3.0 +packaging==23.2 +pluggy==1.3.0 pycparser==2.21 PySocks==1.7.1 +pytest==7.4.3 +pytz==2023.3.post1 +requests==2.31.0 selenium==4.14.0 +six==1.16.0 sniffio==1.3.0 sortedcontainers==2.4.0 +tomli==2.0.1 trio==0.22.2 trio-websocket==0.11.1 urllib3==2.0.7 From ae84795ba2832abc0d76236e17d646a3d46e3cb7 Mon Sep 17 00:00:00 2001 From: dlingle1 Date: Mon, 20 Nov 2023 14:27:06 -0500 Subject: [PATCH 12/24] Add test for contents of the response in api request --- API Testing Lab/test.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/API Testing Lab/test.py b/API Testing Lab/test.py index 65fada6..c00f7d9 100644 --- a/API Testing Lab/test.py +++ b/API Testing Lab/test.py @@ -6,21 +6,25 @@ def test_get(): response = requests.get(base + "iceCream/4") + assert response.json() == {"4": "Cotton Candy"} assert response.status_code == 201 def test_get_no_id(): response = requests.get(base + "iceCream/6") + assert response.json() == {"message": "ID is invalid"} assert response.status_code != 201 def test_put(): response = requests.put(base + "iceCream/4", data={"name": "Cookies and Creme"}) + assert response.json() == {"4": "Cookies and Creme"} assert response.status_code == 203 def test_put_no_id(): response = requests.put(base + "iceCream/6", data={"name": "Cookies and Creme"}) + assert response.json() == {"message": "ID is invalid"} assert response.status_code != 203 @@ -31,14 +35,17 @@ def test_delete(): def test_delete_no_id(): response = requests.delete(base + "iceCream/5") + assert response.json() == {"message": "ID is invalid"} assert response.status_code != 204 def test_post(): response = requests.post(base + "iceCream/5", data={"name": "Chocolate Chip Cookie Dough"}) + assert response.json() == {"5": "Chocolate Chip Cookie Dough"} assert response.status_code == 202 def test_post_existing_id(): response = requests.post(base + "iceCream/3", data={"name": "Chocolate Chip Cookie Dough"}) + assert response.json() == {"message": "ID already exists"} assert response.status_code != 202 From f1a7e0ff13a954c69b98a85a13f0d4e782d9e4be Mon Sep 17 00:00:00 2001 From: dlingle1 Date: Mon, 20 Nov 2023 14:32:06 -0500 Subject: [PATCH 13/24] Fix success codes for api methods --- API Testing Lab/main.py | 8 ++++---- API Testing Lab/test.py | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/API Testing Lab/main.py b/API Testing Lab/main.py index 9eb960f..afbdc9e 100644 --- a/API Testing Lab/main.py +++ b/API Testing Lab/main.py @@ -26,22 +26,22 @@ class IceCream(Resource): def get(self, ice_cream_id): abort_if_id_does_not_exists(ice_cream_id) - return {ice_cream_id: iceCream[ice_cream_id]}, 201 + return {ice_cream_id: iceCream[ice_cream_id]}, 200 def post(self, ice_cream_id): abort_if_id_exists(ice_cream_id) iceCream[ice_cream_id] = request.form['name'] - return {ice_cream_id: iceCream[ice_cream_id]}, 202 + return {ice_cream_id: iceCream[ice_cream_id]}, 201 def put(self, ice_cream_id): abort_if_id_does_not_exists(ice_cream_id) iceCream[ice_cream_id] = request.form['name'] - return {ice_cream_id: iceCream[ice_cream_id]}, 203 + return {ice_cream_id: iceCream[ice_cream_id]}, 201 def delete(self, ice_cream_id): abort_if_id_does_not_exists(ice_cream_id) del iceCream[ice_cream_id] - return '', 204 + return '', 200 # Add resource to api diff --git a/API Testing Lab/test.py b/API Testing Lab/test.py index c00f7d9..00b56e4 100644 --- a/API Testing Lab/test.py +++ b/API Testing Lab/test.py @@ -7,45 +7,45 @@ def test_get(): response = requests.get(base + "iceCream/4") assert response.json() == {"4": "Cotton Candy"} - assert response.status_code == 201 + assert response.status_code == 200 def test_get_no_id(): response = requests.get(base + "iceCream/6") assert response.json() == {"message": "ID is invalid"} - assert response.status_code != 201 + assert response.status_code != 200 def test_put(): response = requests.put(base + "iceCream/4", data={"name": "Cookies and Creme"}) assert response.json() == {"4": "Cookies and Creme"} - assert response.status_code == 203 + assert response.status_code == 201 def test_put_no_id(): response = requests.put(base + "iceCream/6", data={"name": "Cookies and Creme"}) assert response.json() == {"message": "ID is invalid"} - assert response.status_code != 203 + assert response.status_code != 201 def test_delete(): response = requests.delete(base + "iceCream/5") - assert response.status_code == 204 + assert response.status_code == 200 def test_delete_no_id(): response = requests.delete(base + "iceCream/5") assert response.json() == {"message": "ID is invalid"} - assert response.status_code != 204 + assert response.status_code != 200 def test_post(): response = requests.post(base + "iceCream/5", data={"name": "Chocolate Chip Cookie Dough"}) assert response.json() == {"5": "Chocolate Chip Cookie Dough"} - assert response.status_code == 202 + assert response.status_code == 201 def test_post_existing_id(): response = requests.post(base + "iceCream/3", data={"name": "Chocolate Chip Cookie Dough"}) assert response.json() == {"message": "ID already exists"} - assert response.status_code != 202 + assert response.status_code != 201 From 9ac92ab9b8c98182dbfde1dc8dabaa5a9d99d57c Mon Sep 17 00:00:00 2001 From: dlingle1 Date: Mon, 20 Nov 2023 14:35:52 -0500 Subject: [PATCH 14/24] Add delete success message and test for that message --- API Testing Lab/main.py | 2 +- API Testing Lab/test.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/API Testing Lab/main.py b/API Testing Lab/main.py index afbdc9e..2079f94 100644 --- a/API Testing Lab/main.py +++ b/API Testing Lab/main.py @@ -41,7 +41,7 @@ def put(self, ice_cream_id): def delete(self, ice_cream_id): abort_if_id_does_not_exists(ice_cream_id) del iceCream[ice_cream_id] - return '', 200 + return {'message': 'Item is deleted from the menu'}, 200 # Add resource to api diff --git a/API Testing Lab/test.py b/API Testing Lab/test.py index 00b56e4..ab1b405 100644 --- a/API Testing Lab/test.py +++ b/API Testing Lab/test.py @@ -30,6 +30,7 @@ def test_put_no_id(): def test_delete(): response = requests.delete(base + "iceCream/5") + assert response.json() == {"message": "Item is deleted from the menu"} assert response.status_code == 200 From 5d94f805a11c2106f3640a8c15d5014b2b52126a Mon Sep 17 00:00:00 2001 From: dlingle1 <94473147+dlingle1@users.noreply.github.com> Date: Sun, 26 Nov 2023 20:27:59 -0500 Subject: [PATCH 15/24] Create 3 API Postman.md Basic tutorial and installation of Postman. Needs pictures and some minor formatting changes. Will get to that shortly. --- API Testing Lab/3 API Postman.md | 57 ++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 API Testing Lab/3 API Postman.md diff --git a/API Testing Lab/3 API Postman.md b/API Testing Lab/3 API Postman.md new file mode 100644 index 0000000..8d58c4c --- /dev/null +++ b/API Testing Lab/3 API Postman.md @@ -0,0 +1,57 @@ +# API Testing With Postman +## Introduction to Postman +Postman is an API platform that provides tools for building, testing, and using APIs. +It can make HTTP requests, save environments for later, alongside convert API code into languages like Python and JavaScript. +All of this functionality is handled by a simple and easy-to-use user interface. +As a result, Postman is used by millions of API developers every year for all their API needs. + +## How to Setup Postman +1. First, you must download Postman to be able to use it. + Whilst there is a variety of Postman products to use, we are just going to download the free version provided. + [Click here for the link](https://www.postman.com/downloads/) +2. After downloading Postman from that link, you must now install it. + Simply click on the setup file you downloaded should install everything. +3. You will be presented with a menu that will ask you to sign up or create an account. + You can create an account or you can select an option towards the bottom of the window to skip this process. + It should be noted that if you do not have an account associated with your Postman application, you will be limited in certain actions you can do with Postman and your UI will be different. + +## How to Test With Postman +To keep things simple and to work with the basic API template we have used throughout this lab, we are going to focus on using HTTP requests with Postman. +If you did not create an account with Postman, this will be possible but will be slightly different. +The requests should be the same, but you will not be able to create collections and workspaces or take advantage of templates. +You should however still be able to follow along. + +### Step-By-Step +1. You should be in a default workspace, you can either create a new one or use the current one. + However, you will want to create a new collection, in this case, a REST API basics template is perfect or you can create your own with a blank template. + If you use the blank template you will have to create your own requests. + In this example, it is recommended you use the REST API basics template. +2. You should now be presented or create 4 requests, a GET request, a POST request, a PUT request, and finally a DEL request. + Each of the API request methods should be familiar, with a GET retrieving data, a POST adding data, a PUT updating data, and a DEL deleting data in the API. + Let's start with the simplest request, the GET request. +3. To modify the GET request, simply select it. + First, you will want to use provide the request with the API's URL. + For our tutorial, you can use our simple API, simply by pasting `http://127.0.0.1:5000/iceCream`. + You will also want to actually retrieve something specific. + In this case, let us retrieve the 4th flavor on the menu. + Add `/4` to the end of the URL and click Send. + You should receive a dictionary containing the flavor "Cookies and Creme" unless the API was recently modified. +4. Now let us move on to something a little more complicated, the POST method. + First, you will want to select the POST method in your collection and then enter the same URL from the GET method, except instead of `/4` use `/6`. + To keep this tutorial simple and to work similarly to the API requests in Python, we will then select the Body tab below the URL. + From there you might want to select the form-data bubble to ensure that your parameters are clear and make sense, though any format you feel comfortable with should work. + On form-data, you should be able to click on the sections in the table below the first row, this will allow you to select the key and its value. + In this case, the key should be `name` and the value can be whatever flavor you want. + After entering the key and its value into the body, you can now click the Send button, and your request should process and return the flavor you entered. +5. Next, use the PUT request method. + This method will follow the same details as mentioned in step #4. + The main exception is that you should be updating the current menu item to another flavor. + Therefore, under the body tab, you should change the value to `Butter Pecan`. + Once you send this request it will return the new flavor, replacing the flavor you came up with before. +6. Finally let's get rid of the 6th flavor, with the DEL request method. + In this case, you will not have to add anything under the body tab, just keep the same URL from steps #4 and #5. + Once you have sent the request, you will be returned a message saying `"Item is deleted from the menu"`. + +This should give a basic idea of how to run HTTP requests and interact with our simple API lab template. +Feel free to experiment with the requests presented and interact with the API. + From e361c5c374f888fbdd87dcc542ced8da3d7a0785 Mon Sep 17 00:00:00 2001 From: Caleb Luce <142257447+CalebLuce@users.noreply.github.com> Date: Mon, 27 Nov 2023 12:44:07 -0500 Subject: [PATCH 16/24] Update 2 API test examples.md Edit to finish .md assignment after edits of test.py file. --- API Testing Lab/2 API test examples.md | 36 +++++++++----------------- 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/API Testing Lab/2 API test examples.md b/API Testing Lab/2 API test examples.md index 7cf3d66..8953b2b 100644 --- a/API Testing Lab/2 API test examples.md +++ b/API Testing Lab/2 API test examples.md @@ -1,9 +1,6 @@ # API Test Examples -When performing API testing, it is always crucial to include imports for requests. -Importing requests allows the following test examples to work, and thereby is defining GET, PUT, DELETE, and POST test attempts. -In this test file, we have a base URL to work with as well, which is also attached toward the top of the file. -If you were using someone else's server to test your API calls against, a variable like this would be where you would put that URL. +When performing API testing, it is always crucial to include imports for requests. Importing requests allows the following test examples to work, and thereby is defining GET, PUT, DELETE, and POST test attempts. In this test file, we have a base URL to work with as well, which is also attached toward the top of the file. If you were using someone else's server to test your API calls against, a variable like this would be where you would put that URL. ```py import requests @@ -13,44 +10,35 @@ base = "http://127.0.0.1:5000/" ```py def test_get(): response = requests.get(base + "iceCream/4") - assert response.status_code == 201 + assert response.json() == {"4": "Cotton Candy"} + assert response.status_code == 200 ``` -This test makes an HTTP GET request to a constructed endpoint. -`iceCream/4` is appended to the base URL, the JSON content is printed, and an assert statement is made. -Once the GET request is made, the server response is stored in the `response` variable. -The assertion statement for this and all tests presented asserts the HTTP status code, and passes if the statement returns True. -Otherwise, an exception is raised and indicates test failure. The terminal output for this test is shown below: +This test makes an HTTP GET request to a constructed endpoint. `iceCream/4` is appended to the base URL and two assert statements are made. Once the GET request is made, the server response is stored in the `response` variable. The first assertion statement checks to see if the JSON content of `response` is equal to `{"4": "Cotton Candy"}`, and returns True if equality is achieved, else returning False for an exception to be raised. The second assertion statement for this and all tests presented asserts the HTTP status code, and passes if the statement returns True. Otherwise, an exception is raised and indicates test failure. Do note that both assertions have to pass for the test to indicate as a success. The terminal output for this test is shown below: -![Successful Print Statement](https://i.imgur.com/X5yBKqA.png) ![test_get Successful](https://i.imgur.com/QnCPDNM.png) ## Example 2: DELETE ```py def test_delete(): response = requests.delete(base + "iceCream/5") - assert response.status_code == 204 + assert response.json() == {"message": "Item is deleted from the menu"} + assert response.status_code == 200 ``` -This test makes an HTTP DELETE request to an endpoint made by appending `iceCream/5` to the base URL, then stores the server response in the `response` variable. -There is no print statement for this test, and an assert statement is made to verify a successful deletion. -Terminal output displayed below: +This test makes an HTTP DELETE request to an endpoint made by appending `iceCream/5` to the base URL, then stores the server response in the `response` variable. Two assert statements are made to verify a successful deletion. One checks to ensure the content reflects the deletion and the other asserts matching status code. Terminal output displayed below: ![test_delete Successful](https://i.imgur.com/5l1Z9lo.png) -Within the test file, every successful test has an alternative test to ensure a failed GET, PUT, DELETE, or POST test is validated. -The next and last test example will be for an intended failure. +Within the test file, every successful test has an alternative test to ensure a failed GET, PUT, DELETE, or POST test is validated. The next and last test example will be for an intended failure. ## Example 3: DELETE (Intended Failure) ```py def test_delete_no_id(): response = requests.delete(base + "iceCream/5") - assert response.status_code != 204 + assert response.json() == {"message": "ID is invalid"} + assert response.status_code != 200 ``` -This test is performing the same actions as the test within Example 2, though the result is meant to be very different. -When the assert statement is made, any `status_code` that is not equal to the intended successful status code will result in a success. -Should the test succeed in the DELETE request, an exception is thrown and the test fails. Terminal output is displayed below: +This test is performing the same actions as the test within Example 2, though the result is meant to be very different. When the assert statements are made, the first asserts for an error concerning a lack of valid ID, the second asserts that the value of `status_code` that is not equal to the intended successful status code will result in a success. Should the test succeed in the DELETE request, an exception is thrown and the test fails. Terminal output is displayed below: ![test_delete_no_id Successful](https://i.imgur.com/CYoOXQU.png) -With these examples, you should have a better understanding of API Testing. -As mentioned prior; GET, PUT, DELETE, and POST all have alternate intended failure tests. -More examples are presented within the `test.py` file, which you may view at your own will. \ No newline at end of file +With these examples, you should have a better understanding of API Testing. As mentioned prior; GET, PUT, DELETE, and POST all have alternate intended failure tests. More examples are presented within the `test.py` file, which you may view at your own will. From 159124ae12318ab37f2239ca8a2c52bfaf0ec7f4 Mon Sep 17 00:00:00 2001 From: dlingle1 <94473147+dlingle1@users.noreply.github.com> Date: Mon, 27 Nov 2023 16:29:23 -0500 Subject: [PATCH 17/24] Add pictures to 3 API Postman.md, alongside some fixes --- API Testing Lab/3 API Postman.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/API Testing Lab/3 API Postman.md b/API Testing Lab/3 API Postman.md index 8d58c4c..b232d10 100644 --- a/API Testing Lab/3 API Postman.md +++ b/API Testing Lab/3 API Postman.md @@ -9,6 +9,9 @@ As a result, Postman is used by millions of API developers every year for all th 1. First, you must download Postman to be able to use it. Whilst there is a variety of Postman products to use, we are just going to download the free version provided. [Click here for the link](https://www.postman.com/downloads/) + + ![postman-webpage](https://github.com/Volatar/Group7-repo-projects/assets/94473147/d8337177-4a7c-47b2-b381-e116378fbf9a) + 2. After downloading Postman from that link, you must now install it. Simply click on the setup file you downloaded should install everything. 3. You will be presented with a menu that will ask you to sign up or create an account. @@ -24,23 +27,38 @@ You should however still be able to follow along. ### Step-By-Step 1. You should be in a default workspace, you can either create a new one or use the current one. However, you will want to create a new collection, in this case, a REST API basics template is perfect or you can create your own with a blank template. + + ![postman-createcollection](https://github.com/Volatar/Group7-repo-projects/assets/94473147/95f1bb16-9b53-487b-9a14-dd8eb8f71b19) + If you use the blank template you will have to create your own requests. In this example, it is recommended you use the REST API basics template. 2. You should now be presented or create 4 requests, a GET request, a POST request, a PUT request, and finally a DEL request. Each of the API request methods should be familiar, with a GET retrieving data, a POST adding data, a PUT updating data, and a DEL deleting data in the API. Let's start with the simplest request, the GET request. 3. To modify the GET request, simply select it. - First, you will want to use provide the request with the API's URL. + First, you will want to provide the request with the API's URL. For our tutorial, you can use our simple API, simply by pasting `http://127.0.0.1:5000/iceCream`. + + ![postman-url](https://github.com/Volatar/Group7-repo-projects/assets/94473147/18881a07-57df-4547-9fce-86a5536afd36) + You will also want to actually retrieve something specific. In this case, let us retrieve the 4th flavor on the menu. Add `/4` to the end of the URL and click Send. + + ![postman-send](https://github.com/Volatar/Group7-repo-projects/assets/94473147/b73541f5-9d49-42b0-9b98-20ea1eedeb97) + You should receive a dictionary containing the flavor "Cookies and Creme" unless the API was recently modified. + + ![postman-return](https://github.com/Volatar/Group7-repo-projects/assets/94473147/01a741bb-b248-47ac-a52a-b2cc0ac88761) + 4. Now let us move on to something a little more complicated, the POST method. First, you will want to select the POST method in your collection and then enter the same URL from the GET method, except instead of `/4` use `/6`. To keep this tutorial simple and to work similarly to the API requests in Python, we will then select the Body tab below the URL. From there you might want to select the form-data bubble to ensure that your parameters are clear and make sense, though any format you feel comfortable with should work. On form-data, you should be able to click on the sections in the table below the first row, this will allow you to select the key and its value. + + ![postman-body](https://github.com/Volatar/Group7-repo-projects/assets/94473147/023d59f6-2a9a-4a3f-ae91-91aadc3f3b7c) + In this case, the key should be `name` and the value can be whatever flavor you want. After entering the key and its value into the body, you can now click the Send button, and your request should process and return the flavor you entered. 5. Next, use the PUT request method. From eaa21730086c4b65cdb373384468233c9198f9f8 Mon Sep 17 00:00:00 2001 From: Jason <89305357+jslee5@users.noreply.github.com> Date: Thu, 30 Nov 2023 18:19:31 -0500 Subject: [PATCH 18/24] Update 1 API Introduction.md flask install --- API Testing Lab/1 API Introduction.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/API Testing Lab/1 API Introduction.md b/API Testing Lab/1 API Introduction.md index f07d346..1d52225 100644 --- a/API Testing Lab/1 API Introduction.md +++ b/API Testing Lab/1 API Introduction.md @@ -10,7 +10,7 @@ API Testing is crucial for ensuring not only a functional API but also a reliabl ## What Will We Use to Test? For this tutorial, we will use Pytest as our testing tool. Pytest is an efficient framework that simplifies API Testing. -To get started, make sure to install the required packages by entering `pip install pytest requests` into your terminal. +To get started, make sure to install the required packages by entering `pip install pytest requests` and `pip install Flask Flask-RESTful` into your terminal. When creating your test file, follow the Pytest convention by naming it with a `test_` prefix, and that any methods within are also begun with `test_`. Ensure that the code file includes `import requests` and `import pytest` before generating any tests. From d8f7358b675131028892e75efc6476eb63df4787 Mon Sep 17 00:00:00 2001 From: Jason <89305357+jslee5@users.noreply.github.com> Date: Thu, 30 Nov 2023 18:34:17 -0500 Subject: [PATCH 19/24] Update 3 API Postman.md small changes --- API Testing Lab/3 API Postman.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/API Testing Lab/3 API Postman.md b/API Testing Lab/3 API Postman.md index b232d10..0de2647 100644 --- a/API Testing Lab/3 API Postman.md +++ b/API Testing Lab/3 API Postman.md @@ -55,12 +55,12 @@ You should however still be able to follow along. First, you will want to select the POST method in your collection and then enter the same URL from the GET method, except instead of `/4` use `/6`. To keep this tutorial simple and to work similarly to the API requests in Python, we will then select the Body tab below the URL. From there you might want to select the form-data bubble to ensure that your parameters are clear and make sense, though any format you feel comfortable with should work. - On form-data, you should be able to click on the sections in the table below the first row, this will allow you to select the key and its value. + On form-data, you want to double-click on the sections in the table below the first row, this will allow you to select the key and its value. ![postman-body](https://github.com/Volatar/Group7-repo-projects/assets/94473147/023d59f6-2a9a-4a3f-ae91-91aadc3f3b7c) In this case, the key should be `name` and the value can be whatever flavor you want. - After entering the key and its value into the body, you can now click the Send button, and your request should process and return the flavor you entered. + After entering the key and its value into the body, you can now click the Send button, and your request should process and return the flavor you entered(We used Rocky Road as an Example). 5. Next, use the PUT request method. This method will follow the same details as mentioned in step #4. The main exception is that you should be updating the current menu item to another flavor. From bd7cad80a539cf7e2aa4e127e10fb822173dc1d5 Mon Sep 17 00:00:00 2001 From: Jason <89305357+jslee5@users.noreply.github.com> Date: Thu, 30 Nov 2023 18:36:56 -0500 Subject: [PATCH 20/24] Update 3 API Postman.md --- API Testing Lab/3 API Postman.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/API Testing Lab/3 API Postman.md b/API Testing Lab/3 API Postman.md index 0de2647..18cb6c1 100644 --- a/API Testing Lab/3 API Postman.md +++ b/API Testing Lab/3 API Postman.md @@ -55,12 +55,12 @@ You should however still be able to follow along. First, you will want to select the POST method in your collection and then enter the same URL from the GET method, except instead of `/4` use `/6`. To keep this tutorial simple and to work similarly to the API requests in Python, we will then select the Body tab below the URL. From there you might want to select the form-data bubble to ensure that your parameters are clear and make sense, though any format you feel comfortable with should work. - On form-data, you want to double-click on the sections in the table below the first row, this will allow you to select the key and its value. + On form-data, you want to **double-click** on the sections in the table below the first row, this will allow you to select the key and its value. ![postman-body](https://github.com/Volatar/Group7-repo-projects/assets/94473147/023d59f6-2a9a-4a3f-ae91-91aadc3f3b7c) In this case, the key should be `name` and the value can be whatever flavor you want. - After entering the key and its value into the body, you can now click the Send button, and your request should process and return the flavor you entered(We used Rocky Road as an Example). + After entering the key and its value into the body, you can now click the Send button, and your request should process and return the flavor you entered (We used Rocky Road as an Example). 5. Next, use the PUT request method. This method will follow the same details as mentioned in step #4. The main exception is that you should be updating the current menu item to another flavor. From 6dcfb756db3703afaa4170ff4ef13844580fb65f Mon Sep 17 00:00:00 2001 From: Rangodung <145149574+Rangodung@users.noreply.github.com> Date: Sat, 2 Dec 2023 15:06:39 -0500 Subject: [PATCH 21/24] Update test.py --- API Testing Lab/test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/API Testing Lab/test.py b/API Testing Lab/test.py index ab1b405..d397d1f 100644 --- a/API Testing Lab/test.py +++ b/API Testing Lab/test.py @@ -6,7 +6,7 @@ def test_get(): response = requests.get(base + "iceCream/4") - assert response.json() == {"4": "Cotton Candy"} + assert response.json() == {"4": "Cookies and Creme"} assert response.status_code == 200 From df0de7c16f9d32bd40a2dbf66797269804d767a5 Mon Sep 17 00:00:00 2001 From: Taylor Sanderson Date: Sun, 3 Dec 2023 12:21:40 -0500 Subject: [PATCH 22/24] some fixes to the API testing docs and code the tests were not all passing so did one minor change so they do. --- API Testing Lab/2 API test examples.md | 32 +++++++++++++++++++++----- API Testing Lab/3 API Postman.md | 19 +++++++-------- API Testing Lab/test.py | 2 +- 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/API Testing Lab/2 API test examples.md b/API Testing Lab/2 API test examples.md index 8953b2b..2134f92 100644 --- a/API Testing Lab/2 API test examples.md +++ b/API Testing Lab/2 API test examples.md @@ -1,6 +1,9 @@ # API Test Examples -When performing API testing, it is always crucial to include imports for requests. Importing requests allows the following test examples to work, and thereby is defining GET, PUT, DELETE, and POST test attempts. In this test file, we have a base URL to work with as well, which is also attached toward the top of the file. If you were using someone else's server to test your API calls against, a variable like this would be where you would put that URL. +When performing API testing, it is always crucial to include imports for requests. +Importing requests allows the following test examples to work, and thereby is defining GET, PUT, DELETE, and POST test attempts. +In this test file, we have a base URL to work with as well, which is also attached toward the top of the file. +If you were using someone else's server to test your API calls against, a variable like this would be where you would put that URL. ```py import requests @@ -13,7 +16,15 @@ def test_get(): assert response.json() == {"4": "Cotton Candy"} assert response.status_code == 200 ``` -This test makes an HTTP GET request to a constructed endpoint. `iceCream/4` is appended to the base URL and two assert statements are made. Once the GET request is made, the server response is stored in the `response` variable. The first assertion statement checks to see if the JSON content of `response` is equal to `{"4": "Cotton Candy"}`, and returns True if equality is achieved, else returning False for an exception to be raised. The second assertion statement for this and all tests presented asserts the HTTP status code, and passes if the statement returns True. Otherwise, an exception is raised and indicates test failure. Do note that both assertions have to pass for the test to indicate as a success. The terminal output for this test is shown below: +This test makes an HTTP GET request to a constructed endpoint. +`iceCream/4` is appended to the base URL and two assert statements are made. +Once the GET request is made, the server response is stored in the `response` variable. +The first assertion statement checks to see if the JSON content of `response` is equal to `{"4": "Cotton Candy"}`, and returns True if it is equal. +It returns False if it is not equal, so that an exception will be raised. +The second assertion statement for this and all tests presented asserts the HTTP status code, and passes if the statement returns True. +Otherwise, an exception is raised and indicates test failure. +Do note that both assertions have to pass for the test to indicate as a success. +The terminal output for this test is shown below: ![test_get Successful](https://i.imgur.com/QnCPDNM.png) @@ -24,11 +35,15 @@ def test_delete(): assert response.json() == {"message": "Item is deleted from the menu"} assert response.status_code == 200 ``` -This test makes an HTTP DELETE request to an endpoint made by appending `iceCream/5` to the base URL, then stores the server response in the `response` variable. Two assert statements are made to verify a successful deletion. One checks to ensure the content reflects the deletion and the other asserts matching status code. Terminal output displayed below: +This test makes an HTTP DELETE request to an endpoint made by appending `iceCream/5` to the base URL, then stores the server response in the `response` variable. +Two assert statements are made to verify a successful deletion. +One checks to ensure the content reflects the deletion and the other asserts matching status code. +Terminal output displayed below: ![test_delete Successful](https://i.imgur.com/5l1Z9lo.png) -Within the test file, every successful test has an alternative test to ensure a failed GET, PUT, DELETE, or POST test is validated. The next and last test example will be for an intended failure. +Within the test file, every successful test has an alternative test to ensure a failed GET, PUT, DELETE, or POST test is validated. +The next and last test example will be for an intended failure. ## Example 3: DELETE (Intended Failure) ```py @@ -37,8 +52,13 @@ def test_delete_no_id(): assert response.json() == {"message": "ID is invalid"} assert response.status_code != 200 ``` -This test is performing the same actions as the test within Example 2, though the result is meant to be very different. When the assert statements are made, the first asserts for an error concerning a lack of valid ID, the second asserts that the value of `status_code` that is not equal to the intended successful status code will result in a success. Should the test succeed in the DELETE request, an exception is thrown and the test fails. Terminal output is displayed below: +This test is performing the same actions as the test within Example 2, though the result is meant to be very different. +When the assert statements are made, the first asserts for an error concerning a lack of valid ID, the second asserts that the value of `status_code` is not equal to the intended successful status code. +Should the test *succeed* in the DELETE request, an exception is thrown and the test fails. +Terminal output is displayed below: ![test_delete_no_id Successful](https://i.imgur.com/CYoOXQU.png) -With these examples, you should have a better understanding of API Testing. As mentioned prior; GET, PUT, DELETE, and POST all have alternate intended failure tests. More examples are presented within the `test.py` file, which you may view at your own will. +With these examples, you should have a better understanding of API Testing. +As mentioned prior; GET, PUT, DELETE, and POST all have alternate intended failure tests. +More examples are presented within the `test.py` file, which you may view at your own will. diff --git a/API Testing Lab/3 API Postman.md b/API Testing Lab/3 API Postman.md index 18cb6c1..ee456e0 100644 --- a/API Testing Lab/3 API Postman.md +++ b/API Testing Lab/3 API Postman.md @@ -1,22 +1,23 @@ # API Testing With Postman ## Introduction to Postman Postman is an API platform that provides tools for building, testing, and using APIs. -It can make HTTP requests, save environments for later, alongside convert API code into languages like Python and JavaScript. +It can make HTTP requests, save environments for later, and convert API code into languages like Python and JavaScript. All of this functionality is handled by a simple and easy-to-use user interface. As a result, Postman is used by millions of API developers every year for all their API needs. -## How to Setup Postman +## How to Set up Postman 1. First, you must download Postman to be able to use it. - Whilst there is a variety of Postman products to use, we are just going to download the free version provided. + Whilst there is a variety of Postman products to use, we are just going to download the free version. [Click here for the link](https://www.postman.com/downloads/) ![postman-webpage](https://github.com/Volatar/Group7-repo-projects/assets/94473147/d8337177-4a7c-47b2-b381-e116378fbf9a) 2. After downloading Postman from that link, you must now install it. - Simply click on the setup file you downloaded should install everything. + Simply click on the setup file you downloaded, and it should install everything. 3. You will be presented with a menu that will ask you to sign up or create an account. - You can create an account or you can select an option towards the bottom of the window to skip this process. + You can create an account, or you can select an option towards the bottom of the window to skip this process. It should be noted that if you do not have an account associated with your Postman application, you will be limited in certain actions you can do with Postman and your UI will be different. + This lab assumes you have created an account. ## How to Test With Postman To keep things simple and to work with the basic API template we have used throughout this lab, we are going to focus on using HTTP requests with Postman. @@ -26,13 +27,13 @@ You should however still be able to follow along. ### Step-By-Step 1. You should be in a default workspace, you can either create a new one or use the current one. - However, you will want to create a new collection, in this case, a REST API basics template is perfect or you can create your own with a blank template. - + However, you will want to create a new collection, in this case, a REST API basics template is perfect, or you can create your own with a blank template. + ![postman-createcollection](https://github.com/Volatar/Group7-repo-projects/assets/94473147/95f1bb16-9b53-487b-9a14-dd8eb8f71b19) If you use the blank template you will have to create your own requests. In this example, it is recommended you use the REST API basics template. -2. You should now be presented or create 4 requests, a GET request, a POST request, a PUT request, and finally a DEL request. +2. You should now be presented with, or create yourself, four requests: a GET request, a POST request, a PUT request, and finally a DEL request. Each of the API request methods should be familiar, with a GET retrieving data, a POST adding data, a PUT updating data, and a DEL deleting data in the API. Let's start with the simplest request, the GET request. 3. To modify the GET request, simply select it. @@ -66,7 +67,7 @@ You should however still be able to follow along. The main exception is that you should be updating the current menu item to another flavor. Therefore, under the body tab, you should change the value to `Butter Pecan`. Once you send this request it will return the new flavor, replacing the flavor you came up with before. -6. Finally let's get rid of the 6th flavor, with the DEL request method. +6. Finally, let's get rid of the 6th flavor, with the DEL request method. In this case, you will not have to add anything under the body tab, just keep the same URL from steps #4 and #5. Once you have sent the request, you will be returned a message saying `"Item is deleted from the menu"`. diff --git a/API Testing Lab/test.py b/API Testing Lab/test.py index d397d1f..02a92b8 100644 --- a/API Testing Lab/test.py +++ b/API Testing Lab/test.py @@ -6,7 +6,7 @@ def test_get(): response = requests.get(base + "iceCream/4") - assert response.json() == {"4": "Cookies and Creme"} + assert response.json() != {"4": "Cookies and Creme"} assert response.status_code == 200 From e97ee3595d81c0af058b975d29e8825259d5ef5e Mon Sep 17 00:00:00 2001 From: Taylor Sanderson Date: Sun, 3 Dec 2023 12:23:14 -0500 Subject: [PATCH 23/24] added one more test --- API Testing Lab/test.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/API Testing Lab/test.py b/API Testing Lab/test.py index 02a92b8..2c32e25 100644 --- a/API Testing Lab/test.py +++ b/API Testing Lab/test.py @@ -21,6 +21,11 @@ def test_put(): assert response.json() == {"4": "Cookies and Creme"} assert response.status_code == 201 +def test_get_again(): + response = requests.get(base + "iceCream/4") + assert response.json() == {"4": "Cookies and Creme"} + assert response.status_code == 200 + def test_put_no_id(): response = requests.put(base + "iceCream/6", data={"name": "Cookies and Creme"}) From 9f33043bef80b353276c0cd8042a0985b25182c9 Mon Sep 17 00:00:00 2001 From: Taylor Sanderson Date: Sun, 3 Dec 2023 12:24:24 -0500 Subject: [PATCH 24/24] revert one of roberts changes and mine --- API Testing Lab/test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/API Testing Lab/test.py b/API Testing Lab/test.py index 2c32e25..8a4242a 100644 --- a/API Testing Lab/test.py +++ b/API Testing Lab/test.py @@ -6,7 +6,7 @@ def test_get(): response = requests.get(base + "iceCream/4") - assert response.json() != {"4": "Cookies and Creme"} + assert response.json() == {"4": "Cotton Candy"} assert response.status_code == 200 @@ -21,6 +21,7 @@ def test_put(): assert response.json() == {"4": "Cookies and Creme"} assert response.status_code == 201 + def test_get_again(): response = requests.get(base + "iceCream/4") assert response.json() == {"4": "Cookies and Creme"}