Exemplo n.º 1
0
def toggle_status(task_id):
    task = Task.query.get(task_id)
    if not task:
        raise TaskError('Task #{0} not found'.format(task_id), 404)
    if task.status == 'open':
        task.status = 'closed'
    elif task.status == 'closed':
        task.status = 'open'
    task = db.session.merge(task)
    db.session.commit()
    serializer = TaskSerializer(only=['id', 'is_closed'], strict=True)
    return serializer.dump(task).data
Exemplo n.º 2
0
Arquivo: task.py Projeto: xuhcc/airy
def toggle_status(task_id):
    task = Task.query.get(task_id)
    if not task:
        raise TaskError('Task #{0} not found'.format(task_id), 404)
    if task.status == 'open':
        task.status = 'closed'
    elif task.status == 'closed':
        task.status = 'open'
    task = db.session.merge(task)
    db.session.commit()
    serializer = TaskSerializer(only=['id', 'is_closed'], strict=True)
    return serializer.dump(task).data
Exemplo n.º 3
0
def save(data, task_id=None):
    data = data or {}
    if task_id is not None:
        if not Task.query.get(task_id):
            raise TaskError('Task #{0} not found'.format(task_id), 404)
        data['id'] = task_id
    serializer = TaskSerializer(
        only=['id', 'title', 'url', 'description', 'project_id'])
    task, errors = serializer.load(data)
    if errors:
        raise TaskError(errors, 400)
    task = db.session.merge(task)
    db.session.commit()
    serializer = TaskSerializer(strict=True)
    return serializer.dump(task).data
Exemplo n.º 4
0
Arquivo: task.py Projeto: xuhcc/airy
def save(data, task_id=None):
    data = data or {}
    if task_id is not None:
        if not Task.query.get(task_id):
            raise TaskError(
                'Task #{0} not found'.format(task_id), 404)
        data['id'] = task_id
    serializer = TaskSerializer(
        only=['id', 'title', 'url', 'description', 'project_id'])
    task, errors = serializer.load(data)
    if errors:
        raise TaskError(errors, 400)
    task = db.session.merge(task)
    db.session.commit()
    serializer = TaskSerializer(strict=True)
    return serializer.dump(task).data
Exemplo n.º 5
0
 def test_serialization(self):
     task = TaskFactory.create()
     time_entry = TimeEntryFactory.create(task=task)
     self.db.session.commit()
     serializer = TaskSerializer(strict=True)
     data = serializer.dump(task).data
     assert data['id'] == task.id
     assert data['title'] == task.title
     assert data['url'] == task.url
     assert data['description'] == task.description
     assert data['project_id'] == task.project.id
     assert data['total_time'] == time_entry.duration.total_seconds()
     assert data['is_closed'] is False
     time_data = data['time_entries'][0]
     assert time_data['id'] == time_entry.id
     assert time_data['comment'] == time_entry.comment
     assert time_data['task_id'] == task.id
Exemplo n.º 6
0
 def test_serialization(self):
     task = TaskFactory.create()
     time_entry = TimeEntryFactory.create(task=task)
     self.db.session.commit()
     serializer = TaskSerializer(strict=True)
     data = serializer.dump(task).data
     assert data['id'] == task.id
     assert data['title'] == task.title
     assert data['url'] == task.url
     assert data['description'] == task.description
     assert data['project_id'] == task.project.id
     assert data['total_time'] == time_entry.duration.total_seconds()
     assert data['is_closed'] is False
     time_data = data['time_entries'][0]
     assert time_data['id'] == time_entry.id
     assert time_data['comment'] == time_entry.comment
     assert time_data['task_id'] == task.id
     assert 'task_total_time' not in time_data