示例#1
0
async def test_projects_endpoint_returns_list_of_projects(database, client):
    # Given
    await database.execute_many(
        query=projects_table.insert(),
        values=[
            {
                "name": "Project One"
            },
            {
                "name": "Project Two"
            },
        ],
    )

    # When
    response = await client.get("/projects")

    # Then
    assert response.status_code == 200
    assert response.json() == [
        {
            "id": 1,
            "name": "Project One"
        },
        {
            "id": 2,
            "name": "Project Two"
        },
    ]
示例#2
0
async def test_task_endpoint_returns_task(database, client):
    # Given
    await database.execute(
        query=projects_table.insert(),
        values={
            "id": 1,
            "name": "Project One"
        },
    )

    await database.execute(
        query=tasks_table.insert(),
        values={
            "id": 1,
            "project_id": 1,
            "name": "Task One"
        },
    )

    # When
    response = await client.get("/projects/1/tasks/1")

    # Then
    assert response.status_code == 200
    assert response.json() == {
        "id": 1,
        "name": "Task One",
        "completedAt": None
    }
示例#3
0
def main(rebuild_db: bool = True):
    if rebuild_db:
        drop_tables(engine)
        create_tables(engine)

    connection = engine.connect()

    connection.execute(
        projects_table.insert(),
        {
            "id": 1,
            "name": "Project One"
        },
    )

    connection.execute(
        tasks_table.insert(),
        [
            {
                "id": 1,
                "project_id": 1,
                "name": "Learn Python",
                "completed_at": date(2021, 1, 6),
            },
            {
                "id": 2,
                "project_id": 1,
                "name": "Learn Domain Driven Design",
                "completed_at": None,
            },
            {
                "id": 3,
                "project_id": 1,
                "name": "Do the shopping",
                "completed_at": None,
            },
            {
                "id": 4,
                "project_id": 1,
                "name": "Clean the house",
                "completed_at": None,
            },
        ],
    )

    tasks = connection.execute(tasks_table.select())

    typer.echo(
        tabulate(
            [[
                task.id,
                task.name,
                task.completed_at,
            ] for task in tasks],
            headers=["Id", "Name", "Completed At"],
        ), )
    typer.echo("\nSeeding completed 🚀")
示例#4
0
async def test_tasks_endpoint(database, client):
    # Given
    await database.execute(
        query=projects_table.insert(),
        values={
            "id": 1,
            "name": "Project One"
        },
    )

    await database.execute_many(
        query=tasks_table.insert(),
        values=[
            {
                "id": 1,
                "project_id": 1,
                "name": "Task One"
            },
            {
                "id": 2,
                "project_id": 1,
                "name": "Task Two",
                "completed_at": date(2021, 1, 6),
            },
            {
                "id": 3,
                "project_id": 1,
                "name": "Task Three"
            },
        ],
    )

    # When
    response = await client.get("/projects/1/tasks")

    # Then
    assert response.status_code == 200
    assert response.json() == [
        {
            "id": 1,
            "name": "Task One",
            "completedAt": None
        },
        {
            "id": 2,
            "name": "Task Two",
            "completedAt": "2021-01-06"
        },
        {
            "id": 3,
            "name": "Task Three",
            "completedAt": None
        },
    ]
示例#5
0
async def test_project_endpoint_returns_the_project(database, client):
    # Given
    await database.execute(
        query=projects_table.insert(),
        values={
            "id": 1,
            "name": "Project One"
        },
    )

    # When
    response = await client.get("/projects/1")

    # Then
    assert response.status_code == 200
    assert response.json() == {"id": 1, "name": "Project One"}