Skip to content

Commit 96e5382

Browse files
Merge pull request #84 from AngelesRocks/iss-1555
[ID:1555] Test working correctly
2 parents c7f4571 + 70f4431 commit 96e5382

File tree

1 file changed

+25
-5
lines changed
  • .learn/exercises/07.1-test-post-todo

1 file changed

+25
-5
lines changed

.learn/exercises/07.1-test-post-todo/test.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
import toml, pytest, os, sys, tempfile, mock, json
1+
import toml
2+
import pytest
3+
import os
4+
import sys
5+
import tempfile
6+
import mock
7+
import json
28
from flask import Flask
39

10+
411
@pytest.fixture
512
def client():
613
with mock.patch('flask.Flask', lambda x: Flask(x)):
@@ -16,13 +23,16 @@ def client():
1623
os.close(db_fd)
1724
os.unlink(app.config['DATABASE'])
1825

26+
1927
@pytest.mark.it("Folder src must exist")
2028
def test_src_folder():
21-
assert os.path.isdir("./src/")
29+
assert os.path.isdir("./src/")
30+
2231

2332
@pytest.mark.it("File app.py must exist")
2433
def test_pipfile_exists():
25-
assert os.path.isfile("src/app.py")
34+
assert os.path.isfile("src/app.py")
35+
2636

2737
@pytest.mark.it("Declare a global variable todos, outside any function")
2838
def test_todos_exist():
@@ -32,44 +42,51 @@ def test_todos_exist():
3242
except AttributeError:
3343
raise AttributeError("The variable 'todos' should exist on app.py")
3444

45+
3546
@pytest.mark.it("Variable todos must be a list")
3647
def test_todos_should_be_list():
3748
from src import app
3849
assert isinstance(app.todos, list)
3950

51+
4052
@pytest.mark.it("The global todos list needs to have at least one dummy todo with the required format")
4153
def test_one_dummy():
4254
from src import app
4355
assert len(app.todos) > 0
4456

57+
4558
@pytest.mark.it('Each item inside the global todos list should have the following format: { "label": "Sample", "done": True }')
4659
def test_items_format():
4760
from src import app
4861
for task in app.todos:
4962
assert "label" in task
5063
assert "done" in task
5164

65+
5266
@pytest.mark.it('Each item inside the global todos variable should be a dictionary with two keys: "label" and "done"')
5367
def test_label_and_done():
5468
from src import app
5569
for task in app.todos:
5670
assert "label" in task
5771
assert "done" in task
5872

73+
5974
@pytest.mark.it('The value of the "label" of each of the todos should be a string')
6075
def test_labels_string():
6176
from src import app
6277
for task in app.todos:
6378
if "label" in task:
6479
assert isinstance(task["label"], str)
6580

81+
6682
@pytest.mark.it('The value of the "done" key on each todo should be a boolean')
6783
def test_done_bool():
6884
from src import app
6985
for task in app.todos:
7086
if "done" in task:
7187
assert isinstance(task["done"], bool)
7288

89+
7390
@pytest.mark.it("The response of the hello_world function should be a json, remember to use jsonify")
7491
def test_return(client):
7592
response = client.get('/todos')
@@ -86,16 +103,19 @@ def test_return(client):
86103
assert "label" in task
87104
assert "done" in task
88105

106+
89107
@pytest.mark.it("The function add_new_todo should be declared")
90108
def test_add_new_todo():
91109
from src import app
92110
try:
93111
app.add_new_todo
94112
assert callable(app.add_new_todo)
95113
except AttributeError:
96-
raise AttributeError("The function 'add_new_todo' should exist on app.py")
114+
raise AttributeError(
115+
"The function 'add_new_todo' should exist on app.py")
116+
97117

98118
@pytest.mark.it("The endpoint POST /todos should exist")
99119
def test_return(client):
100-
response = client.post('/todos')
120+
response = client.post('/todos', json=json.dumps({}))
101121
assert response.status_code in [200, 201]

0 commit comments

Comments
 (0)