def test_all_targets_healthy_false(aws_client):
    client = MagicMock()
    aws_client.return_value = client
    tg_names = ['TestTargetGroup1', 'TestTargetGroup2']
    client.describe_target_groups.return_value = {
        "TargetGroups": [{
            'TargetGroupArn': """
            arn:aws:elasticloadbalancing:eu-west-1:111111111111:targetgroup/TestTargetGroup1/1234567890abcdef
            """,
            'TargetGroupName': 'TestTargetGroup1'
        }, {
            'TargetGroupArn': """
            arn:aws:elasticloadbalancing:eu-west-1:111111111111:targetgroup/TestTargetGroup2/234567890abcdef0
            """,
            'TargetGroupName': 'TestTargetGroup2'
        }]
    }
    client.describe_target_health.side_effect = [{
        'TargetHealthDescriptions': [{
            'TargetHealth': {
                'State': 'healthy'
            }
        }]
    }, {
        'TargetHealthDescriptions': [{
            'TargetHealth': {
                'State': 'unhealthy'
            }
        }]
    }]
    response = all_targets_healthy(tg_names=tg_names)
    assert response is False
Exemplo n.º 2
0
def test_all_targets_healthy_false(aws_client):
    client = MagicMock()
    aws_client.return_value = client
    tg_names = ["TestTargetGroup1", "TestTargetGroup2"]
    client.describe_target_groups.return_value = {
        "TargetGroups": [
            {
                "TargetGroupArn": """
            arn:aws:elasticloadbalancing:eu-west-1:111111111111:targetgroup/TestTargetGroup1/1234567890abcdef
            """,
                "TargetGroupName": "TestTargetGroup1",
            },
            {
                "TargetGroupArn": """
            arn:aws:elasticloadbalancing:eu-west-1:111111111111:targetgroup/TestTargetGroup2/234567890abcdef0
            """,
                "TargetGroupName": "TestTargetGroup2",
            },
        ]
    }
    client.describe_target_health.side_effect = [
        {
            "TargetHealthDescriptions": [{
                "TargetHealth": {
                    "State": "healthy"
                }
            }]
        },
        {
            "TargetHealthDescriptions": [{
                "TargetHealth": {
                    "State": "unhealthy"
                }
            }]
        },
    ]
    response = all_targets_healthy(tg_names=tg_names)
    assert response is False
def test_all_targets_healthy_needs_tg_names():
    with pytest.raises(FailedActivity) as x:
        all_targets_healthy([])
    assert "Non-empty list of target groups is required" in str(x)