@mock_ec2
def test_eip_reassociate():
    conn = boto.connect_ec2('the_key', 'the_secret')

    reservation = conn.run_instances('ami-1234abcd', min_count=2)
    instance1, instance2 = reservation.instances

    eip = conn.allocate_address()
    conn.associate_address(instance_id=instance1.id, public_ip=eip.public_ip)

    # Same ID is idempotent
    conn.associate_address(instance_id=instance1.id, public_ip=eip.public_ip)

    # Different ID detects resource association
    with assert_raises(EC2ResponseError) as cm:
        conn.associate_address(instance_id=instance2.id, public_ip=eip.public_ip, allow_reassociation=False)
    cm.exception.code.should.equal('Resource.AlreadyAssociated')
    cm.exception.status.should.equal(400)
    cm.exception.request_id.should_not.be.none

    conn.associate_address.when.called_with(instance_id=instance2.id, public_ip=eip.public_ip, allow_reassociation=True).should_not.throw(EC2ResponseError)

    eip.release()
    eip = None

    instance1.terminate()
    instance2.terminate()
reassociate EIP
dataset/ETHPy150Open spulec/moto/tests/test_ec2/test_elastic_ip_addresses.py/test_eip_reassociate