diff --git a/ada-project-docs/wave_07.md b/ada-project-docs/wave_07.md index d3a5a5b8d..e67a4cd6d 100644 --- a/ada-project-docs/wave_07.md +++ b/ada-project-docs/wave_07.md @@ -1,11 +1,17 @@ -# Wave 7: Deployment +# Wave 7: Deployment and Refactoring ## Goal -Our goal is to make our project accessible online! +Our goal for wave 7 is twofold. We want to implement refactors that will reduce redundancy between our routes and we want our API to be available online! ## Requirements +### Refactoring +Using the Wave 07 tests and the refactoring examples we went over in class with Flasky, refactor your code in a way that removes redundancies across your Task and Goal routes. + +Keep in mind that you may need to rework your project file structure and adjust your imports to make the tests work. + +### Deployment Deploy this project to Render. When deploying a web service to Render, it will try to be helpful and set the `Language` field for you, but it doesn't always select the correct option. diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 55475db79..117245696 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -2,6 +2,97 @@ from app.db import db import pytest +@pytest.mark.skip(reason="No way to test this feature yet") +def test_task_to_dict(): + #Arrange + new_task = Task(id = 1, title="Make My Bed", + description="Start the day off right!", + completed_at=None) + + #Act + task_dict = new_task.to_dict() + + #Assert + assert len(task_dict) == 4 + assert task_dict["id"] == 1 + assert task_dict["title"] == "Make My Bed" + assert task_dict["description"] == "Start the day off right!" + assert task_dict["is_complete"] == False + +@pytest.mark.skip(reason="No way to test this feature yet") +def test_task_to_dict_missing_id(): + #Arrange + new_task = Task(title="Make My Bed", + description="Start the day off right!", + completed_at=None) + + #Act + task_dict = new_task.to_dict() + + #Assert + assert len(task_dict) == 4 + assert task_dict["id"] is None + assert task_dict["title"] == "Make My Bed" + assert task_dict["description"] == "Start the day off right!" + assert task_dict["is_complete"] == False + +@pytest.mark.skip(reason="No way to test this feature yet") +def test_task_to_dict_missing_title(): + #Arrange + new_task = Task(id = 1, + description="Start the day off right!", + completed_at=None) + + #Act + task_dict = new_task.to_dict() + + #Assert + assert len(task_dict) == 4 + assert task_dict["id"] == 1 + assert task_dict["title"] is None + assert task_dict["description"] == "Start the day off right!" + assert task_dict["is_complete"] == False + +@pytest.mark.skip(reason="No way to test this feature yet") +def test_task_from_dict(): + #Arrange + task_dict = { + "title": "Make My Bed", + "description": "Start the day off right!", + "is_complete": False + } + + #Act + task_obj = Task.from_dict(task_dict) + + #Assert + assert task_obj.title == "Make My Bed" + assert task_obj.description == "Start the day off right!" + assert task_obj.completed_at is None + +@pytest.mark.skip(reason="No way to test this feature yet") +def test_task_from_dict_no_title(): + #Arrange + task_dict = { + "description": "Start the day off right!", + "is_complete": False + } + + #Act & Assert + with pytest.raises(KeyError, match = 'title'): + Task.from_dict(task_dict) + +@pytest.mark.skip(reason="No way to test this feature yet") +def test_task_from_dict_no_description(): + #Arrange + task_dict = { + "title": "Make My Bed", + "is_complete": False + } + + #Act & Assert + with pytest.raises(KeyError, match = 'description'): + Task.from_dict(task_dict) @pytest.mark.skip(reason="No way to test this feature yet") def test_get_tasks_no_saved_tasks(client): @@ -96,7 +187,6 @@ def test_create_task(client): assert new_task.description == "Test Description" assert new_task.completed_at == None - @pytest.mark.skip(reason="No way to test this feature yet") def test_update_task(client, one_task): # Act diff --git a/tests/test_wave_05.py b/tests/test_wave_05.py index 222d10cf0..4818cfbfd 100644 --- a/tests/test_wave_05.py +++ b/tests/test_wave_05.py @@ -1,5 +1,67 @@ +from app.models.goal import Goal import pytest +@pytest.mark.skip(reason="No way to test this feature yet") +def test_goal_to_dict(): + #Arrange + new_goal = Goal(id=1, title="Seize the Day!") + + #Act + goal_dict = new_goal.to_dict() + + #Assert + assert goal_dict["id"] == 1 + assert goal_dict["title"] == "Seize the Day!" + +@pytest.mark.skip(reason="No way to test this feature yet") +def test_goal_to_dict_no_id(): + #Arrange + new_goal = Goal(title="Seize the Day!") + + #Act + goal_dict = new_goal.to_dict() + + #Assert + assert goal_dict["id"] is None + assert goal_dict["title"] == "Seize the Day!" + +@pytest.mark.skip(reason="No way to test this feature yet") +def test_goal_to_dict_no_title(): + #Arrange + new_goal = Goal(id=1) + + #Act + goal_dict = new_goal.to_dict() + + #Assert + assert goal_dict["id"] == 1 + assert goal_dict["title"] is None + + + +@pytest.mark.skip(reason="No way to test this feature yet") +def test_goal_from_dict(): + #Arrange + goal_dict = { + "title": "Seize the Day!", + } + + #Act + goal_obj = Goal.from_dict(goal_dict) + + #Assert + assert goal_obj.title == "Seize the Day!" + +@pytest.mark.skip(reason="No way to test this feature yet") +def test_goal_from_dict_no_title(): + #Arrange + goal_dict = { + } + + #Act & Assert + with pytest.raises(KeyError, match = 'title'): + Goal.from_dict(goal_dict) + @pytest.mark.skip(reason="No way to test this feature yet") def test_get_goals_no_saved_goals(client): diff --git a/tests/test_wave_07.py b/tests/test_wave_07.py new file mode 100644 index 000000000..7e7cef55a --- /dev/null +++ b/tests/test_wave_07.py @@ -0,0 +1,151 @@ +import pytest +from werkzeug.exceptions import HTTPException +from app.models.goal import Goal +from app.models.task import Task +from app.routes.route_utilities import create_model, validate_model + +@pytest.mark.skip(reason="No way to test this feature yet") +def test_route_utilities_validate_model_with_task(client, three_tasks): + #Act + task_1 = validate_model(Task, 1) + task_2 = validate_model(Task, 2) + task_3 = validate_model(Task, 3) + + #Assert + assert task_1.id == 1 + assert task_1.title == "Water the garden 🌷" + assert task_1.description == "" + assert task_1.completed_at is None + + assert task_2.id == 2 + assert task_2.title == "Answer forgotten email 📧" + + assert task_3.id == 3 + assert task_3.title == "Pay my outstanding tickets 😭" + + +@pytest.mark.skip(reason="No way to test this feature yet") +def test_route_utilities_validate_model_with_task_invalid_id(client, three_tasks): + #Act & Assert + # Calling `validate_model` without being invoked by a route will + # cause an `HTTPException` when an `abort` statement is reached + with pytest.raises(HTTPException) as e: + result_task = validate_model(Task, "One") + + # Test that the correct status code and response message are returned + response = e.value.get_response() + assert response.status_code == 400 + + raise Exception("Complete test with an assertion about the response body") + # ***************************************************************************** + # ** Complete test with an assertion about the response body **************** + # ***************************************************************************** + +@pytest.mark.skip(reason="No way to test this feature yet") +def test_route_utilities_validate_model_with_task_missing_id(client, three_tasks): + #Act & Assert + with pytest.raises(HTTPException) as e: + result_task = validate_model(Task, 4) + + raise Exception("Complete test with assertion status code and response body") + # ***************************************************************************** + # **Complete test with assertion about status code response body*************** + # ***************************************************************************** + + +@pytest.mark.skip(reason="No way to test this feature yet") +def test_route_utilities_validate_model_with_goal(client, one_goal): + #Act + goal_1 = validate_model(Goal, 1) + + #Assert + assert goal_1.id == 1 + assert goal_1.title == "Build a habit of going outside daily" + +@pytest.mark.skip(reason="No way to test this feature yet") +def test_route_utilities_validate_model_with_goal_invalid_id(client, one_goal): + #Act & Assert + with pytest.raises(HTTPException) as e: + result_task = validate_model(Goal, "One") + + raise Exception("Complete test with assertion status code and response body") + # ***************************************************************************** + # **Complete test with assertion about status code response body*************** + # ***************************************************************************** + +@pytest.mark.skip(reason="No way to test this feature yet") +def test_route_utilities_validate_model_with_goal_missing_id(client, one_goal): + #Act & Assert + with pytest.raises(HTTPException) as e: + result_task = validate_model(Goal, 4) + + raise Exception("Complete test with assertion status code and response body") + # ***************************************************************************** + # **Complete test with assertion about status code response body*************** + # ***************************************************************************** + +@pytest.mark.skip(reason="No way to test this feature yet") +def test_route_utilities_create_model_with_task(client): + #Arrange + request_body = { + "title": "Make the bed", + "description": "", + "completed_at": None + } + + #Act + response = create_model(Task, request_body) + + #Assert + assert response[0]["id"] == 1 #create_model returns a tuple + assert response[0]["title"] == "Make the bed" + assert response[0]["description"] == "" + assert response[0]["is_complete"] == False + assert response[1] == 201 + +@pytest.mark.skip(reason="No way to test this feature yet") +def test_route_utilities_create_model_with_task_missing_title(client): + #Arrange + request_body = { + "description": "", + "completed_at": None + } + + #Act + with pytest.raises(HTTPException) as e: + create_model(Task, request_body) + + response = e.value.get_response() + assert response.status_code == 400 + assert response.get_json() == {"details": "Invalid data"} + + +@pytest.mark.skip(reason="No way to test this feature yet") +def test_route_utilities_create_model_with_goal(client): + #Arrange + request_body = { + "title": "Seize the Day!" + } + + #Act + response = create_model(Goal, request_body) + + #Assert + assert response[0]["id"] == 1 #create_model returns a tuple + assert response[0]["title"] == "Seize the Day!" + assert response[1] == 201 + +@pytest.mark.skip(reason="No way to test this feature yet") +def test_route_utilities_create_model_with_goal_missing_title(client): + #Arrange + request_body = { + } + + #Act + with pytest.raises(HTTPException) as e: + create_model(Goal, request_body) + + raise Exception("Complete test with assertion status code and response body") + # ***************************************************************************** + # **Complete test with assertion about status code response body*************** + # *****************************************************************************