def test_fake_repository():
    repository = FakeRepository(projects=[
        build_project(id=1, name="First"),
    ])

    repository.create(build_project(name="Foo"))
    repository.create(build_project(name="Bar"))

    assert len(repository.list()) == 3

    project = repository.get(1)
    assert project is not None
    assert project.id == 1
Ejemplo n.º 2
0
    def test_passes_if_max_incomplete_tasks_number_is_none(self):
        project = build_project(max_incomplete_tasks_number=None)

        try:
            ensure.project_has_allowed_number_of_incomplete_tasks(project)
        except MaxIncompleteTasksNumberIsReached:
            pytest.fail()
Ejemplo n.º 3
0
def test_get_task_raises_error():
    project = build_project(name="Test Project")
    task = build_task(id=1, name="One")
    project.tasks = [task, build_task(id=2, name="Two")]

    with pytest.raises(TaskNotFoundError):
        project.get_task(3)
Ejemplo n.º 4
0
    def test_fails_if_max_incomplete_tasks_number_is_reached(self):
        project = build_project(max_incomplete_tasks_number=2)
        project.tasks.append(build_task())
        project.tasks.append(build_task())

        with pytest.raises(MaxIncompleteTasksNumberIsReached):
            ensure.project_has_allowed_number_of_incomplete_tasks(project)
Ejemplo n.º 5
0
def test_incomplete_task():
    project = build_project(name="Test Project")
    task = build_task(id=1, name="One", completed_at=date(2021, 1, 17))
    project.tasks = [task]

    task = project.incomplete_task(id=1)

    assert task.completed_at is None
Ejemplo n.º 6
0
def test_add_task():
    project = build_project(name="Test Project")
    assert len(project.tasks) == 0

    task = project.add_task(name="Testing")

    assert len(project.tasks) == 1
    assert project.tasks == [task]
Ejemplo n.º 7
0
    def test_passes_if_max_incomplete_tasks_number_is_not_reached(self):
        project = build_project(max_incomplete_tasks_number=2)
        project.tasks.append(build_task())

        try:
            ensure.project_has_allowed_number_of_incomplete_tasks(project)
        except MaxIncompleteTasksNumberIsReached:
            pytest.fail()
Ejemplo n.º 8
0
def test_complete_task():
    project = build_project(name="Test Project")
    task = build_task(id=1, name="One")
    project.tasks = [task]

    task = project.complete_task(id=1, now=date(2021, 1, 17))

    assert task.completed_at is not None
    assert task.completed_at == date(2021, 1, 17)
Ejemplo n.º 9
0
def test_tasks_endpoint_creates_task(session, client):
    # Given
    project = build_project(name="Test project")
    session.add(project)
    session.commit()

    # When
    response = client.post(
        f"/projects/{project.id}/tasks",
        json={"name": "Some task"},
    )

    # Then
    assert response.status_code == 303
Ejemplo n.º 10
0
def test_task_complete_endpoint(session, client):
    # Given
    project = build_project(name="Test project")
    task = project.add_task(name="Test")
    session.add(project)
    session.commit()

    now = datetime(2012, 1, 18, 9, 30)
    client.app.dependency_overrides[get_current_time] = lambda: now

    # When
    response = client.put(f"/projects/{project.id}/tasks/{task.id}/complete")

    # Then
    assert response.status_code == 303
Ejemplo n.º 11
0
def test_complete_tasks_completes_all_tasks():
    # Given
    tasks = [
        build_task(name="Foo", completed_at=None),
        build_task(name="Foo", completed_at=date(2020, 12, 31)),
        build_task(name="Foo", completed_at=None),
    ]
    project = build_project()
    project.tasks = tasks

    # When
    project.complete_tasks(now=date(2021, 1, 12))

    # Then
    for task in tasks:
        assert task.is_completed
Ejemplo n.º 12
0
def test_task_incomplete_endpoint(session, client):
    # Given
    project = build_project(name="Test project")
    project.add_task(name="Test")

    task = project.add_task(name="Test")
    task.completed_at = date(2021, 1, 12)

    session.add(project)
    session.commit()

    # When
    response = client.put(f"/projects/{project.id}/tasks/{task.id}/incomplete")

    # Then
    assert response.status_code == 303
Ejemplo n.º 13
0
def test_get_task_returns_task():
    project = build_project(name="Test Project")
    task = build_task(id=1, name="One")
    project.tasks = [task, build_task(id=2, name="Two")]

    assert project.get_task(1) == task
Ejemplo n.º 14
0
def test_add_task_fails_when_allowed_number_of_incomplete_tasks_is_reached():
    project = build_project(max_incomplete_tasks_number=1)
    project.add_task(name="First")

    with pytest.raises(MaxIncompleteTasksNumberIsReached):
        project.add_task(name="Second")
Ejemplo n.º 15
0
def project():
    project = build_project(id=1)
    project.tasks = [build_task(id=2)]

    return project