From b45b8aed24fc9dc2e1319e3b182cd89bee432673 Mon Sep 17 00:00:00 2001 From: Abby Date: Sun, 14 May 2023 10:22:01 -0400 Subject: [PATCH 01/13] added post route and also recreated database with correct completed at constriant --- app/__init__.py | 2 ++ app/models/task.py | 17 ++++++++++++++- app/routes.py | 54 +++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 71 insertions(+), 2 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 2764c4cc8..92aea0e31 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -30,5 +30,7 @@ def create_app(test_config=None): migrate.init_app(app, db) # Register Blueprints here + from .routes import task_list_bp + app.register_blueprint(task_list_bp) return app diff --git a/app/models/task.py b/app/models/task.py index c91ab281f..d92390138 100644 --- a/app/models/task.py +++ b/app/models/task.py @@ -2,4 +2,19 @@ class Task(db.Model): - task_id = db.Column(db.Integer, primary_key=True) + task_id = db.Column(db.Integer, primary_key=True, autoincrement=True) + title = db.Column(db.String) #when refactoring change to varchar + description = db.Column(db.String) # when refacoring change to varvhar + completed_at = db.Column(db.DateTime, default=None, nullable=True) + + +# wave 1 +#Our task list API should be able to work with an entity called Task. +# Tasks are entities that describe a task a user wants to complete. They contain a: +# title to name the task +# description to hold details about the task +# an optional datetime that the task is completed on +# Our goal for this wave is to be able to create, read, update, and delete different tasks. +# We will create RESTful routes for this different operations. + + diff --git a/app/routes.py b/app/routes.py index 3aae38d49..259adc68a 100644 --- a/app/routes.py +++ b/app/routes.py @@ -1 +1,53 @@ -from flask import Blueprint \ No newline at end of file +from app import db +from app.models.task import Task +from flask import Blueprint, jsonify, make_response, request + + +task_list_bp = Blueprint("task_list", __name__, url_prefix="/tasks") + + +# create +@task_list_bp.route("", methods=["POST"]) + +def post_task(): + request_body = request.get_json() + + if "title" not in request_body or "description" not in request_body: + return make_response("Invalid request", 400) + new_task = Task( + title = request_body["title"], + description = request_body["description"], + completed_at = request_body["completed_at"] + ) + + db.session.add(new_task) + db.session.commit() + + return make_response(f"New task: {new_task.title}, created", 201) + +# if not completed_at: +# return make_response({ +# "task": {"id": new_task.id, +# "title": new_task.title, +# "description": new.task.description, +# "is_complete": false} +# }, 201 +# ) + + + + + + + + + +# #read +# @task_list_bp.route("/tasks", methods=["GET"]) + + +# #update + +# # delete + + From 57c5306d8268d7a739e7af7daec40b9312ee8287 Mon Sep 17 00:00:00 2001 From: Abby Date: Sun, 14 May 2023 10:52:29 -0400 Subject: [PATCH 02/13] get all tasks complete and also figured out completed_at and is_complete dependcies --- app/routes.py | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/app/routes.py b/app/routes.py index 259adc68a..e60233d55 100644 --- a/app/routes.py +++ b/app/routes.py @@ -6,6 +6,8 @@ task_list_bp = Blueprint("task_list", __name__, url_prefix="/tasks") + + # create @task_list_bp.route("", methods=["POST"]) @@ -25,25 +27,30 @@ def post_task(): return make_response(f"New task: {new_task.title}, created", 201) -# if not completed_at: -# return make_response({ -# "task": {"id": new_task.id, -# "title": new_task.title, -# "description": new.task.description, -# "is_complete": false} -# }, 201 -# ) - - - - - - - - - # #read -# @task_list_bp.route("/tasks", methods=["GET"]) +@task_list_bp.route("", methods=["GET"]) + +def get_all_tasks(): + + task_response = [] + tasks = Task.query.all() + + for task in tasks: + if not task.completed_at: + task_response.append({"id":task.task_id, + "title":task.title, + "description": task.description, + "is_complete": False + + }) + else: + task_response.append({ + "id":task.task_id, + "title":task.title, + "description": task.description, + "completed_at":task.completed_at + }) + return jsonify(task_response) # #update From 955f257b8f83c96c9bd8da237a18d97208d6300b Mon Sep 17 00:00:00 2001 From: Abby Date: Sun, 14 May 2023 11:46:12 -0400 Subject: [PATCH 03/13] completed GET portion of CRUD --- app/routes.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/app/routes.py b/app/routes.py index e60233d55..2a49b87e7 100644 --- a/app/routes.py +++ b/app/routes.py @@ -1,6 +1,6 @@ from app import db from app.models.task import Task -from flask import Blueprint, jsonify, make_response, request +from flask import Blueprint, jsonify, make_response, request, abort task_list_bp = Blueprint("task_list", __name__, url_prefix="/tasks") @@ -36,6 +36,9 @@ def get_all_tasks(): tasks = Task.query.all() for task in tasks: + if not tasks: + return jasonify(task_response) + if not task.completed_at: task_response.append({"id":task.task_id, "title":task.title, @@ -53,6 +56,38 @@ def get_all_tasks(): return jsonify(task_response) +def validate_task(task_id): + try: + task_id = int(task_id) + except: + abort(make_response({"message": f"Book_id {task_id} invalid"}, 400)) + task = Task.query.get(task_id) + + if not task: + abort(make_response({"message": f"task: {task_id} not found"}, 404)) + return book + +#read one task/ read if empty task. + +@task_list_bp.route("/", methods=["GET"]) +def get_one_task(task_id): + task = validate_task(task_id) + if not task.completed_at: + return {"id":task.task_id, + "title":task.title, + "description": task.description, + "is_complete": False + + } + else: + return { + "id":task.task_id, + "title":task.title, + "description": task.description, + "completed_at":task.completed_at + } + + # #update # # delete From 21836be3b2e7c387e16f194b3c0717e158b5121d Mon Sep 17 00:00:00 2001 From: Abby Date: Sun, 14 May 2023 16:12:08 -0400 Subject: [PATCH 04/13] tests completed and CRUD completed --- app/routes.py | 36 ++++++++++++++++++++++++++++-------- tests/test_wave_01.py | 33 +++++++++++++++++---------------- 2 files changed, 45 insertions(+), 24 deletions(-) diff --git a/app/routes.py b/app/routes.py index 2a49b87e7..66ca17677 100644 --- a/app/routes.py +++ b/app/routes.py @@ -15,7 +15,7 @@ def post_task(): request_body = request.get_json() if "title" not in request_body or "description" not in request_body: - return make_response("Invalid request", 400) + return make_response({"details": "Invalid data"}, 400) new_task = Task( title = request_body["title"], description = request_body["description"], @@ -60,12 +60,12 @@ def validate_task(task_id): try: task_id = int(task_id) except: - abort(make_response({"message": f"Book_id {task_id} invalid"}, 400)) + abort(make_response({"message": f"Task {task_id} invalid"}, 400)) task = Task.query.get(task_id) if not task: - abort(make_response({"message": f"task: {task_id} not found"}, 404)) - return book + abort(make_response({"details": "Invalid Data"}, 404)) + return task #read one task/ read if empty task. @@ -73,23 +73,43 @@ def validate_task(task_id): def get_one_task(task_id): task = validate_task(task_id) if not task.completed_at: - return {"id":task.task_id, + return {"task": + {"id":task.task_id, "title":task.title, "description": task.description, "is_complete": False - } + }} else: - return { + return {"task":{ "id":task.task_id, "title":task.title, "description": task.description, "completed_at":task.completed_at - } + }} # #update +@task_list_bp.route("/", methods=["PUT"]) +def update_task(task_id): + + task = validate_task(task_id) + request_body = request.get_json() + + task.title = request_body["title"] + task.description = request_body["description"] + + db.session.commit() + + return make_response(f"Task {task.task_id} succsefully updated", 200) + # # delete +@task_list_bp.route("/", methods=["DELETE"]) +def delete_task(task_id): + task = validate_task(task_id) + db.session.delete(task) + db.session.commit() + return abort(make_response({"details":f"Task {task.task_id} \"{task.title}\" successfully deleted"})) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index dca626d78..ddc92afd0 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -2,7 +2,7 @@ import pytest -@pytest.mark.skip(reason="No way to test this feature yet") +# @pytest.mark.skip(reason="No way to test this feature yet") def test_get_tasks_no_saved_tasks(client): # Act response = client.get("/tasks") @@ -13,7 +13,7 @@ def test_get_tasks_no_saved_tasks(client): assert response_body == [] -@pytest.mark.skip(reason="No way to test this feature yet") +# @pytest.mark.skip(reason="No way to test this feature yet") def test_get_tasks_one_saved_tasks(client, one_task): # Act response = client.get("/tasks") @@ -32,7 +32,7 @@ def test_get_tasks_one_saved_tasks(client, one_task): ] -@pytest.mark.skip(reason="No way to test this feature yet") +# @pytest.mark.skip(reason="No way to test this feature yet") def test_get_task(client, one_task): # Act response = client.get("/tasks/1") @@ -51,7 +51,7 @@ def test_get_task(client, one_task): } -@pytest.mark.skip(reason="No way to test this feature yet") +# @pytest.mark.skip(reason="No way to test this feature yet") def test_get_task_not_found(client): # Act response = client.get("/tasks/1") @@ -59,14 +59,14 @@ def test_get_task_not_found(client): # Assert assert response.status_code == 404 - - raise Exception("Complete test with assertion about response body") + assert response_body == {"details": "Invalid Data"} + # raise Exception("Complete test with assertion about response body") # ***************************************************************** # **Complete test with assertion about response body*************** # ***************************************************************** -@pytest.mark.skip(reason="No way to test this feature yet") +# @pytest.mark.skip(reason="No way to test this feature yet") def test_create_task(client): # Act response = client.post("/tasks", json={ @@ -93,7 +93,7 @@ def test_create_task(client): assert new_task.completed_at == None -@pytest.mark.skip(reason="No way to test this feature yet") +# @pytest.mark.skip(reason="No way to test this feature yet") def test_update_task(client, one_task): # Act response = client.put("/tasks/1", json={ @@ -119,7 +119,7 @@ def test_update_task(client, one_task): assert task.completed_at == None -@pytest.mark.skip(reason="No way to test this feature yet") +# @pytest.mark.skip(reason="No way to test this feature yet") def test_update_task_not_found(client): # Act response = client.put("/tasks/1", json={ @@ -130,14 +130,15 @@ def test_update_task_not_found(client): # Assert assert response.status_code == 404 + assert response_body == {"details": "Invalid Data"} - raise Exception("Complete test with assertion about response body") + # raise Exception("Complete test with assertion about response body") # ***************************************************************** # **Complete test with assertion about response body*************** # ***************************************************************** -@pytest.mark.skip(reason="No way to test this feature yet") +# @pytest.mark.skip(reason="No way to test this feature yet") def test_delete_task(client, one_task): # Act response = client.delete("/tasks/1") @@ -152,7 +153,7 @@ def test_delete_task(client, one_task): assert Task.query.get(1) == None -@pytest.mark.skip(reason="No way to test this feature yet") +# @pytest.mark.skip(reason="No way to test this feature yet") def test_delete_task_not_found(client): # Act response = client.delete("/tasks/1") @@ -161,15 +162,15 @@ def test_delete_task_not_found(client): # Assert assert response.status_code == 404 - raise Exception("Complete test with assertion about response body") + # raise Exception("Complete test with assertion about response body") # ***************************************************************** # **Complete test with assertion about response body*************** # ***************************************************************** - + assert response_body == {'details': 'Invalid Data'} assert Task.query.all() == [] -@pytest.mark.skip(reason="No way to test this feature yet") +# @pytest.mark.skip(reason="No way to test this feature yet") def test_create_task_must_contain_title(client): # Act response = client.post("/tasks", json={ @@ -186,7 +187,7 @@ def test_create_task_must_contain_title(client): assert Task.query.all() == [] -@pytest.mark.skip(reason="No way to test this feature yet") +# @pytest.mark.skip(reason="No way to test this feature yet") def test_create_task_must_contain_description(client): # Act response = client.post("/tasks", json={ From ecd3436215ebd61865078856d54b3eefc715ead1 Mon Sep 17 00:00:00 2001 From: Abby Date: Mon, 15 May 2023 14:07:30 -0400 Subject: [PATCH 05/13] wave 2 completed, fixed wave 1 errors --- app/routes.py | 40 +++++++++++++++++++++++++++++++++++----- tests/test_wave_02.py | 4 ++-- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/app/routes.py b/app/routes.py index 66ca17677..a1f4c720d 100644 --- a/app/routes.py +++ b/app/routes.py @@ -19,13 +19,20 @@ def post_task(): new_task = Task( title = request_body["title"], description = request_body["description"], - completed_at = request_body["completed_at"] + # completed_at = request_body["completed_at"] ) db.session.add(new_task) db.session.commit() - return make_response(f"New task: {new_task.title}, created", 201) + return jsonify({ + "task": { + "id": new_task.task_id, + "title": new_task.title, + "is_complete": False, + "description": new_task.description + } + }), 201 # #read @task_list_bp.route("", methods=["GET"]) @@ -33,7 +40,17 @@ def post_task(): def get_all_tasks(): task_response = [] - tasks = Task.query.all() + sort_query = request.args.get("sort") + + if sort_query == 'asc': + tasks = Task.query.order_by(Task.title).all() + elif sort_query == 'desc': + tasks = Task.query.order_by(Task.title.desc()).all() + + else: + tasks = Task.query.all() + + for task in tasks: if not tasks: @@ -100,9 +117,22 @@ def update_task(task_id): task.description = request_body["description"] db.session.commit() + + if not task.completed_at: + return jsonify({"task": + {"id":task.task_id, + "title":task.title, + "description": task.description, + "is_complete": False - return make_response(f"Task {task.task_id} succsefully updated", 200) - + }}), 200 + else: + return jsonify({"task":{ + "id":task.task_id, + "title":task.title, + "description": task.description, + "completed_at":task.completed_at + }}), 200 # # delete @task_list_bp.route("/", methods=["DELETE"]) diff --git a/tests/test_wave_02.py b/tests/test_wave_02.py index a087e0909..651e3aebd 100644 --- a/tests/test_wave_02.py +++ b/tests/test_wave_02.py @@ -1,7 +1,7 @@ import pytest -@pytest.mark.skip(reason="No way to test this feature yet") +# @pytest.mark.skip(reason="No way to test this feature yet") def test_get_tasks_sorted_asc(client, three_tasks): # Act response = client.get("/tasks?sort=asc") @@ -29,7 +29,7 @@ def test_get_tasks_sorted_asc(client, three_tasks): ] -@pytest.mark.skip(reason="No way to test this feature yet") +# @pytest.mark.skip(reason="No way to test this feature yet") def test_get_tasks_sorted_desc(client, three_tasks): # Act response = client.get("/tasks?sort=desc") From 2102e2096eded77c4e23b60043beb5ed40443b6c Mon Sep 17 00:00:00 2001 From: Abby Date: Mon, 15 May 2023 14:34:55 -0400 Subject: [PATCH 06/13] mark_complete endpoint done --- app/routes.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/app/routes.py b/app/routes.py index a1f4c720d..4d46ca6b2 100644 --- a/app/routes.py +++ b/app/routes.py @@ -134,6 +134,38 @@ def update_task(task_id): "completed_at":task.completed_at }}), 200 +@task_list_bp.route("//mark_complete", methods=["PATCH"]) +def update_task_to_complete(task_id): + task = validate_task(task_id) + + db.session.commit() + + + if not task.completed_at: + return jsonify({"task": + {"id":task.task_id, + "title":task.title, + "description": task.description, + "is_complete": True + + }}), 200 + +@task_list_bp.route("//mark_incomplete", methods=["PATCH"]) + +def update_task_to_incomplete(task_id): + + task = validate_task(task_id) + db.session.commit() + + if task.completed_at: + return jsonify({"task": + {"id":task.task_id, + "title":task.title, + "description": task.description, + "is_complete": False + + }}), 200 + # # delete @task_list_bp.route("/", methods=["DELETE"]) def delete_task(task_id): From 35731936d527c81fbe9f2ab7bd7177656601f3d0 Mon Sep 17 00:00:00 2001 From: Abby Date: Mon, 15 May 2023 22:07:20 -0400 Subject: [PATCH 07/13] tests updates, goals added, wave 3 no bugs --- app/__init__.py | 2 + app/models/goal.py | 20 +++++++ app/models/task.py | 20 +++++++ app/routes.py | 129 +++++++++++++++++++++++++++++++++++------- tests/test_wave_01.py | 5 -- tests/test_wave_03.py | 27 ++++----- tests/test_wave_05.py | 40 ++++++------- 7 files changed, 181 insertions(+), 62 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 92aea0e31..3285b1878 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -32,5 +32,7 @@ def create_app(test_config=None): # Register Blueprints here from .routes import task_list_bp app.register_blueprint(task_list_bp) + from .routes import goals_bp + app.register_blueprint(goals_bp) return app diff --git a/app/models/goal.py b/app/models/goal.py index b0ed11dd8..8e8731ecf 100644 --- a/app/models/goal.py +++ b/app/models/goal.py @@ -3,3 +3,23 @@ class Goal(db.Model): goal_id = db.Column(db.Integer, primary_key=True) + title = db.Column(db.String) + + + + @classmethod + def from_dict(cls, goal_data): + new_goal = Goal( + title=goal_data["title"] + ) + + return new_goal + + + + + + def to_dict_goal(self): + return{ "goal": { + "id":self.goal_id, + "title":self.title}} \ No newline at end of file diff --git a/app/models/task.py b/app/models/task.py index d92390138..a9dfe01a4 100644 --- a/app/models/task.py +++ b/app/models/task.py @@ -8,6 +8,26 @@ class Task(db.Model): completed_at = db.Column(db.DateTime, default=None, nullable=True) + @classmethod + def from_dict(cls, task_data): + new_task = Task( + title=task_data["title"], + description=task_data["description"], + completed_at=task_data["completed_at"] + ) + + return new_task + + + + + + def to_dict(self): + return{ "task": { + "id":self.task_id, + "title":self.title, + "description":self.description, + "is_complete": True if self.completed_at else False}} # wave 1 #Our task list API should be able to work with an entity called Task. # Tasks are entities that describe a task a user wants to complete. They contain a: diff --git a/app/routes.py b/app/routes.py index 4d46ca6b2..4aed842b5 100644 --- a/app/routes.py +++ b/app/routes.py @@ -1,14 +1,17 @@ from app import db from app.models.task import Task +from app.models.goal import Goal from flask import Blueprint, jsonify, make_response, request, abort +from datetime import datetime task_list_bp = Blueprint("task_list", __name__, url_prefix="/tasks") +goals_bp = Blueprint("goals_list", __name__, url_prefix="/goals") -# create +# create tasks @task_list_bp.route("", methods=["POST"]) def post_task(): @@ -34,7 +37,31 @@ def post_task(): } }), 201 -# #read + +#create goals +@goals_bp.route("", methods=["POST"]) + +def post_goal(): + + request_body = request.get_json() + if "title" not in request_body: + return make_response({"details": "Invalid data"}, 400) + + new_goal = Goal( + title = request_body["title"] + ) + db.session.add(new_goal) + db.session.commit() + + + return jsonify({ + "goal": { + "id": new_goal.goal_id, + "title": new_goal.title} }), 201 + + + +# #read all tasks @task_list_bp.route("", methods=["GET"]) def get_all_tasks(): @@ -83,7 +110,43 @@ def validate_task(task_id): if not task: abort(make_response({"details": "Invalid Data"}, 404)) return task + +#validate goal id +def validate_goal(goal_id): + try: + goal_id = int(goal_id) + except: + abort(make_response({"message": f"Task {task_id} invalid"}, 400)) + goal = Goal.query.get(goal_id) + + if not goal: + abort(make_response({"details": "Invalid Data"}, 404)) + return goal + +#read all goals +@goals_bp.route("", methods=["GET"]) +def read_all_goals(): + goal_response = [] + goals = Goal.query.all() + + for goal in goals: + if not goals: + return jsonify(goal_response) + else: + goal_response.append({ "goal": { + "id":goal.goal_id, + "title":goal.title}}) + + return jsonify(goal_response) + + + + + + + + #read one task/ read if empty task. @task_list_bp.route("/", methods=["GET"]) @@ -105,8 +168,16 @@ def get_one_task(task_id): "completed_at":task.completed_at }} +#read one goal +@goals_bp.route("/", methods=["GET"]) +def get_one_goal(goal_id): + goal = validate_goal(goal_id) + + return jsonify({"id":goal.goal_id, + "title":goal.title}), 200 -# #update + +# #update task @task_list_bp.route("/", methods=["PUT"]) def update_task(task_id): @@ -134,39 +205,49 @@ def update_task(task_id): "completed_at":task.completed_at }}), 200 + +#update goal +@goals_bp.route("/", methods=["PUT"]) +def update_goal(goal_id): + + goal = validate_goal(goal_id) + request_body = request.get_json() + + goal.title = request_body["title"] + + db.session.commit + return goal.to_dict_goal() + + @task_list_bp.route("//mark_complete", methods=["PATCH"]) def update_task_to_complete(task_id): task = validate_task(task_id) + task.completed_at = datetime.now() + + db.session.commit() + return task.to_dict(), 200 + - if not task.completed_at: - return jsonify({"task": - {"id":task.task_id, - "title":task.title, - "description": task.description, - "is_complete": True - }}), 200 @task_list_bp.route("//mark_incomplete", methods=["PATCH"]) def update_task_to_incomplete(task_id): task = validate_task(task_id) - db.session.commit() + + task.completed_at = None - if task.completed_at: - return jsonify({"task": - {"id":task.task_id, - "title":task.title, - "description": task.description, - "is_complete": False + db.session.commit() + return task.to_dict() + + - }}), 200 -# # delete +# delete task @task_list_bp.route("/", methods=["DELETE"]) def delete_task(task_id): task = validate_task(task_id) @@ -175,3 +256,13 @@ def delete_task(task_id): db.session.commit() return abort(make_response({"details":f"Task {task.task_id} \"{task.title}\" successfully deleted"})) + +#delete goal: +@goals_bp.route("/", methods=["DELETE"]) +def delete_goal(goal_id): + goal = validate_goal(goal_id) + + db.session.delete(goal) + db.session.commit() + + return abort(make_response({"details":f"Task {goal.goal_id} \"{goal.title}\" successfully deleted"})) \ No newline at end of file diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index ddc92afd0..108d3c207 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -161,11 +161,6 @@ def test_delete_task_not_found(client): # Assert assert response.status_code == 404 - - # raise Exception("Complete test with assertion about response body") - # ***************************************************************** - # **Complete test with assertion about response body*************** - # ***************************************************************** assert response_body == {'details': 'Invalid Data'} assert Task.query.all() == [] diff --git a/tests/test_wave_03.py b/tests/test_wave_03.py index 32d379822..917c6e0d4 100644 --- a/tests/test_wave_03.py +++ b/tests/test_wave_03.py @@ -5,7 +5,7 @@ import pytest -@pytest.mark.skip(reason="No way to test this feature yet") +# @pytest.mark.skip(reason="No way to test this feature yet") def test_mark_complete_on_incomplete_task(client, one_task): # Arrange """ @@ -42,7 +42,7 @@ def test_mark_complete_on_incomplete_task(client, one_task): assert Task.query.get(1).completed_at -@pytest.mark.skip(reason="No way to test this feature yet") +# @pytest.mark.skip(reason="No way to test this feature yet") def test_mark_incomplete_on_complete_task(client, completed_task): # Act response = client.patch("/tasks/1/mark_incomplete") @@ -62,7 +62,7 @@ def test_mark_incomplete_on_complete_task(client, completed_task): assert Task.query.get(1).completed_at == None -@pytest.mark.skip(reason="No way to test this feature yet") +# @pytest.mark.skip(reason="No way to test this feature yet") def test_mark_complete_on_completed_task(client, completed_task): # Arrange """ @@ -99,7 +99,7 @@ def test_mark_complete_on_completed_task(client, completed_task): assert Task.query.get(1).completed_at -@pytest.mark.skip(reason="No way to test this feature yet") +# @pytest.mark.skip(reason="No way to test this feature yet") def test_mark_incomplete_on_incomplete_task(client, one_task): # Act response = client.patch("/tasks/1/mark_incomplete") @@ -119,7 +119,7 @@ def test_mark_incomplete_on_incomplete_task(client, one_task): assert Task.query.get(1).completed_at == None -@pytest.mark.skip(reason="No way to test this feature yet") +# @pytest.mark.skip(reason="No way to test this feature yet") def test_mark_complete_missing_task(client): # Act response = client.patch("/tasks/1/mark_complete") @@ -127,14 +127,10 @@ def test_mark_complete_missing_task(client): # Assert assert response.status_code == 404 + assert response_body == {"details": "Invalid Data"}, 404 - raise Exception("Complete test with assertion about response body") - # ***************************************************************** - # **Complete test with assertion about response body*************** - # ***************************************************************** - -@pytest.mark.skip(reason="No way to test this feature yet") +# @pytest.mark.skip(reason="No way to test this feature yet") def test_mark_incomplete_missing_task(client): # Act response = client.patch("/tasks/1/mark_incomplete") @@ -143,7 +139,8 @@ def test_mark_incomplete_missing_task(client): # Assert assert response.status_code == 404 - raise Exception("Complete test with assertion about response body") - # ***************************************************************** - # **Complete test with assertion about response body*************** - # ***************************************************************** + # raise Exception("Complete test with assertion about response body") + # # ***************************************************************** + # # **Complete test with assertion about response body*************** + # # ***************************************************************** + assert response_body == {"details": "Invalid Data"}, 404 diff --git a/tests/test_wave_05.py b/tests/test_wave_05.py index aee7c52a1..80939fba6 100644 --- a/tests/test_wave_05.py +++ b/tests/test_wave_05.py @@ -1,7 +1,7 @@ import pytest -@pytest.mark.skip(reason="No way to test this feature yet") +# @pytest.mark.skip(reason="No way to test this feature yet") def test_get_goals_no_saved_goals(client): # Act response = client.get("/goals") @@ -12,7 +12,7 @@ def test_get_goals_no_saved_goals(client): assert response_body == [] -@pytest.mark.skip(reason="No way to test this feature yet") +# @pytest.mark.skip(reason="No way to test this feature yet") def test_get_goals_one_saved_goal(client, one_goal): # Act response = client.get("/goals") @@ -29,7 +29,7 @@ def test_get_goals_one_saved_goal(client, one_goal): ] -@pytest.mark.skip(reason="No way to test this feature yet") +# @pytest.mark.skip(reason="No way to test this feature yet") def test_get_goal(client, one_goal): # Act response = client.get("/goals/1") @@ -46,22 +46,19 @@ def test_get_goal(client, one_goal): } -@pytest.mark.skip(reason="test to be completed by student") +# @pytest.mark.skip(reason="test to be completed by student") def test_get_goal_not_found(client): pass # Act response = client.get("/goals/1") response_body = response.get_json() - raise Exception("Complete test") - # Assert - # ---- Complete Test ---- - # assertion 1 goes here - # assertion 2 goes here - # ---- Complete Test ---- + assert response.status_code == 404 + assert response_body == {'details': 'Invalid Data'} + assert Goal.query.all() == [] -@pytest.mark.skip(reason="No way to test this feature yet") +# @pytest.mark.skip(reason="No way to test this feature yet") def test_create_goal(client): # Act response = client.post("/goals", json={ @@ -80,7 +77,7 @@ def test_create_goal(client): } -@pytest.mark.skip(reason="test to be completed by student") +# @pytest.mark.skip(reason="test to be completed by student") def test_update_goal(client, one_goal): raise Exception("Complete test") # Act @@ -94,7 +91,7 @@ def test_update_goal(client, one_goal): # ---- Complete Assertions Here ---- -@pytest.mark.skip(reason="test to be completed by student") +# @pytest.mark.skip(reason="test to be completed by student") def test_update_goal_not_found(client): raise Exception("Complete test") # Act @@ -130,21 +127,18 @@ def test_delete_goal(client, one_goal): # ***************************************************************** -@pytest.mark.skip(reason="test to be completed by student") +# @pytest.mark.skip(reason="test to be completed by student") def test_delete_goal_not_found(client): - raise Exception("Complete test") - - # Act - # ---- Complete Act Here ---- + response = client.delete("/goals/1") + response_body = response.get_json() # Assert - # ---- Complete Assertions Here ---- - # assertion 1 goes here - # assertion 2 goes here - # ---- Complete Assertions Here ---- + assert response.status_code == 404 + assert response_body == {'details': 'Invalid Data'} + assert Goal.query.all() == [] -@pytest.mark.skip(reason="No way to test this feature yet") +# @pytest.mark.skip(reason="No way to test this feature yet") def test_create_goal_missing_title(client): # Act response = client.post("/goals", json={}) From 115ffc18a1ebe0023919bb70951722bd844fa84a Mon Sep 17 00:00:00 2001 From: Abby Date: Wed, 17 May 2023 08:13:11 -0400 Subject: [PATCH 08/13] fixed tests wave 5 --- tests/test_wave_05.py | 55 +++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/tests/test_wave_05.py b/tests/test_wave_05.py index 80939fba6..35534a6e8 100644 --- a/tests/test_wave_05.py +++ b/tests/test_wave_05.py @@ -1,3 +1,4 @@ +from app.models.goal import Goal import pytest @@ -55,8 +56,6 @@ def test_get_goal_not_found(client): assert response.status_code == 404 assert response_body == {'details': 'Invalid Data'} - assert Goal.query.all() == [] - # @pytest.mark.skip(reason="No way to test this feature yet") def test_create_goal(client): @@ -75,36 +74,46 @@ def test_create_goal(client): "title": "My New Goal" } } + new_goal = Goal.query.get(1) + assert new_goal + assert new_goal.title == "My New Goal" # @pytest.mark.skip(reason="test to be completed by student") def test_update_goal(client, one_goal): - raise Exception("Complete test") - # Act - # ---- Complete Act Here ---- + # raise Exception("Complete test") + response = client.put("/goals/1", json={ + "title": "Build a habit of going outside daily" + }) + response_body = response.get_json() # Assert - # ---- Complete Assertions Here ---- - # assertion 1 goes here - # assertion 2 goes here - # assertion 3 goes here - # ---- Complete Assertions Here ---- + assert response.status_code == 200 + assert "goal" in response_body + assert response_body == { + "goal": { + "id": 1, + "title": "Build a habit of going outside daily" + } + } + goal = Goal.query.get(1) + assert goal.title == "Build a habit of going outside daily" # @pytest.mark.skip(reason="test to be completed by student") def test_update_goal_not_found(client): - raise Exception("Complete test") - # Act - # ---- Complete Act Here ---- + response = client.put("/goals/1", json={ + "title": "Build a habit of going outside daily" + + }) + response_body = response.get_json() # Assert - # ---- Complete Assertions Here ---- - # assertion 1 goes here - # assertion 2 goes here - # ---- Complete Assertions Here ---- + assert response.status_code == 404 + assert response_body == {"details": "Invalid Data"} -@pytest.mark.skip(reason="No way to test this feature yet") +# @pytest.mark.skip(reason="No way to test this feature yet") def test_delete_goal(client, one_goal): # Act response = client.delete("/goals/1") @@ -118,13 +127,7 @@ def test_delete_goal(client, one_goal): } # Check that the goal was deleted - response = client.get("/goals/1") - assert response.status_code == 404 - - raise Exception("Complete test with assertion about response body") - # ***************************************************************** - # **Complete test with assertion about response body*************** - # ***************************************************************** + assert Goal.query.get(1) == None # @pytest.mark.skip(reason="test to be completed by student") @@ -136,6 +139,7 @@ def test_delete_goal_not_found(client): assert response.status_code == 404 assert response_body == {'details': 'Invalid Data'} assert Goal.query.all() == [] + # @pytest.mark.skip(reason="No way to test this feature yet") @@ -149,3 +153,4 @@ def test_create_goal_missing_title(client): assert response_body == { "details": "Invalid data" } + assert Goal.query.all() == [] \ No newline at end of file From 7494df7e4e10b350652136cf97443679c6071996 Mon Sep 17 00:00:00 2001 From: Abby Date: Wed, 17 May 2023 08:13:38 -0400 Subject: [PATCH 09/13] Slack api implementation --- app/routes.py | 89 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 82 insertions(+), 7 deletions(-) diff --git a/app/routes.py b/app/routes.py index 4aed842b5..68e29fc69 100644 --- a/app/routes.py +++ b/app/routes.py @@ -3,8 +3,12 @@ from app.models.goal import Goal from flask import Blueprint, jsonify, make_response, request, abort from datetime import datetime +import requests +import json +from dotenv import load_dotenv +import os - +load_dotenv() task_list_bp = Blueprint("task_list", __name__, url_prefix="/tasks") goals_bp = Blueprint("goals_list", __name__, url_prefix="/goals") @@ -60,6 +64,60 @@ def post_goal(): "title": new_goal.title} }), 201 +# create nested post +@goals_bp.route("//tasks", methods=["POST"]) + +def create_task(goal_id): + goal = validate_goal(goal_id) + request_body = request.get_json() + + result = {"id": goal.goal_id, + "task_ids": request_body["task_ids"] +} + + for task_id in request_body["task_ids"]: + task = validate_task(task_id) + goal.tasks.append(task) + + + db.session.commit() + + return result + + +# create nested get + +@goals_bp.route("/tasks", methods=["GET"]) +def get_tasks_one_goal(goal_id): + goal = validate_goal(goal_id) + goal_response = [] + task_response = [] + tasks = Task.query.all() + if "title" not in request_body or "id" not in request_body: + return make_response({"details": "Invalid data"}, 400) + for task in tasks: + if not tasks: + return jasonify(task_response) + + if not task.completed_at: + task_response.append({"id":task.task_id, + "title":task.title, + "description": task.description, + "is_complete": False + + }) + else: + task_response.append({ + "id":task.task_id, + "title":task.title, + "description": task.description, + "completed_at":task.completed_at + }) + + goal_response.append(task_response) + return jsonify(task_response) + + # #read all tasks @task_list_bp.route("", methods=["GET"]) @@ -116,7 +174,7 @@ def validate_goal(goal_id): try: goal_id = int(goal_id) except: - abort(make_response({"message": f"Task {task_id} invalid"}, 400)) + abort(make_response({"message": f"Goal {goal_id} invalid"}, 400)) goal = Goal.query.get(goal_id) if not goal: @@ -134,9 +192,9 @@ def read_all_goals(): if not goals: return jsonify(goal_response) else: - goal_response.append({ "goal": { + goal_response.append({ "id":goal.goal_id, - "title":goal.title}}) + "title":goal.title}) return jsonify(goal_response) @@ -173,8 +231,11 @@ def get_one_task(task_id): def get_one_goal(goal_id): goal = validate_goal(goal_id) - return jsonify({"id":goal.goal_id, - "title":goal.title}), 200 + + return jsonify({"goal":{"id": goal.goal_id, + "title":goal.title}}) + + # #update task @@ -225,6 +286,20 @@ def update_task_to_complete(task_id): task.completed_at = datetime.now() + url = "https://slack.com/api/chat.postMessage" + + payload = json.dumps({ + "channel": "C0581AUJACV", + "text": (f"Someone just completed the task {task.title}") + }) + headers = { + 'Authorization': os.environ.get("SLACK_API_TOKEN"), + 'Content-Type': 'application/json' + } + + response = requests.request("POST", url, headers=headers, data=payload) + + print(response.text) db.session.commit() @@ -265,4 +340,4 @@ def delete_goal(goal_id): db.session.delete(goal) db.session.commit() - return abort(make_response({"details":f"Task {goal.goal_id} \"{goal.title}\" successfully deleted"})) \ No newline at end of file + return abort(make_response({"details":f"Goal {goal.goal_id} \"{goal.title}\" successfully deleted"})) \ No newline at end of file From 41f446694d4dab32a94264f17b5d3d23d83ccf20 Mon Sep 17 00:00:00 2001 From: Abby Date: Wed, 17 May 2023 08:14:44 -0400 Subject: [PATCH 10/13] fix model errors --- app/models/goal.py | 4 +++- app/models/task.py | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/goal.py b/app/models/goal.py index 8e8731ecf..6afa241a5 100644 --- a/app/models/goal.py +++ b/app/models/goal.py @@ -2,8 +2,10 @@ class Goal(db.Model): - goal_id = db.Column(db.Integer, primary_key=True) + goal_id = db.Column(db.Integer, primary_key=True, autoincrement=True) title = db.Column(db.String) + tasks = db.relationship("Task", back_populates="goal", lazy=True) + diff --git a/app/models/task.py b/app/models/task.py index a9dfe01a4..f88ae02d6 100644 --- a/app/models/task.py +++ b/app/models/task.py @@ -6,6 +6,8 @@ class Task(db.Model): title = db.Column(db.String) #when refactoring change to varchar description = db.Column(db.String) # when refacoring change to varvhar completed_at = db.Column(db.DateTime, default=None, nullable=True) + goal_id = db.Column(db.Integer, db.ForeignKey('goal.goal_id')) + goal = db.relationship("Goal", back_populates="tasks") @classmethod From 1b08b3467bf8119f6820750b631d004f5fb92393 Mon Sep 17 00:00:00 2001 From: Abby Date: Wed, 17 May 2023 08:16:13 -0400 Subject: [PATCH 11/13] cleaned up test file comments --- tests/test_wave_01.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 108d3c207..7bf967ab1 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -51,7 +51,7 @@ def test_get_task(client, one_task): } -# @pytest.mark.skip(reason="No way to test this feature yet") +# @pytest.mark.skip(reason="No way to test this featgit ure yet") def test_get_task_not_found(client): # Act response = client.get("/tasks/1") @@ -60,11 +60,7 @@ def test_get_task_not_found(client): # Assert assert response.status_code == 404 assert response_body == {"details": "Invalid Data"} - # raise Exception("Complete test with assertion about response body") - # ***************************************************************** - # **Complete test with assertion about response body*************** - # ***************************************************************** - + # @pytest.mark.skip(reason="No way to test this feature yet") def test_create_task(client): @@ -132,10 +128,7 @@ def test_update_task_not_found(client): assert response.status_code == 404 assert response_body == {"details": "Invalid Data"} - # raise Exception("Complete test with assertion about response body") - # ***************************************************************** - # **Complete test with assertion about response body*************** - # ***************************************************************** + # @pytest.mark.skip(reason="No way to test this feature yet") From fefdf050f35dfe3f6866dab9b5a256e9675e1814 Mon Sep 17 00:00:00 2001 From: Abby Date: Wed, 17 May 2023 17:35:19 -0400 Subject: [PATCH 12/13] All passing! All done --- app/models/task.py | 2 +- app/routes.py | 208 +++++++++++------------------------------- tests/test_wave_06.py | 20 ++-- 3 files changed, 64 insertions(+), 166 deletions(-) diff --git a/app/models/task.py b/app/models/task.py index f88ae02d6..6ee9749a3 100644 --- a/app/models/task.py +++ b/app/models/task.py @@ -25,7 +25,7 @@ def from_dict(cls, task_data): def to_dict(self): - return{ "task": { + return{"task": { "id":self.task_id, "title":self.title, "description":self.description, diff --git a/app/routes.py b/app/routes.py index 68e29fc69..54dc8a5e5 100644 --- a/app/routes.py +++ b/app/routes.py @@ -11,16 +11,32 @@ load_dotenv() task_list_bp = Blueprint("task_list", __name__, url_prefix="/tasks") goals_bp = Blueprint("goals_list", __name__, url_prefix="/goals") +#validating the task_id +def validate_task(task_id): + try: + task_id = int(task_id) + except: + abort(make_response({"message": f"Task {task_id} invalid"}, 400)) + task = Task.query.get(task_id) + if not task: + abort(make_response({"details": "Invalid Data"}, 404)) + return task - - - +#validate goal_id +def validate_goal(goal_id): + try: + goal_id = int(goal_id) + except: + abort(make_response({"message": f"Goal {goal_id} invalid"}, 400)) + goal = Goal.query.get(goal_id) + if not goal: + abort(make_response({"details": "Invalid Data"}, 404)) + return goal + # create tasks @task_list_bp.route("", methods=["POST"]) - def post_task(): request_body = request.get_json() - if "title" not in request_body or "description" not in request_body: return make_response({"details": "Invalid data"}, 400) new_task = Task( @@ -28,10 +44,8 @@ def post_task(): description = request_body["description"], # completed_at = request_body["completed_at"] ) - db.session.add(new_task) db.session.commit() - return jsonify({ "task": { "id": new_task.task_id, @@ -41,106 +55,77 @@ def post_task(): } }), 201 - #create goals @goals_bp.route("", methods=["POST"]) - def post_goal(): - request_body = request.get_json() if "title" not in request_body: return make_response({"details": "Invalid data"}, 400) - new_goal = Goal( title = request_body["title"] ) db.session.add(new_goal) db.session.commit() - - return jsonify({ "goal": { "id": new_goal.goal_id, "title": new_goal.title} }), 201 - - # create nested post @goals_bp.route("//tasks", methods=["POST"]) - def create_task(goal_id): goal = validate_goal(goal_id) request_body = request.get_json() - result = {"id": goal.goal_id, "task_ids": request_body["task_ids"] } - for task_id in request_body["task_ids"]: task = validate_task(task_id) goal.tasks.append(task) - - db.session.commit() - return result - -# create nested get - +# create nested get, singular goal, with its many tasks @goals_bp.route("/tasks", methods=["GET"]) def get_tasks_one_goal(goal_id): goal = validate_goal(goal_id) - goal_response = [] task_response = [] - tasks = Task.query.all() - if "title" not in request_body or "id" not in request_body: - return make_response({"details": "Invalid data"}, 400) - for task in tasks: - if not tasks: - return jasonify(task_response) + + + for task in goal.tasks: if not task.completed_at: - task_response.append({"id":task.task_id, - "title":task.title, - "description": task.description, - "is_complete": False + task_response.append({ + "id": task.task_id, + "goal_id":goal.goal_id, + "title":task.title, + "description": task.description, + "is_complete": False }) else: task_response.append({ - "id":task.task_id, - "title":task.title, - "description": task.description, - "completed_at":task.completed_at - }) - - goal_response.append(task_response) - return jsonify(task_response) - - - + "id": task.task_id, + "goal_id": goal.goal_id, + "title": task.title, + "description": task.description, + "completed_at":task.completed_at + }) + return jsonify({ + "id": goal.goal_id, + "title": goal.title, + "tasks": task_response}) # #read all tasks @task_list_bp.route("", methods=["GET"]) - def get_all_tasks(): - task_response = [] sort_query = request.args.get("sort") - if sort_query == 'asc': tasks = Task.query.order_by(Task.title).all() elif sort_query == 'desc': tasks = Task.query.order_by(Task.title.desc()).all() - else: tasks = Task.query.all() - - - for task in tasks: - if not tasks: - return jasonify(task_response) - if not task.completed_at: task_response.append({"id":task.task_id, "title":task.title, @@ -157,31 +142,6 @@ def get_all_tasks(): }) return jsonify(task_response) - -def validate_task(task_id): - try: - task_id = int(task_id) - except: - abort(make_response({"message": f"Task {task_id} invalid"}, 400)) - task = Task.query.get(task_id) - - if not task: - abort(make_response({"details": "Invalid Data"}, 404)) - return task - -#validate goal id -def validate_goal(goal_id): - try: - goal_id = int(goal_id) - except: - abort(make_response({"message": f"Goal {goal_id} invalid"}, 400)) - goal = Goal.query.get(goal_id) - - if not goal: - abort(make_response({"details": "Invalid Data"}, 404)) - return goal - - #read all goals @goals_bp.route("", methods=["GET"]) def read_all_goals(): @@ -197,35 +157,21 @@ def read_all_goals(): "title":goal.title}) return jsonify(goal_response) - - - - - - - - #read one task/ read if empty task. - @task_list_bp.route("/", methods=["GET"]) def get_one_task(task_id): task = validate_task(task_id) - if not task.completed_at: - return {"task": - {"id":task.task_id, - "title":task.title, - "description": task.description, - "is_complete": False - - }} + # goal = validate_goal(goal_id) + + if task.goal_id: + return{"task": { + "id":task.task_id, + "goal_id": task.goal_id, + "title":task.title, + "description":task.description, + "is_complete": True if task.completed_at else False}} else: - return {"task":{ - "id":task.task_id, - "title":task.title, - "description": task.description, - "completed_at":task.completed_at - }} - + return task.to_dict() #read one goal @goals_bp.route("/", methods=["GET"]) def get_one_goal(goal_id): @@ -234,60 +180,33 @@ def get_one_goal(goal_id): return jsonify({"goal":{"id": goal.goal_id, "title":goal.title}}) - - - - # #update task @task_list_bp.route("/", methods=["PUT"]) def update_task(task_id): task = validate_task(task_id) request_body = request.get_json() - task.title = request_body["title"] task.description = request_body["description"] - db.session.commit() - - if not task.completed_at: - return jsonify({"task": - {"id":task.task_id, - "title":task.title, - "description": task.description, - "is_complete": False - - }}), 200 - else: - return jsonify({"task":{ - "id":task.task_id, - "title":task.title, - "description": task.description, - "completed_at":task.completed_at - }}), 200 - + return task.to_dict() #update goal @goals_bp.route("/", methods=["PUT"]) def update_goal(goal_id): - goal = validate_goal(goal_id) request_body = request.get_json() - goal.title = request_body["title"] - db.session.commit return goal.to_dict_goal() - +#mark_complete endpoint with slack api implementation @task_list_bp.route("//mark_complete", methods=["PATCH"]) def update_task_to_complete(task_id): task = validate_task(task_id) - task.completed_at = datetime.now() - + #slack implementation url = "https://slack.com/api/chat.postMessage" - payload = json.dumps({ "channel": "C0581AUJACV", "text": (f"Someone just completed the task {task.title}") @@ -296,48 +215,31 @@ def update_task_to_complete(task_id): 'Authorization': os.environ.get("SLACK_API_TOKEN"), 'Content-Type': 'application/json' } - response = requests.request("POST", url, headers=headers, data=payload) - print(response.text) - db.session.commit() - return task.to_dict(), 200 - - - +#mark_incomplete endpoint @task_list_bp.route("//mark_incomplete", methods=["PATCH"]) - def update_task_to_incomplete(task_id): - task = validate_task(task_id) - task.completed_at = None - db.session.commit() return task.to_dict() - - - # delete task @task_list_bp.route("/", methods=["DELETE"]) def delete_task(task_id): task = validate_task(task_id) - db.session.delete(task) db.session.commit() - return abort(make_response({"details":f"Task {task.task_id} \"{task.title}\" successfully deleted"})) #delete goal: @goals_bp.route("/", methods=["DELETE"]) def delete_goal(goal_id): goal = validate_goal(goal_id) - db.session.delete(goal) db.session.commit() - return abort(make_response({"details":f"Goal {goal.goal_id} \"{goal.title}\" successfully deleted"})) \ No newline at end of file diff --git a/tests/test_wave_06.py b/tests/test_wave_06.py index 8afa4325e..b957d64c7 100644 --- a/tests/test_wave_06.py +++ b/tests/test_wave_06.py @@ -2,7 +2,7 @@ import pytest -@pytest.mark.skip(reason="No way to test this feature yet") +# @pytest.mark.skip(reason="No way to test this feature yet") def test_post_task_ids_to_goal(client, one_goal, three_tasks): # Act response = client.post("/goals/1/tasks", json={ @@ -23,7 +23,7 @@ def test_post_task_ids_to_goal(client, one_goal, three_tasks): assert len(Goal.query.get(1).tasks) == 3 -@pytest.mark.skip(reason="No way to test this feature yet") +# @pytest.mark.skip(reason="No way to test this feature yet") def test_post_task_ids_to_goal_already_with_goals(client, one_task_belongs_to_one_goal, three_tasks): # Act response = client.post("/goals/1/tasks", json={ @@ -42,22 +42,18 @@ def test_post_task_ids_to_goal_already_with_goals(client, one_task_belongs_to_on assert len(Goal.query.get(1).tasks) == 2 -@pytest.mark.skip(reason="No way to test this feature yet") +# @pytest.mark.skip(reason="No way to test this feature yet") def test_get_tasks_for_specific_goal_no_goal(client): # Act response = client.get("/goals/1/tasks") response_body = response.get_json() - # Assert + # Assert{'details': 'Invalid Data'} assert response.status_code == 404 - - raise Exception("Complete test with assertion about response body") - # ***************************************************************** - # **Complete test with assertion about response body*************** - # ***************************************************************** + assert response_body == { "details": "Invalid Data"} -@pytest.mark.skip(reason="No way to test this feature yet") +# @pytest.mark.skip(reason="No way to test this feature yet") def test_get_tasks_for_specific_goal_no_tasks(client, one_goal): # Act response = client.get("/goals/1/tasks") @@ -74,7 +70,7 @@ def test_get_tasks_for_specific_goal_no_tasks(client, one_goal): } -@pytest.mark.skip(reason="No way to test this feature yet") +# @pytest.mark.skip(reason="No way to test this feature yet") def test_get_tasks_for_specific_goal(client, one_task_belongs_to_one_goal): # Act response = client.get("/goals/1/tasks") @@ -99,7 +95,7 @@ def test_get_tasks_for_specific_goal(client, one_task_belongs_to_one_goal): } -@pytest.mark.skip(reason="No way to test this feature yet") +# @pytest.mark.skip(reason="No way to test this feature yet") def test_get_task_includes_goal_id(client, one_task_belongs_to_one_goal): response = client.get("/tasks/1") response_body = response.get_json() From ea1d5bdf9022b32a10c0647cc40733d5f0328137 Mon Sep 17 00:00:00 2001 From: Abby Date: Wed, 17 May 2023 20:11:27 -0400 Subject: [PATCH 13/13] render_db_attachement --- app/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 3285b1878..b649b8056 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -15,8 +15,10 @@ def create_app(test_config=None): app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False if test_config is None: - app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get( - "SQLALCHEMY_DATABASE_URI") + app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get("RENDER_DB_URI") + + # app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get( + # "SQLALCHEMY_DATABASE_URI") else: app.config["TESTING"] = True app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get(