コード例 #1
0
ファイル: test_repo.py プロジェクト: sirrah23/GTDApp
def test_store_task(resource):
    user_id = resource
    TaskRepo.add_task(description="This is a task", user=user_id)
    tasks = TaskRepo.get_all_tasks()
    assert len(tasks) == 1
    assert tasks[0]["description"] == "This is a task"
    assert tasks[0]["status"] == "todo"
コード例 #2
0
ファイル: test_repo.py プロジェクト: sirrah23/GTDApp
def test_task_to_project(resource):
    user_id = resource
    task = TaskRepo.add_task(description="Thing", user=user_id)
    project = TaskRepo.task_to_project(task["id"], user_id)
    # No more tasks
    assert len(TaskRepo.get_all_tasks()) == 0
    # Project used to be the task
    assert project is not None
    assert project["description"] == "Thing"
コード例 #3
0
def task_update(task_id):
    res = TaskRepo.toggle_task(task_id)
    if not res:
        return json.dumps({"success": False})
    task = TaskRepo.get_task(task_id)
    if task:
        return json.dumps({"success": True, "data": task})
    else:
        return json.dumps({"success": True})
コード例 #4
0
ファイル: test_repo.py プロジェクト: sirrah23/GTDApp
def test_store_project(resource):
    user_id = resource
    TaskRepo.add_task(description="Task1", user=user_id)
    TaskRepo.add_task(description="Task2", user=user_id)
    tasks = list(map(lambda t: t["id"], TaskRepo.get_all_tasks()))
    ProjectRepo.add_project(description="ProjectA", tasks=tasks, user=user_id)
    projects = ProjectRepo.get_all_projects()
    assert len(projects) == 1
    assert projects[0]["description"] == "ProjectA"
    assert len(projects[0]["tasks"]) == 2
    assert projects[0]["tasks"][0]["id"] in tasks
    assert projects[0]["tasks"][1]["id"] in tasks
コード例 #5
0
ファイル: test_repo.py プロジェクト: sirrah23/GTDApp
def test_toggle_task_todo_to_done(resource):
    user_id = resource
    TaskRepo.add_task(description="This is a task", user=user_id)
    tasks = TaskRepo.get_all_tasks()
    assert len(tasks) == 1
    assert tasks[0]["description"] == "This is a task"
    assert tasks[0]["status"] == "todo"
    assert TaskRepo.toggle_task(str(tasks[0]["id"])) == True
    tasks = TaskRepo.get_all_tasks()
    assert len(tasks) == 1
    assert tasks[0]["description"] == "This is a task"
    assert tasks[0]["status"] == "done"
コード例 #6
0
def task_to_project(task_id):
    uid = current_user.get_obj_id()
    project = TaskRepo.task_to_project(task_id, uid)
    if not project:
        return json.dumps({"success": False})
    else:
        return json.dumps({"success": True, "data": project})
コード例 #7
0
def task_get():
    uid = current_user.get_obj_id()
    user_tasks = TaskRepo.get_all_tasks(user=uid)
    res = {}
    res["success"] = True
    res["data"] = user_tasks
    return json.dumps(res)
コード例 #8
0
ファイル: test_repo.py プロジェクト: sirrah23/GTDApp
def test_delete_project_task_bad(resource):
    """
    Should not be able to delete a task if it does not belong to the project
    """
    user_id = resource
    proj = ProjectRepo.add_project(description="ProjectA",
                                   user=user_id,
                                   tasks=[])
    task = TaskRepo.add_task(description="Task1", user=user_id)
    assert ProjectRepo.delete_project_task(proj["id"], task["id"],
                                           user_id) == False
コード例 #9
0
def task_add():
    uid = current_user.get_obj_id()
    payload = request.get_json()
    if "description" not in payload:
        res = {"success": False}
    else:
        res = {}
        added_task = TaskRepo.add_task(payload["description"], uid)
        if added_task:
            res["success"] = True
            res["data"] = added_task
        else:
            res["success"] = False
    return json.dumps(res)
コード例 #10
0
ファイル: test_repo.py プロジェクト: sirrah23/GTDApp
def test_delete_task(resource):
    user_id = resource
    task_to_del = TaskRepo.add_task(description="This is a task", user=user_id)
    TaskRepo.add_task(description="This is another task", user=user_id)
    assert len(TaskRepo.get_all_tasks()) == 2
    assert TaskRepo.delete_task(task_to_del["id"], user_id) == True
    remaining_tasks = TaskRepo.get_all_tasks()
    assert len(remaining_tasks) == 1
    assert remaining_tasks[0]["description"] == "This is another task"
コード例 #11
0
def task_delete(task_id):
    uid = current_user.get_obj_id()
    res = TaskRepo.delete_task(task_id, uid)
    return json.dumps({"success": res})
コード例 #12
0
from flask_login import LoginManager
from GTDApp.repo import ItemRepo, TaskRepo, UserRepo, ProjectRepo


# Initialize the app
app = Flask(__name__)
app.secret_key = "myspookysecret"  # TODO: Make this configurable

if os.environ.get("CONFIG_TYPE") == "test":
    app.config.from_pyfile(os.path.join(os.path.dirname(__file__), "..", "./config/config.cfg.test"))
else:
    app.config.from_pyfile(os.path.join(os.path.dirname(__file__), "..", "./config/config.cfg.default"))


# Initialize the login manager for the app
login_manager = LoginManager()
login_manager.init_app(app)


# Connect to the database
ItemRepo.connect(app.config["DBNAME"])
TaskRepo.connect(app.config["DBNAME"])
UserRepo.connect(app.config["DBNAME"])
ProjectRepo.connect(app.config["DBNAME"])


from GTDApp.views import index
from GTDApp.views import item
from GTDApp.views import task
from GTDApp.views import project