コード例 #1
0
def test_deleting_a_task_really_removes_it_from_tasks_list():
    TASKS.append(copy(DEFAULT_TASK.dict()))
    client = TestClient(app)
    client.delete(f"/tasks/{DEFAULT_TASK.id}")
    resp = client.get(f"/tasks/{DEFAULT_TASK.id}")
    assert resp.status_code == status.HTTP_404_NOT_FOUND
    TASKS.clear()
コード例 #2
0
def test_creating_task_should_return_an_unique_id():
    client = TestClient(app)
    task_payload1 = {"title": "nice title", "description": "hey apple"}
    task_payload2 = {"title": "title monster", "description": "something"}
    resp1 = client.post("/tasks", json=task_payload1)
    resp2 = client.post("/tasks", json=task_payload2)
    assert resp1.json()["id"] != resp2.json()["id"]
    TASKS.clear()
コード例 #3
0
def test_create_task_endpoint_should_return_created_task_itself():
    client = TestClient(app)
    task_payload = {"title": "nice title", "description": "hey apple"}
    resp = client.post("/tasks", json=task_payload)
    resp_json = resp.json()
    resp_json.pop("id")
    resp_json.pop("status")
    assert resp_json == task_payload
    TASKS.clear()
コード例 #4
0
def test_listing_tasks_sorted_by_description():
    TASKS.append(Task(id=uuid4(), title="xpto", description="banana").dict())
    TASKS.append(Task(id=uuid4(), title="xpto", description="melon").dict())
    TASKS.append(Task(id=uuid4(), title="xpto", description="apple").dict())
    client = TestClient(app)
    resp = client.get("/tasks?sort=true&sort_by=description")
    description_list = list(map(lambda task: task["description"], resp.json()))
    assert description_list == sorted(description_list)
    TASKS.clear()
コード例 #5
0
def test_listing_tasks_with_sort_query_param_sorted_by_title():
    TASKS.append(Task(id=uuid4(), title="banana", description="xpto").dict())
    TASKS.append(Task(id=uuid4(), title="melon", description="xpto").dict())
    TASKS.append(Task(id=uuid4(), title="apple", description="xpto").dict())
    client = TestClient(app)
    resp = client.get("/tasks?sort=true")
    titles_list = list(map(lambda task: task["title"], resp.json()))
    assert titles_list == sorted(titles_list)
    TASKS.clear()
コード例 #6
0
async def delete_task(task_id: UUID):
    tasks_to_remove = list(filter(lambda task: task["id"] == task_id, TASKS))
    if not tasks_to_remove:
        raise HTTPException(status_code=404, detail="Not found")
    TASKS.remove(tasks_to_remove[0])
    return
コード例 #7
0
def test_listing_tasks_return_one_task_with_status():
    TASKS.append(copy(DEFAULT_TASK.dict()))
    client = TestClient(app)
    resp = client.get("/tasks")
    assert "status" in resp.json().pop()
    TASKS.clear()
コード例 #8
0
def test_deleting_a_task_correctly_return_204():
    TASKS.append(copy(DEFAULT_TASK.dict()))
    client = TestClient(app)
    resp = client.delete(f"/tasks/{DEFAULT_TASK.id}")
    assert resp.status_code == status.HTTP_204_NO_CONTENT
    TASKS.clear()
コード例 #9
0
def test_retrieving_task_ok_return_200():
    TASKS.append(copy(DEFAULT_TASK.dict()))
    client = TestClient(app)
    resp = client.get(f"/tasks/{DEFAULT_TASK.id}")
    assert resp.status_code == status.HTTP_200_OK
    TASKS.clear()
コード例 #10
0
def test_creating_task_should_add_to_tasks_list():
    client = TestClient(app)
    task_payload = {"title": "nice title", "description": "hey apple"}
    client.post("/tasks", json=task_payload)
    assert len(TASKS) == 1
    TASKS.clear()
コード例 #11
0
def test_creating_task_should_return_201():
    client = TestClient(app)
    task_payload = {"title": "nice title", "description": "hey apple"}
    resp = client.post("/tasks", json=task_payload)
    assert resp.status_code == status.HTTP_201_CREATED
    TASKS.clear()
コード例 #12
0
def test_created_task_has_default_status_not_done():
    client = TestClient(app)
    task_payload = {"title": "nice title", "description": "hey apple"}
    resp = client.post("/tasks", json=task_payload)
    assert resp.json()["status"] == PossibleStatus.not_done
    TASKS.clear()