def create_hero(hero_name, universe): hero = Hero() hero.name = hero_name hero.description = '{0} description'.format(hero_name) hero.universe = universe hero.save() return hero
def test_save_and_get_hero(self): """Test save and get hero""" # Criando o novo heroi new_hero = Hero() new_hero.name = 'Superman' new_hero.description = 'Superman' new_hero.universe = 'dc' new_hero.save() # Obtendo o heroi pelo id hero = Hero.get_hero(new_hero.id) self.assertEqual(hero.name, 'Superman') self.assertEqual(hero.id, new_hero.id)
def create(cls, params): """""" if not params.get('name'): return {'error': str('name is required')}, 400 if not params.get('universe'): return {'error': str('universe is required')}, 400 hero = Hero() hero.name = cls.title_case(params.get('name')) hero.image_url = cls.title_case(params.get('imageUrl')) hero.description = cls.title_case(params.get('description')) hero.universe = cls.title_case(params.get('universe')) hero.save() return hero.to_dict()
def create(params): """ Create a new hero :param dict params: Request dict params :return Hero: Hero created """ hero = Hero() hero.name = params['name'] hero.description = params['description'] hero.imageUrl = params['imageUrl'] hero.universe = params['universe'] HeroModule.format_hero_params(hero) HeroModule.valid_hero_params(hero) hero.save() return hero