Пример #1
0
    def test_remove_task_with_sublist(self):
        mainlist = TaskList()
        sublist = TaskList()
        self.db.session.add(mainlist)
        self.db.session.add(sublist)
        self.db.session.commit()

        task = Task(description="mainlisttask", list_id=1, sublist_id=2)
        task1 = Task(description="sublisttask", list_id=2)

        self.db.session.add(task)
        self.db.session.add(task1)
        self.db.session.commit()

        self.assertIsNotNone(Task.query.filter_by(id=1).first())

        self.assertIsNotNone(Task.query.filter_by(id=2).first())
        data = task.as_json()
        self.client.get_received()
        self.client.emit("remove_task", data)

        self.assertIsNone(Task.query.filter_by(id=1).first())

        self.assertIsNone(Task.query.filter_by(id=2).first())

        self.assertIsNotNone(TaskList.query.filter_by(id=1).first())

        self.assertIsNone(TaskList.query.filter_by(id=2).first())
Пример #2
0
def createTaskList():
    """API for creating a new task list from request body"""
    data = request.get_json(force=True)
    postAttrs = ['userId', 'name']
    code, msg, result = 0, '', {"data": None}

    if not judgeInputValid(data):
        code, msg = 400, apiStatus.getResponseMsg(400)
        result["code"] = code
        result["message"] = msg
        return jsonify(result)

    elif not judgeKeysCorrect(data, postAttrs):
        code, msg = 400, apiStatus.getResponseMsg(400)
    else:
        try:
            userId = data['userId']
            name = data['name']
            newTaskList = TaskList(userId=userId, name=name)
            db.session.add(newTaskList)
            db.session.commit()
            result['data'] = newTaskList.toDict()
            code, msg = 201, apiStatus.getResponseMsg(201)
        except:
            code, msg = 500, apiStatus.getResponseMsg(500)

    result["code"] = code
    result["message"] = msg
    return jsonify(result)
Пример #3
0
 def post(self):
     """
     Create a new task
     """
     args = parser.parse_args()
     task = TaskList(
         title=args["title"],
         description=args["description"],
         status=args["status"],
         priority=args["priority"],
     )
     task.save()
     return {"task": marshal(task, task_fields)}, 201
Пример #4
0
    def test_read_task_list_valid_with_tasks(self):
        task_list = TaskList()
        self.db.session.add(task_list)
        self.db.session.commit()
        tasks = [
            Task(description="Foo", list_id=task_list.id),
            Task(description="Bar", list_id=task_list.id, is_complete=True),
        ]
        self.db.session.add_all(tasks)
        self.db.session.commit()

        self.client.get_received()
        self.client.emit("read_task_list", {"id": task_list.id})
        received = self.client.get_received()

        self.assertEqual(len(received), 1)
        self.assertEqual(received[0]["args"], [{
            "id": 1,
            "tasks": [
                {
                    "id": 1,
                    "description": "Foo",
                    "is_complete": False,
                    "list_id": 1,
                    "sublist_id": None,
                },
                {
                    "id": 2,
                    "description": "Bar",
                    "is_complete": True,
                    "list_id": 1,
                    "sublist_id": None,
                },
            ],
        }])
Пример #5
0
    def test_read_task_list_valid_without_tasks(self):
        task_list = TaskList()
        self.db.session.add(task_list)
        self.db.session.commit()

        self.client.get_received()
        self.client.emit("read_task_list", {"id": task_list.id})
        received = self.client.get_received()

        self.assertEqual(len(received), 1)
        self.assertEqual(received[0]["args"], [{
            "id": 1,
            "tasks": [],
        }])
Пример #6
0
def personal():
    tlform = TaskListForm()

    if tlform.validate_on_submit():
        err = g.user.create_list(TaskList(name=tlform.name.data,
                                          description=tlform.description.data,
                                          author_id=g.user.id))
        if not err:
            flash('Task List %s was added successfully' % tlform.name.data, 'success')
        else:
            flash(err, 'warning')
        return redirect(url_for('main.personal'))
    return render_template('personal.html',
                           user=g.user,
                           task_list=None,
                           task_lists=g.user.get_task_lists(),
                           tform=None,
                           tlform=tlform,
                           sform=None)
Пример #7
0
def new_tasklist(project_id):
    form = NewComponentForm()
    project = Project.query.filter_by(id=project_id).first_or_404()
    if form.validate_on_submit():
        # Check if current user is in the project
        if current_user.is_in_project(project_id):
            tasklist = TaskList(name=form.name.data,
                                description=form.description.data)
            db.session.add(tasklist)
            project.tasklists.append(tasklist)
            db.session.commit()
            flash("Task List - \"{}\" created successfully!".format(
                tasklist.name, project.name))
            return redirect(url_for('main.project', project_id=project.id))
        else:
            flash("You cannot add task lists to this project.")
            return redirect(url_for('main.index'))
    return render_template('main/new_tasklist.html',
                           form=form,
                           project_id=project_id,
                           project_name=project.name)
Пример #8
0
def addTask_post():
    form = AddTaskForm(request.form)
    if form.validate():
        # Get Task Details
        title = form.title.data
        body = form.body.data
        status = False

        # Insert tasks into database
        try:
            task = TaskList(title=title,
                            body=body,
                            status=status,
                            user_id=current_user.id)
            db.session.add(task)
            db.session.commit()
        except Exception:
            flash("Problem Adding the task", "danger")
            return redirect(url_for('userhome'))
        else:
            flash("Task added successfully", "success")
            return redirect(url_for('userhome'))

    return render_template('addTask.html', form=form)