diff --git a/IMPLEMENTATION_COVERAGE.md b/IMPLEMENTATION_COVERAGE.md index 498910222..dc27017d2 100644 --- a/IMPLEMENTATION_COVERAGE.md +++ b/IMPLEMENTATION_COVERAGE.md @@ -6740,9 +6740,9 @@
29% implemented -- [ ] add_flow_outputs +- [X] add_flow_outputs - [ ] add_flow_sources -- [ ] add_flow_vpc_interfaces +- [X] add_flow_vpc_interfaces - [X] create_flow - [X] delete_flow - [X] describe_flow diff --git a/moto/mediaconnect/models.py b/moto/mediaconnect/models.py index ae4b16578..a48f42e8d 100644 --- a/moto/mediaconnect/models.py +++ b/moto/mediaconnect/models.py @@ -185,6 +185,26 @@ class MediaConnectBackend(BaseBackend): raise NotFoundException(message="Resource not found.") return resource.tags + def add_flow_vpc_interfaces(self, flow_arn, vpc_interfaces): + if flow_arn in self._flows: + flow = self._flows[flow_arn] + flow.vpc_interfaces = vpc_interfaces + else: + raise NotFoundException( + message="flow with arn={} not found".format(flow_arn) + ) + return flow_arn, flow.vpc_interfaces + + def add_flow_outputs(self, flow_arn, outputs): + if flow_arn in self._flows: + flow = self._flows[flow_arn] + flow.outputs = outputs + else: + raise NotFoundException( + message="flow with arn={} not found".format(flow_arn) + ) + return flow_arn, flow.outputs + # add methods from here diff --git a/moto/mediaconnect/responses.py b/moto/mediaconnect/responses.py index 9b6e2c155..495463f98 100644 --- a/moto/mediaconnect/responses.py +++ b/moto/mediaconnect/responses.py @@ -81,3 +81,21 @@ class MediaConnectResponse(BaseResponse): resource_arn=resource_arn, ) return json.dumps(dict(tags=tags)) + + def add_flow_vpc_interfaces(self): + flow_arn = unquote(self._get_param("flowArn")) + vpc_interfaces = self._get_param("vpcInterfaces") + flow_arn, vpc_interfaces = self.mediaconnect_backend.add_flow_vpc_interfaces( + flow_arn=flow_arn, vpc_interfaces=vpc_interfaces + ) + return json.dumps(dict(flow_arn=flow_arn, vpc_interfaces=vpc_interfaces)) + + def add_flow_outputs(self): + flow_arn = unquote(self._get_param("flowArn")) + outputs = self._get_param("outputs") + flow_arn, outputs = self.mediaconnect_backend.add_flow_outputs( + flow_arn=flow_arn, outputs=outputs + ) + return json.dumps(dict(flow_arn=flow_arn, outputs=outputs)) + + # add methods from here diff --git a/moto/mediaconnect/urls.py b/moto/mediaconnect/urls.py index dc66635b7..c5b5dfc1a 100644 --- a/moto/mediaconnect/urls.py +++ b/moto/mediaconnect/urls.py @@ -12,6 +12,8 @@ response = MediaConnectResponse() url_paths = { "{0}/v1/flows": response.dispatch, "{0}/v1/flows/(?P[^/.]+)": response.dispatch, + "{0}/v1/flows/(?P[^/.]+)/vpcInterfaces": response.dispatch, + "{0}/v1/flows/(?P[^/.]+)/outputs": response.dispatch, "{0}/v1/flows/start/(?P[^/.]+)": response.dispatch, "{0}/v1/flows/stop/(?P[^/.]+)": response.dispatch, "{0}/tags/(?P[^/.]+)": response.dispatch, diff --git a/tests/test_mediaconnect/test_mediaconnect.py b/tests/test_mediaconnect/test_mediaconnect.py index 0e7d985da..07a5d8209 100644 --- a/tests/test_mediaconnect/test_mediaconnect.py +++ b/tests/test_mediaconnect/test_mediaconnect.py @@ -1,9 +1,12 @@ from __future__ import unicode_literals import boto3 +import botocore +import pytest import sure # noqa -from moto import mock_mediaconnect +from botocore.exceptions import ClientError +from moto import mock_mediaconnect region = "eu-west-1" @@ -153,3 +156,93 @@ def test_tag_resource_succeeds(): list_response = client.list_tags_for_resource(ResourceArn="some-arn") list_response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200) list_response["Tags"].should.equal({"Tag1": "Value1"}) + + +@mock_mediaconnect +def test_add_flow_vpc_interfaces_succeeds(): + client = boto3.client("mediaconnect", region_name=region) + channel_config = _create_flow_config("test Flow 1") + + create_response = client.create_flow(**channel_config) + create_response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200) + create_response["Flow"]["Status"].should.equal("STANDBY") + flow_arn = create_response["Flow"]["FlowArn"] + + client.add_flow_vpc_interfaces( + FlowArn=flow_arn, + VpcInterfaces=[ + { + "Name": "VPCInterface", + "SubnetId": "", + "SecurityGroupIds": [], + "RoleArn": "", + } + ], + ) + + describe_response = client.describe_flow(FlowArn=flow_arn) + describe_response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200) + describe_response["Flow"]["VpcInterfaces"].should.equal( + [ + { + "Name": "VPCInterface", + "RoleArn": "", + "SecurityGroupIds": [], + "SubnetId": "", + } + ] + ) + + +@mock_mediaconnect +def test_add_flow_vpc_interfaces_fails(): + client = boto3.client("mediaconnect", region_name=region) + flow_arn = "unknown-flow" + with pytest.raises(ClientError) as err: + client.add_flow_vpc_interfaces( + FlowArn=flow_arn, VpcInterfaces=[], + ) + err = err.value.response["Error"] + err["Code"].should.equal("NotFoundException") + err["Message"].should.equal( + "flow with arn=unknown-flow not found".format(str(flow_arn)) + ) + + +@mock_mediaconnect +def test_add_flow_outputs_succeeds(): + client = boto3.client("mediaconnect", region_name=region) + channel_config = _create_flow_config("test Flow 1") + + create_response = client.create_flow(**channel_config) + create_response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200) + create_response["Flow"]["Status"].should.equal("STANDBY") + flow_arn = create_response["Flow"]["FlowArn"] + + client.add_flow_outputs( + FlowArn=flow_arn, + Outputs=[ + {"Description": "string", "Name": "string", "Port": 123, "Protocol": "rist"} + ], + ) + + describe_response = client.describe_flow(FlowArn=flow_arn) + describe_response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200) + describe_response["Flow"]["Outputs"].should.equal( + [{"Description": "string", "Name": "string", "Port": 123}] + ) + + +@mock_mediaconnect +def test_add_flow_outputs_fails(): + client = boto3.client("mediaconnect", region_name=region) + flow_arn = "unknown-flow" + with pytest.raises(ClientError) as err: + client.add_flow_outputs( + FlowArn=flow_arn, Outputs=[], + ) + err = err.value.response["Error"] + err["Code"].should.equal("NotFoundException") + err["Message"].should.equal( + "flow with arn=unknown-flow not found".format(str(flow_arn)) + )