Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions ada-project-docs/wave_07.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
92 changes: 91 additions & 1 deletion tests/test_wave_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
62 changes: 62 additions & 0 deletions tests/test_wave_05.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
151 changes: 151 additions & 0 deletions tests/test_wave_07.py
Original file line number Diff line number Diff line change
@@ -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***************
# *****************************************************************************