|
| 1 | +import pytest |
| 2 | +from werkzeug.exceptions import HTTPException |
| 3 | +from app.models.goal import Goal |
| 4 | +from app.models.task import Task |
| 5 | +from app.routes.route_utilities import create_model, validate_model |
| 6 | + |
| 7 | +@pytest.mark.skip(reason="No way to test this feature yet") |
| 8 | +def test_route_utilities_validate_model_with_task(client, three_tasks): |
| 9 | + #Act |
| 10 | + task_1 = validate_model(Task, 1) |
| 11 | + task_2 = validate_model(Task, 2) |
| 12 | + task_3 = validate_model(Task, 3) |
| 13 | + |
| 14 | + #Assert |
| 15 | + assert task_1.id == 1 |
| 16 | + assert task_1.title == "Water the garden 🌷" |
| 17 | + assert task_1.description == "" |
| 18 | + assert task_1.completed_at is None |
| 19 | + |
| 20 | + assert task_2.id == 2 |
| 21 | + assert task_2.title == "Answer forgotten email 📧" |
| 22 | + |
| 23 | + assert task_3.id == 3 |
| 24 | + assert task_3.title == "Pay my outstanding tickets 😭" |
| 25 | + |
| 26 | + |
| 27 | +@pytest.mark.skip(reason="No way to test this feature yet") |
| 28 | +def test_route_utilities_validate_model_with_task_invalid_id(client, three_tasks): |
| 29 | + #Act & Assert |
| 30 | + # Calling `validate_model` without being invoked by a route will |
| 31 | + # cause an `HTTPException` when an `abort` statement is reached |
| 32 | + with pytest.raises(HTTPException) as e: |
| 33 | + result_task = validate_model(Task, "One") |
| 34 | + |
| 35 | + # Test that the correct status code and response message are returned |
| 36 | + response = e.value.get_response() |
| 37 | + assert response.status_code == 400 |
| 38 | + |
| 39 | + raise Exception("Complete test with an assertion about the response body") |
| 40 | + # ***************************************************************************** |
| 41 | + # ** Complete test with an assertion about the response body **************** |
| 42 | + # ***************************************************************************** |
| 43 | + |
| 44 | +@pytest.mark.skip(reason="No way to test this feature yet") |
| 45 | +def test_route_utilities_validate_model_with_task_missing_id(client, three_tasks): |
| 46 | + #Act & Assert |
| 47 | + with pytest.raises(HTTPException) as e: |
| 48 | + result_task = validate_model(Task, 4) |
| 49 | + |
| 50 | + raise Exception("Complete test with assertion status code and response body") |
| 51 | + # ***************************************************************************** |
| 52 | + # **Complete test with assertion about status code response body*************** |
| 53 | + # ***************************************************************************** |
| 54 | + |
| 55 | + |
| 56 | +@pytest.mark.skip(reason="No way to test this feature yet") |
| 57 | +def test_route_utilities_validate_model_with_goal(client, one_goal): |
| 58 | + #Act |
| 59 | + goal_1 = validate_model(Goal, 1) |
| 60 | + |
| 61 | + #Assert |
| 62 | + assert goal_1.id == 1 |
| 63 | + assert goal_1.title == "Build a habit of going outside daily" |
| 64 | + |
| 65 | +@pytest.mark.skip(reason="No way to test this feature yet") |
| 66 | +def test_route_utilities_validate_model_with_goal_invalid_id(client, one_goal): |
| 67 | + #Act & Assert |
| 68 | + with pytest.raises(HTTPException) as e: |
| 69 | + result_task = validate_model(Goal, "One") |
| 70 | + |
| 71 | + raise Exception("Complete test with assertion status code and response body") |
| 72 | + # ***************************************************************************** |
| 73 | + # **Complete test with assertion about status code response body*************** |
| 74 | + # ***************************************************************************** |
| 75 | + |
| 76 | +@pytest.mark.skip(reason="No way to test this feature yet") |
| 77 | +def test_route_utilities_validate_model_with_goal_missing_id(client, one_goal): |
| 78 | + #Act & Assert |
| 79 | + with pytest.raises(HTTPException) as e: |
| 80 | + result_task = validate_model(Goal, 4) |
| 81 | + |
| 82 | + raise Exception("Complete test with assertion status code and response body") |
| 83 | + # ***************************************************************************** |
| 84 | + # **Complete test with assertion about status code response body*************** |
| 85 | + # ***************************************************************************** |
| 86 | + |
| 87 | +@pytest.mark.skip(reason="No way to test this feature yet") |
| 88 | +def test_route_utilities_create_model_with_task(client): |
| 89 | + #Arrange |
| 90 | + request_body = { |
| 91 | + "title": "Make the bed", |
| 92 | + "description": "", |
| 93 | + "completed_at": None |
| 94 | + } |
| 95 | + |
| 96 | + #Act |
| 97 | + response = create_model(Task, request_body) |
| 98 | + |
| 99 | + #Assert |
| 100 | + assert response[0]["id"] == 1 #create_model returns a tuple |
| 101 | + assert response[0]["title"] == "Make the bed" |
| 102 | + assert response[0]["description"] == "" |
| 103 | + assert response[0]["is_complete"] == False |
| 104 | + assert response[1] == 201 |
| 105 | + |
| 106 | +@pytest.mark.skip(reason="No way to test this feature yet") |
| 107 | +def test_route_utilities_create_model_with_task_missing_title(client): |
| 108 | + #Arrange |
| 109 | + request_body = { |
| 110 | + "description": "", |
| 111 | + "completed_at": None |
| 112 | + } |
| 113 | + |
| 114 | + #Act |
| 115 | + with pytest.raises(HTTPException) as e: |
| 116 | + create_model(Task, request_body) |
| 117 | + |
| 118 | + response = e.value.get_response() |
| 119 | + assert response.status_code == 400 |
| 120 | + assert response.get_json() == {"details": "Invalid data"} |
| 121 | + |
| 122 | + |
| 123 | +@pytest.mark.skip(reason="No way to test this feature yet") |
| 124 | +def test_route_utilities_create_model_with_goal(client): |
| 125 | + #Arrange |
| 126 | + request_body = { |
| 127 | + "title": "Seize the Day!" |
| 128 | + } |
| 129 | + |
| 130 | + #Act |
| 131 | + response = create_model(Goal, request_body) |
| 132 | + |
| 133 | + #Assert |
| 134 | + assert response[0]["id"] == 1 #create_model returns a tuple |
| 135 | + assert response[0]["title"] == "Seize the Day!" |
| 136 | + assert response[1] == 201 |
| 137 | + |
| 138 | +@pytest.mark.skip(reason="No way to test this feature yet") |
| 139 | +def test_route_utilities_create_model_with_goal_missing_title(client): |
| 140 | + #Arrange |
| 141 | + request_body = { |
| 142 | + } |
| 143 | + |
| 144 | + #Act |
| 145 | + with pytest.raises(HTTPException) as e: |
| 146 | + create_model(Goal, request_body) |
| 147 | + |
| 148 | + raise Exception("Complete test with assertion status code and response body") |
| 149 | + # ***************************************************************************** |
| 150 | + # **Complete test with assertion about status code response body*************** |
| 151 | + # ***************************************************************************** |
0 commit comments