コード例 #1
0
def test_stop_should_stop_tracking():
    task_id = "1000000"

    # create mocks
    task_tracker = Mock()
    local_storage = get_local_storage()()

    usecase = TimeTracking(task_tracker, local_storage)

    usecase.start_tracking(task_id)
    usecase.stop_tracking(task_id)

    with pytest.raises(TaskDoesNotExist):
        usecase.local_storage.get_task(task_id)
コード例 #2
0
def test_stop_should_sync_tracking_with_remote():
    task_id = "1000000"

    # create mocks
    task_tracker = Mock()
    local_storage = get_local_storage()()

    usecase = TimeTracking(task_tracker, local_storage)

    usecase.start_tracking(task_id)
    usecase.stop_tracking(task_id)

    # check that there's been no errors, and the time
    # sync was called to asana.
    assert usecase.task_tracker.sync_time.called_once()
コード例 #3
0
def test_start_should_throw_error_for_task_we_are_already_tracking():
    task_id = "1000000"

    # create mocks
    task_tracker = Mock()
    local_storage = get_local_storage()()

    usecase = TimeTracking(task_tracker, local_storage)

    task = Task(task_id, datetime.now())

    # This is a testing only method.
    usecase.local_storage.DB.append(task_serializer.task_to_dict(task))

    # check that local storage is checked and causes an error
    with pytest.raises(TaskAlreadyExists):
        usecase.start_tracking(task_id)
コード例 #4
0
def test_start_should_throw_error_for_invalid_remote_task_id():
    def raise_exc(n):
        raise RemoteTaskNotFound

    task_id = "1000000"

    # create mocks
    task_tracker = Mock()
    local_storage = get_local_storage()()

    usecase = TimeTracking(task_tracker, local_storage)

    # set task tracker to respond badly to one of the task IDs
    usecase.task_tracker.get_task.side_effect = raise_exc

    # check that the exception is thrown
    with pytest.raises(RemoteTaskNotFound):
        usecase.start_tracking(task_id)
コード例 #5
0
def test_start_should_start_tracking():
    task_id = "1000000"

    # create mocks
    task_tracker = Mock()
    local_storage = get_local_storage()()

    usecase = TimeTracking(task_tracker, local_storage)

    usecase.start_tracking(task_id)

    # Is Asana checked for validity?
    assert usecase.task_tracker.get_task.called_once()

    # Is the data stored? I.e. was it actually written somewhere
    task = usecase.local_storage.get_task(task_id)

    assert task.id == task_id
コード例 #6
0
ファイル: test_complete.py プロジェクト: deverts/WorkTimeCLI
def test_complete_closes_locally_running_task_if_exists():
    task_id = "000000"

    task_tracker = Mock()
    local_storage = get_local_storage()()

    usecase = TimeTracking(task_tracker, local_storage)

    usecase.start_tracking(task_id)

    usecase.complete_task(task_id)

    # check that the task is now actually stopped
    with pytest.raises(TaskDoesNotExist):
        usecase.stop_tracking(task_id)

    assert usecase.task_tracker.sync_time.called_once_with(task_id, 0)

    # Check complete task is called after
    assert usecase.task_tracker.complete_task.called_once_with(task_id)
コード例 #7
0
def test_stop_should_throw_error_for_task_that_no_longer_exist():
    def raise_exc(n, m):
        raise RemoteTaskNotFound

    task_id = "1000000"

    # create mocks
    task_tracker = Mock()
    local_storage = get_local_storage()()

    usecase = TimeTracking(task_tracker, local_storage)

    usecase.start_tracking(task_id)

    # simulate the task no longer existing.
    # this error would be thrown by get_task
    usecase.task_tracker.sync_time.side_effect = raise_exc

    with pytest.raises(RemoteTaskNotFound):
        usecase.stop_tracking(task_id)
コード例 #8
0
        return pick_task_from_list(matches)


if __name__ == "__main__":
    work_time = TimeTracking(AsanaTaskTracker(), FileLocalStorage())

    if args.magic:
        try:
            args.id = find_task_from_slug(work_time, args.magic)
        except RemoteTaskNotFound:
            print("-> Task not found. Please try another slug.")
            sys.exit(0)

    if args.action == "start":
        try:
            work_time.start_tracking(args.id)
            print(f"-> Started tracking {args.id}")
        except TaskAlreadyExists:
            print("-> Already tracking. Doing nothing.")

    elif args.action == "stop":
        try:
            work_time.stop_tracking(args.id)
            print(f"-> Stopped tracking {args.id}")
        except TaskDoesNotExist:
            print("x Task ID either is not tracking, or does not exist.")
    elif args.action == "list":
        tasks = work_time.list_tasks()

        table = PrettyTable()
        table.field_names = ["ID", "Name", "Due"]