예제 #1
0
async def test_connect_invalid_password():
    with pytest.raises(carehare.ConnectionClosedByServer) as cm:
        async with carehare.connect(URL.replace("guest", "wrong"),
                                    ssl=SSL_CONTEXT):
            pass
    assert cm.value.reply_code == 403
    assert "403 ACCESS_REFUSED" in str(cm.value)
예제 #2
0
async def test_connect_warn_on_empty_vhost(caplog):
    with pytest.warns(DeprecationWarning) as record:
        async with carehare.connect(URL + "/", ssl=SSL_CONTEXT):
            pass
    assert record[0].message.args[0] == (
        'Your RabbitMQ URL ends with a slash, which implies vhost "". This is, surprisingly, an error. carehare is interpreting this to mean "default vhost". To avoid this warning, remove the "/" from the end of your URL.'
    )
예제 #3
0
async def test_close_when_rabbitmq_closes_with_error():
    with pytest.raises(carehare.ConnectionClosedByServer) as cm:
        async with carehare.connect(URL, ssl=SSL_CONTEXT) as connection:
            connection._protocol._transport.write(
                b"\x00\x00\x00\x00\x00\x00\x00\x00hi! I'm not AMQP. You can crash now."
            )
            await asyncio.sleep(1)
    assert "501 FRAME_ERROR" in str(cm.value)
예제 #4
0
async def test_queue_declare_not_ok(connection):
    await connection.queue_declare("conflict", exclusive=True)

    async with carehare.connect(URL, ssl=SSL_CONTEXT) as connection2:
        with pytest.raises(carehare.ChannelClosedByServer) as cm:
            await connection2.queue_declare("conflict", exclusive=True)
        assert cm.value.reply_code == 405
        assert "405 RESOURCE_LOCKED" in str(cm.value)
예제 #5
0
async def test_connect_timeout():
    with pytest.raises(asyncio.TimeoutError):
        async with carehare.connect(URL,
                                    ssl=SSL_CONTEXT,
                                    connect_timeout=0.000000001):
            pass
예제 #6
0
async def test_connect_warn_amqp_should_be_amqps():
    with pytest.raises(ValueError) as cm:
        async with carehare.connect(URL.replace("amqps://", "amqp://"),
                                    ssl=SSL_CONTEXT):
            pass
    assert "you must not provide `ssl`" in str(cm.value)
예제 #7
0
async def test_connect_port():
    async with carehare.connect(URL.replace("localhost", "localhost:5671"),
                                ssl=SSL_CONTEXT):
        pass
예제 #8
0
async def test_value_error_on_invalid_vhost(caplog):
    with pytest.raises(ValueError):
        async with carehare.connect(URL + "/myvhost/", ssl=SSL_CONTEXT):
            pass
예제 #9
0
async def test_connect_vhost():
    async with carehare.connect(URL + "/myvhost", ssl=SSL_CONTEXT):
        pass
예제 #10
0
async def test_connect_ssl_error():
    with pytest.raises(ssl.SSLCertVerificationError):
        async with carehare.connect(URL.replace("guest", "wrong")):
            pass
예제 #11
0
async def test_connect_invalid_scheme():
    with pytest.raises(ValueError) as cm:
        async with carehare.connect(URL.replace("amqps://", "http://"),
                                    ssl=SSL_CONTEXT):
            pass
    assert "amqps://" in str(cm.value)
예제 #12
0
async def connection():
    async with connect(URL, ssl=SSL_CONTEXT) as connection:
        yield connection