def test_validate_comment_null(self): task = TaskFactory.create() self.db.session.commit() valid_data = TimeEntryFactory.stub(task=None, comment=None).__dict__ valid_data['task_id'] = task.id valid_data['duration'] = valid_data['duration'].total_seconds() assert valid_data['comment'] is None serializer = TimeEntrySerializer(exclude=['added_at']) instance, errors = serializer.load(valid_data) assert not errors
def test_update(self): time_entry = TimeEntryFactory.create() self.db.session.commit() data = TimeEntryFactory.stub(task=None).__dict__ data['id'] = time_entry.id data['task_id'] = time_entry.task.id data['duration'] = data['duration'].total_seconds() serializer = TimeEntrySerializer(exclude=['added_at']) instance, errors = serializer.load(data) assert not errors assert instance.id == time_entry.id assert instance.duration.total_seconds() == data['duration'] assert instance.task_id == time_entry.task.id
def test_validate_duration(self): task = TaskFactory.create() self.db.session.commit() data = TimeEntryFactory.stub(task=None).__dict__ data['task_id'] = task.id # Min invalid_data = data.copy() invalid_data['duration'] = 30 serializer = TimeEntrySerializer(exclude=['added_at']) instance, errors = serializer.load(invalid_data) assert 'duration' in errors # Max invalid_data = data.copy() invalid_data['duration'] = 101 * 3600 serializer = TimeEntrySerializer(exclude=['added_at']) instance, errors = serializer.load(invalid_data) assert 'duration' in errors # Seconds invalid_data = data.copy() invalid_data['duration'] = 11111 serializer = TimeEntrySerializer(exclude=['added_at']) instance, errors = serializer.load(invalid_data) assert 'duration' in errors
def test_validate_task_id(self): data = TimeEntryFactory.stub(task=None).__dict__ data['task_id'] = 0 serializer = TimeEntrySerializer(exclude=['added_at']) instance, errors = serializer.load(data) assert 'task_id' in errors