Skip to content

Commit

Permalink
Greengrass Implement delete_function_definition
Browse files Browse the repository at this point in the history
  • Loading branch information
cm-iwata committed Jun 16, 2022
1 parent a508287 commit 915e1c2
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
6 changes: 6 additions & 0 deletions moto/greengrass/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,12 @@ def get_function_definition(self, function_definition_id):
raise IdNotFoundException("That Lambda List Definition does not exist.")
return self.function_definitions[function_definition_id]

def delete_function_definition(self, function_definition_id):
if function_definition_id not in self.function_definitions:
raise IdNotFoundException("That lambdas definition does not exist.")
del self.function_definitions[function_definition_id]
del self.function_definition_versions[function_definition_id]

def create_function_definition_version(
self, function_definition_id, functions, default_config
):
Expand Down
10 changes: 10 additions & 0 deletions moto/greengrass/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,23 @@ def function_definition(self, request, full_url, headers):
if self.method == "GET":
return self.get_function_definition()

if self.method == "DELETE":
return self.delete_function_definition()

def get_function_definition(self):
function_definition_id = self.path.split("/")[-1]
res = self.greengrass_backend.get_function_definition(
function_definition_id=function_definition_id,
)
return 200, {"status": 200}, json.dumps(res.to_dict())

def delete_function_definition(self):
function_definition_id = self.path.split("/")[-1]
self.greengrass_backend.delete_function_definition(
function_definition_id=function_definition_id,
)
return 200, {"status": 200}, json.dumps({})

def function_definition_versions(self, request, full_url, headers):
self.setup_class(request, full_url, headers)

Expand Down
42 changes: 42 additions & 0 deletions tests/test_greengrass/test_greengrass_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,48 @@ def test_get_function_definition_with_invalid_id():
ex.value.response["Error"]["Code"].should.equal("IdNotFoundException")


@mock_greengrass
def test_delete_function_definition():

client = boto3.client("greengrass", region_name="ap-northeast-1")
init_ver = {
"Functions": [
{
"FunctionArn": "arn:aws:lambda:ap-northeast-1:123456789012:function:test-func:1",
"Id": "1234567890",
"FunctionConfiguration": {
"MemorySize": 16384,
"EncodingType": "binary",
"Pinned": True,
"Timeout": 3,
},
}
]
}
create_res = client.create_function_definition(
InitialVersion=init_ver, Name="TestFunc"
)

func_def_id = create_res["Id"]
del_res = client.delete_function_definition(FunctionDefinitionId=func_def_id)
del_res["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)


@mock_greengrass
def test_delete_function_definition_with_invalid_id():

client = boto3.client("greengrass", region_name="ap-northeast-1")

with pytest.raises(ClientError) as ex:
client.delete_function_definition(
FunctionDefinitionId="6fbffc21-989e-4d29-a793-a42f450a78c6"
)
ex.value.response["Error"]["Message"].should.equal(
"That lambdas definition does not exist."
)
ex.value.response["Error"]["Code"].should.equal("IdNotFoundException")


@freezegun.freeze_time("2022-06-01 12:00:00")
@mock_greengrass
def test_create_function_definition_version():
Expand Down

0 comments on commit 915e1c2

Please sign in to comment.