From 81859f9180c00c3a9228fe19271aedc85a3d546c Mon Sep 17 00:00:00 2001 From: Brandon Clodius Date: Tue, 2 Feb 2021 10:21:16 -0500 Subject: [PATCH] (fix) Fixes #3648 (#3649) * (fix) Fixes #3648 * (fix) formatting * (review) add assertion for exception thrown --- moto/elbv2/models.py | 7 ++++--- tests/test_elbv2/test_elbv2.py | 7 +++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/moto/elbv2/models.py b/moto/elbv2/models.py index 05f6249cc..799ba6e96 100644 --- a/moto/elbv2/models.py +++ b/moto/elbv2/models.py @@ -827,9 +827,10 @@ Member must satisfy regular expression pattern: {}".format( for load_balancer in self.load_balancers.values(): for listener_arn in listener_arns: listener = load_balancer.listeners.get(listener_arn) - if not listener: - raise ListenerNotFoundError() - matched.append(listener) + if listener: + matched.append(listener) + if listener_arns and len(matched) == 0: + raise ListenerNotFoundError() return matched def delete_load_balancer(self, arn): diff --git a/tests/test_elbv2/test_elbv2.py b/tests/test_elbv2/test_elbv2.py index 5e681ac0e..3d80821c0 100644 --- a/tests/test_elbv2/test_elbv2.py +++ b/tests/test_elbv2/test_elbv2.py @@ -415,10 +415,9 @@ def test_create_target_group_and_listeners(): response.get("LoadBalancers").should.have.length_of(0) # And it deleted the remaining listener - response = conn.describe_listeners( - ListenerArns=[http_listener_arn, https_listener_arn] - ) - response.get("Listeners").should.have.length_of(0) + with pytest.raises(ClientError) as e: + conn.describe_listeners(ListenerArns=[http_listener_arn, https_listener_arn]) + e.value.response["Error"]["Code"].should.equal("ListenerNotFound") # But not the target groups response = conn.describe_target_groups()