Ejemplo n.º 1
0
def test_anonymous_connection(mockpika, mock_pikathread,
                              revert_classvariables):
    """check that a specified configuration file is read, that command line
    parameters have precedence and are passed on the pika layer"""

    mockconn = mock.Mock()
    mockpika.BlockingConnection.return_value = mockconn
    parser = optparse.OptionParser()
    transport = PikaTransport()
    transport.add_command_line_options(parser)

    parser.parse_args(["--rabbit-user="******"--rabbit-pass="******"", "")
Ejemplo n.º 2
0
def test_check_config_file_behaviour(mockpika, mock_pikathread, tmp_path,
                                     revert_classvariables):
    """Check that a specified configuration file is read, that command line
    parameters have precedence and are passed on to the pika layer."""

    parser = optparse.OptionParser()
    transport = PikaTransport()
    transport.add_command_line_options(parser)

    cfgfile = tmp_path / "config"
    cfgfile.write_text("""
        # An example pika configuration file
        # Only lines in the [pika] block will be interpreted

        [rabbit]
        host = localhost
        port = 5672
        username = someuser
        password = somesecret
        vhost = namespace
        """)

    parser.parse_args(
        ["--rabbit-conf",
         str(cfgfile), "--rabbit-user", mock.sentinel.user])

    transport = PikaTransport()
    transport.connect()

    mock_pikathread.start.assert_called_once()
    mockpika.PlainCredentials.assert_called_once_with(mock.sentinel.user,
                                                      "somesecret")
    args, kwargs = mockpika.ConnectionParameters.call_args
    assert not args
    assert kwargs == {
        "host": "localhost",
        "port": 5672,
        "virtual_host": "namespace",
        "credentials": mockpika.PlainCredentials.return_value,
    }

    with pytest.raises(workflows.Error):
        parser.parse_args(["--rabbit-conf", ""])