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
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
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
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