diff --git a/.learn/exercises/07.1-test-post-todo/test.py b/.learn/exercises/07.1-test-post-todo/test.py index 14530ecc..04df79e0 100644 --- a/.learn/exercises/07.1-test-post-todo/test.py +++ b/.learn/exercises/07.1-test-post-todo/test.py @@ -1,6 +1,13 @@ -import toml, pytest, os, sys, tempfile, mock, json +import toml +import pytest +import os +import sys +import tempfile +import mock +import json from flask import Flask + @pytest.fixture def client(): with mock.patch('flask.Flask', lambda x: Flask(x)): @@ -16,13 +23,16 @@ def client(): os.close(db_fd) os.unlink(app.config['DATABASE']) + @pytest.mark.it("Folder src must exist") def test_src_folder(): - assert os.path.isdir("./src/") + assert os.path.isdir("./src/") + @pytest.mark.it("File app.py must exist") def test_pipfile_exists(): - assert os.path.isfile("src/app.py") + assert os.path.isfile("src/app.py") + @pytest.mark.it("Declare a global variable todos, outside any function") def test_todos_exist(): @@ -32,16 +42,19 @@ def test_todos_exist(): except AttributeError: raise AttributeError("The variable 'todos' should exist on app.py") + @pytest.mark.it("Variable todos must be a list") def test_todos_should_be_list(): from src import app assert isinstance(app.todos, list) + @pytest.mark.it("The global todos list needs to have at least one dummy todo with the required format") def test_one_dummy(): from src import app assert len(app.todos) > 0 + @pytest.mark.it('Each item inside the global todos list should have the following format: { "label": "Sample", "done": True }') def test_items_format(): from src import app @@ -49,6 +62,7 @@ def test_items_format(): assert "label" in task assert "done" in task + @pytest.mark.it('Each item inside the global todos variable should be a dictionary with two keys: "label" and "done"') def test_label_and_done(): from src import app @@ -56,6 +70,7 @@ def test_label_and_done(): assert "label" in task assert "done" in task + @pytest.mark.it('The value of the "label" of each of the todos should be a string') def test_labels_string(): from src import app @@ -63,6 +78,7 @@ def test_labels_string(): if "label" in task: assert isinstance(task["label"], str) + @pytest.mark.it('The value of the "done" key on each todo should be a boolean') def test_done_bool(): from src import app @@ -70,6 +86,7 @@ def test_done_bool(): if "done" in task: assert isinstance(task["done"], bool) + @pytest.mark.it("The response of the hello_world function should be a json, remember to use jsonify") def test_return(client): response = client.get('/todos') @@ -86,6 +103,7 @@ def test_return(client): assert "label" in task assert "done" in task + @pytest.mark.it("The function add_new_todo should be declared") def test_add_new_todo(): from src import app @@ -93,9 +111,11 @@ def test_add_new_todo(): app.add_new_todo assert callable(app.add_new_todo) except AttributeError: - raise AttributeError("The function 'add_new_todo' should exist on app.py") + raise AttributeError( + "The function 'add_new_todo' should exist on app.py") + @pytest.mark.it("The endpoint POST /todos should exist") def test_return(client): - response = client.post('/todos') + response = client.post('/todos', json=json.dumps({})) assert response.status_code in [200, 201]