def test_add_ng_invalid_value(self): # id model = Category('a', 'test') self.assertFalse(model.is_valid()) # name model = Category(1, '') self.assertFalse(model.is_valid()) model = Category(1, None) self.assertFalse(model.is_valid())
def edit(id): request_data = request.get_json() if request_data is None: raise BadRequest() category = Category(**request.json) if not category.is_valid(): raise BadRequest( description='保存エラー。エラー内容を確認してください。', response=category.validation_errors ) mapper = CategoryMapper() saved = mapper.save(category) if not saved: raise Conflict() return ApiResponse(200, message='更新しました')
def add(): request_data = request.get_json() if request_data is None: raise BadRequest() category = Category(**request.json) if not category.is_valid(): raise BadRequest( description='保存エラー。エラー内容を確認してください。', response=category.validation_errors ) mapper = CategoryMapper() if mapper.is_upper_limit(): raise BadRequest(description='商品カテゴリの登録数は10件までです') saved = mapper.save(category) if not saved: raise Conflict() return ApiResponse(201, message='保存しました')