def test_invalid_event():
    get_addresses()
    return_all_ips_to_pool()

    event2 = copy.deepcopy(event)
    event2["source"] = "aws.unknown"
    handler(event2, {})

    _, available, _ = get_addresses()
    assert len(available) == 2
def test_remove_and_add():
    return_all_ips_to_pool()

    instances = get_pool_instances("bastion")
    for instance in instances:
        event["detail"]["state"] = "running"
        event["detail"]["instance-id"] = instance.instance_id
        handler(event, {})

    _, available, allocated = get_addresses()
    assert len(available) == 0

    event["detail"]["state"] = "terminated"
    event["detail"]["instance-id"] = instances[0].instance_id
    handler(event, {})

    _, available, _ = get_addresses()
    assert len(available) == 0
def test_timer():
    get_addresses()
    return_all_ips_to_pool()

    event = {
        "detail-type": "Scheduled Event",
        "source": "aws.events",
        "detail": {}
    }
    handler(event, {})

    _, available, _ = get_addresses()
    assert len(available) == 0

    event = {
        "detail-type": "Scheduled Event",
        "source": "aws.events",
        "detail": {}
    }
    handler(event, {})

    _, available, _ = get_addresses()
    assert len(available) == 0
def test_add_non_existing_instance_eip():
    return_all_ips_to_pool()
    event["detail"]["state"] = "running"
    event["detail"]["instance-id"] = "i-000000000000a4a41"
    handler(event, {})
def test_remove_non_existing_instance():
    event["detail"]["state"] = "terminated"
    event["detail"]["instance-id"] = " i-000000000000a4a41"
    handler(event, {})