-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We'll pass the recipe ID through as a path parameter - similar to getting a single recipe
- Loading branch information
1 parent
492edff
commit 6382643
Showing
6 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from aws_lambda_powertools.utilities.data_classes import APIGatewayProxyEventV2 | ||
from aws_lambda_powertools.utilities.typing import LambdaContext | ||
|
||
|
||
from backend.models.recipe import Recipe | ||
from backend.services.logger import get_logger | ||
from backend.models.response import APIGatewayResponse | ||
|
||
logger = get_logger("recipes-delete") | ||
|
||
|
||
@logger.inject_lambda_context | ||
def handler( | ||
event: APIGatewayProxyEventV2, context: LambdaContext | ||
) -> APIGatewayResponse: | ||
id = event["pathParameters"]["id"] | ||
recipe = Recipe.find_one(id=id) | ||
recipe.delete() | ||
return APIGatewayResponse.build(body={}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from sys import path | ||
import json | ||
from unittest.mock import patch, MagicMock | ||
from aws_lambda_powertools.utilities.data_classes import APIGatewayProxyEventV2 | ||
from backend.tests.fixtures import LAMBDA_CONTEXT | ||
from backend.handlers.recipes.delete import handler | ||
|
||
API_GATEWAY_EVENT_WITH_RECIPE_ID = APIGatewayProxyEventV2( | ||
{"body": "", "pathParameters": {"id": "recipe_id"}} | ||
) | ||
|
||
|
||
class TestRecipesDeleteHandler: | ||
|
||
@patch("backend.handlers.recipes.delete.Recipe") | ||
def test_handler_returns_a_dict_with_correct_fields(self, recipe_mock: MagicMock): | ||
response = handler(API_GATEWAY_EVENT_WITH_RECIPE_ID, LAMBDA_CONTEXT) | ||
for response_key in [ | ||
"body", | ||
"statusCode", | ||
"cookies", | ||
"headers", | ||
"isBase64Encoded", | ||
]: | ||
assert response_key in response.keys() | ||
|
||
@patch("backend.handlers.recipes.delete.Recipe") | ||
def test_handler_calls_delete_on_the_recipe(self, recipe_mock: MagicMock): | ||
found_recipe_mock = MagicMock() | ||
recipe_mock.find_one.return_value = found_recipe_mock | ||
handler(API_GATEWAY_EVENT_WITH_RECIPE_ID, LAMBDA_CONTEXT) | ||
|
||
found_recipe_mock.delete.assert_called_once |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters