コード例 #1
0
ファイル: test_serializers.py プロジェクト: xuhcc/airy
 def test_validate_project_id(self):
     data = TaskFactory.stub(project=None).__dict__
     data['project_id'] = 0
     serializer = TaskSerializer(
         only=['id', 'title', 'description', 'project_id'])
     instance, errors = serializer.load(data)
     assert 'project_id' in errors
コード例 #2
0
 def test_validate_project_id(self):
     data = TaskFactory.stub(project=None).__dict__
     data['project_id'] = 0
     serializer = TaskSerializer(
         only=['id', 'title', 'description', 'project_id'])
     instance, errors = serializer.load(data)
     assert 'project_id' in errors
コード例 #3
0
ファイル: test_serializers.py プロジェクト: xuhcc/airy
 def test_required(self):
     serializer = TaskSerializer(
         only=['id', 'title', 'url', 'description', 'project_id'])
     instance, errors = serializer.load({})
     assert 'title' in errors
     assert 'url' not in errors
     assert 'description' not in errors
     assert 'project_id' in errors
コード例 #4
0
 def test_required(self):
     serializer = TaskSerializer(
         only=['id', 'title', 'url', 'description', 'project_id'])
     instance, errors = serializer.load({})
     assert 'title' in errors
     assert 'url' not in errors
     assert 'description' not in errors
     assert 'project_id' in errors
コード例 #5
0
ファイル: test_serializers.py プロジェクト: xuhcc/airy
 def test_preprocess_url(self):
     serializer = TaskSerializer(
         only=['id', 'title', 'description', 'project_id'])
     project = ProjectFactory.create()
     self.db.session.commit()
     data = TaskFactory.stub(project=None, url='').__dict__
     data['project_id'] = project.id
     instance, errors = serializer.load(data)
     assert not errors
     assert instance.url is None
コード例 #6
0
 def test_preprocess_url(self):
     serializer = TaskSerializer(
         only=['id', 'title', 'description', 'project_id'])
     project = ProjectFactory.create()
     self.db.session.commit()
     data = TaskFactory.stub(project=None, url='').__dict__
     data['project_id'] = project.id
     instance, errors = serializer.load(data)
     assert not errors
     assert instance.url is None
コード例 #7
0
ファイル: test_serializers.py プロジェクト: xuhcc/airy
 def test_validate_title_length(self):
     serializer = TaskSerializer(
         only=['id', 'title', 'description', 'project_id'])
     # Min
     data = TaskFactory.stub(title='x').__dict__
     instance, errors = serializer.load(data)
     assert 'title' in errors
     # Max
     data = TaskFactory.stub(title='x' * 101).__dict__
     instance, errors = serializer.load(data)
     assert 'title' in errors
コード例 #8
0
 def test_validate_title_length(self):
     serializer = TaskSerializer(
         only=['id', 'title', 'description', 'project_id'])
     # Min
     data = TaskFactory.stub(title='x').__dict__
     instance, errors = serializer.load(data)
     assert 'title' in errors
     # Max
     data = TaskFactory.stub(title='x' * 101).__dict__
     instance, errors = serializer.load(data)
     assert 'title' in errors
コード例 #9
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
コード例 #10
0
ファイル: task.py プロジェクト: 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
コード例 #11
0
ファイル: test_serializers.py プロジェクト: xuhcc/airy
 def test_update(self):
     task = TaskFactory.create()
     self.db.session.commit()
     data = TaskFactory.stub(project=None).__dict__
     data['id'] = task.id
     data['project_id'] = task.project.id
     serializer = TaskSerializer(
         only=['id', 'title', 'url', 'description', 'project_id'])
     instance, errors = serializer.load(data)
     assert not errors
     assert instance.id == task.id
     assert instance.title == data['title']
     assert instance.project_id == task.project.id
コード例 #12
0
 def test_update(self):
     task = TaskFactory.create()
     self.db.session.commit()
     data = TaskFactory.stub(project=None).__dict__
     data['id'] = task.id
     data['project_id'] = task.project.id
     serializer = TaskSerializer(
         only=['id', 'title', 'url', 'description', 'project_id'])
     instance, errors = serializer.load(data)
     assert not errors
     assert instance.id == task.id
     assert instance.title == data['title']
     assert instance.project_id == task.project.id
コード例 #13
0
ファイル: task.py プロジェクト: 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
コード例 #14
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
コード例 #15
0
ファイル: test_serializers.py プロジェクト: xuhcc/airy
 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
コード例 #16
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