def post(self) -> dict: create_params = self.create_params() ingredient = Ingredient(**create_params) session.add(ingredient) session.commit() ingredient = IngredientClientSchema().dump(ingredient) response = BasicResponse(ingredient) return BasicResponseSchema().dump(response)
def test_show(test_client: FlaskClient, admin_headers: dict): ingredient = Ingredient(name='Name', calories=200) session.add(ingredient) session.commit() response = test_client.get(f"/api/admin/v1/ingredients/{ingredient.id}/", headers=admin_headers) actual = response.json['result'] expected = IngredientClientSchema().dump(ingredient) assert actual == expected
def put(self, id: int) -> dict: ingredient = session.query(Ingredient).get(id) update_params = self.update_params() for key, value in update_params.items(): setattr(ingredient, key, value) session.commit() ingredient = IngredientClientSchema().dump(ingredient) response = BasicResponse(ingredient) return BasicResponseSchema().dump(response)
def test_create(test_client: FlaskClient, admin_headers: dict): data = ({ "name": "Name", "calories": 200, }) response = test_client.post('/api/admin/v1/ingredients/', json=data, headers=admin_headers) actual = response.json['result'] expected = IngredientClientSchema().dump(session.query(Ingredient).one()) assert actual == expected
def test_update(test_client: FlaskClient, admin_headers: dict): ingredient = Ingredient(name='Name', calories=200) session.add(ingredient) session.commit() data = ({ "name": "Name111", "calories": 2001, }) response = test_client.put(f"/api/admin/v1/ingredients/{ingredient.id}/", json=data, headers=admin_headers) actual = response.json['result'] expected = IngredientClientSchema().dump(ingredient) assert actual == expected
def get(self, id: int) -> dict: ingredient = session.query(Ingredient).get(id) ingredient = IngredientClientSchema().dump(ingredient) response = BasicResponse(ingredient) return BasicResponseSchema().dump(response)
def get(self) -> dict: ingredients = session.query(Ingredient).all() ingredients = IngredientClientSchema().dump(ingredients, many=True) response = BasicResponse(ingredients) return BasicResponseSchema().dump(response)